ffmpeg - 在 youtube live 上运行 ffmpeg 时没有声音

标签 ffmpeg youtube

尽管我对 ffmpeg 的了解有限,但我还是设法使用在树莓派上运行的 ffmpeg 将我的鸟箱相机直播到 youtube。相机也有音频,通过在带有 rtsp 的 windows 中使用本地 vlc,音频还可以。

但是,在 youtube 上没有声音(与 windows 本地使用的 rtsp 命令相同),我在 youtube studio 中看到了这个“警告”:“音频流的当前比特率 (0) 低于推荐的比特率。我们建议为音频流使用 128 Kbps 比特率。”

如何通过 youtube 获取声音?
这是我运行的命令。该命令是在网上找到的,我将其用于我的使用,并立即让视频工作:

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

最佳答案

您的命令正在使用 anullsrc 过滤器来生成静音音频。 YouTube 需要音频流。因此,如果用户的输入没有音频,则经常使用 anullsrc 制作静音音频来满足此要求。 ffmpeg正在使用此无声音频而不是相机的音频。删除 anullsrc 因为你不需要它。

利用:

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
  • 因为你是stream copying带有 -c:v copy 的视频我删除了无论如何都被忽略的不必要的编码选项( -tune zerolatency -vcodec libx264 -use_wallclock_as_timestamps 1 -pix_fmt )。
  • 我删除了 -strict experimental .当 FFmpeg AAC 编码器被认为是实验性的时,它曾经是必需的,但自 2015 年以来一直没有这种情况。但是,它仍然经常从过时的答案中复制和粘贴。
  • 关于ffmpeg - 在 youtube live 上运行 ffmpeg 时没有声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62052140/

    相关文章:

    php - YouTube API v3 PHP 获取 channel 中的总观看次数

    php - Youtube Analytics API问题?

    c++ - 是否有 Mac OS X 相当于 Windows 的命名管道

    iphone - 在 iOS 中使用 FFMPEG 进行 H.264 编码时未找到编解码器

    python-3.x - 将 numpy 数组通过管道传输到虚拟视频设备

    python - 如何解决错误 FileNotFoundError : [WinError 2] The system cannot find the file specified when using ffmpeg-python?

    c# - 在Windows Phone 8上从iframe播放YouTube视频

    java - 无法从 JSON 数据获取值 - YouTube API -

    youtube - 嵌入 Codenameone Youtube 视频

    opencv - FFmpeg 将输出更改为特定的像素格式?