since a longtime I do livestream to youtube or twitch with 'copy' codec of raspivid (1280x720@25) and sound from /dev/zero

Now I try to add an audio track from chinese usb mic.

If I use copy audio codec, I get 'pcm_s16le' and combined with video, speed 1x and 25fps but no sounds plays from client.

I saw in twitch requirement, audio needs to be aac, so I change my ffmpeg, but as it runs, I fall to 12/13 fps and I can't reach more than 0.8 speed, too low for livestream.

/usr/bin/raspivid -o - -w 1280 -h 720 -n -t 0 -ex auto -awb auto -fps 25 -b 6000000 | \
  /usr/bin/ffmpeg -y -xerror \
  -thread_queue_size 32k -f h264 -i - \ 
  -thread_queue_size 128k -f alsa -ar 48000 -ac 1 -i hw:1,0 \ 
  -c:v copy -c:a aac -b:a 128k -strict experimental -g 50 
  -f flv /tmp/truc.flv   (or rtmp url)

at start, I get :

Input #0, h264, from 'pipe:':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Guessed Channel Layout for Input Stream #1.0 : mono
Input #1, alsa, from 'hw:1,0':
  Duration: N/A, start: 1621334643.781596, bitrate: 768 kb/s
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Output #0, flv, to '/tmp/truc.flv':
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p(progressive), 1280x720, q=2-31, 25 fps, 25 tbr, 1k tbn, 1200k tbc
    Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 48000 Hz, mono, fltp, 128 kb/s
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))

Pi is running a "modest" overclock setting (800mhz) with 256Mb for GPU

model name is : ARMv6-compatible processor rev 7 (v6l)

Is this hardware is strong enough to do that ?

  • that's surprising, thought audio compression wasn't at all taxing on the CPU ... are you sure the frame rate drops when you stream, as opposed to save to file ... I can imagine saving to file may have an issue if the SD card is slow May 18, 2021 at 12:04
  • as a test, try adding -threads 4 - I've read that ffmpeg default "optimal" threads usage isn't always optimal - oh, wait ... RPIB+ ... so it's single core ... nevermind May 18, 2021 at 12:08
  • nothing better with -threads 4, and speed is quite the same with rtsp, dummy file, or dev/null :-(
    – Overnuts
    May 18, 2021 at 12:50
  • yeah, piB+ only has a single core, I realised that and edited the comment May 18, 2021 at 22:42


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.