Reputation: 21
Despite my limited knowledge in ffmpeg, I've managed to livestream my birdbox camera to youtube using ffmpeg running on a raspberry pi. The camera has also audio and by using local vlc in windows with rtsp, the audio is ok.
However, on youtube there is no sound (same rtsp command as used locally in windows), and I see this "warning" in youtube studio: "The current bitrate (0) of the audio stream is lower than the recommended bitrate. We recommend using a 128 Kbps bitrate for the audio stream."
How can I get the sound through youtube? This is the command I run. The command was found on the net, and I adopted it for my usage, and got video working straight away:
pi@raspberrypi:~ $ ffmpeg -f lavfi -i anullsrc -thread_queue_size 512 -rtsp_transport udp -i "rtsp://10.x.x.x:554/user=user&password=password&channel=1&stream=0.sdp?real_stream" -tune zerolatency -vcodec libx264 -use_wallclock_as_timestamps 1 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/mykey
ffmpeg version git-2020-05-01-3c740f2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516
configuration: --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
libavutil 56. 43.100 / 56. 43.100
libavcodec 58. 82.100 / 58. 82.100
libavformat 58. 42.102 / 58. 42.102
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 80.100 / 7. 80.100
libswscale 5. 6.101 / 5. 6.101
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, lavfi, from 'anullsrc':
Duration: N/A, start: 0.000000, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
Guessed Channel Layout for Input Stream #1.1 : mono
Input #1, rtsp, from 'rtsp://10.x.x.x:554/user=user&password=password&channel=1&stream=0.sdp?real_stream':
Metadata:
title : RTSP Session
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #1:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 20 fps, 20 tbr, 90k tbn, 180k tbc
Stream #1:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 0, only the last option '-c:v copy' will be used.
Stream mapping:
Stream #1:0 -> #0:0 (copy)
Stream #0:0 -> #0:1 (pcm_u8 (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/mykey':
Metadata:
encoder : Lavf58.42.102
Stream #0:0: Video: h264 (Main) ([7][0][0][0] / 0x0007), yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 20 fps, 20 tbr, 1k tbn, 90k tbc
Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.82.100 aac
[flv @ 0x2c43750] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
Upvotes: 2
Views: 2208
Reputation: 133703
Your command is using the anullsrc filter to generate silent audio. YouTube requires an audio stream. So users often use anullsrc to make silent audio to fulfill this requirement if their input has no audio. ffmpeg
is using this silent audio instead of your camera's audio. Remove anullsrc because you don't need it.
Use:
ffmpeg -thread_queue_size 512 -rtsp_transport udp -i "rtsp://10.x.x.x:554/user=user&password=password&channel=1&stream=0.sdp?real_stream" -c:v copy -c:a aac -f flv rtmp://a.rtmp.youtube.com/live2/mykey
Because you are stream copying the video with -c:v copy
I removed the unnecessary encoding options that are being ignored anyway (-tune zerolatency -vcodec libx264 -use_wallclock_as_timestamps 1 -pix_fmt
).
I removed -strict experimental
. It used to be required when the FFmpeg AAC encoder was considered experimental, but that has not been the case since 2015. However, it is very often still copied and pasted from outdated answers.
Upvotes: 1