我正在使用 ffmpeg 使用以下命令将视频流式传输到流媒体引擎(nginx-rtmp):
ffmpeg -re -fflags +genpts -stream_loop -1 -i Sintel.mp4 -c copy -f flv rtmp://stream-engine/myStream
然而,当我ffprobe
直接对流媒体引擎进行这种流式传输时,有时流中没有视频。
测试流的命令:ffprobe -loglevel 'debug' rtmp://stream-engine/mystream
95%我得到以下输出:
ffprobe version 3.0.2 Copyright (c) 2007-2016 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libvorbis --enable-libvpx --enable-vda libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [rtmp @ 0x7ff57e4028a0] No default whitelist set [tcp @ 0x7ff57e402d40] No default whitelist set [rtmp @ 0x7ff57e4028a0] Handshaking... [rtmp @ 0x7ff57e4028a0] Type answer 3 [rtmp @ 0x7ff57e4028a0] Server version 13.14.10.13 [rtmp @ 0x7ff57e4028a0] Proto = rtmp, path = /source/myStream, app = source, fname = myStream [rtmp @ 0x7ff57e4028a0] Server bandwidth = 5000000 [rtmp @ 0x7ff57e4028a0] Client bandwidth = 5000000 [rtmp @ 0x7ff57e4028a0] New incoming chunk size = 4096 [rtmp @ 0x7ff57e4028a0] Creating stream... [rtmp @ 0x7ff57e4028a0] Sending play command for 'myStream' [flv @ 0x7ff57f002e00] Format flv probed with size=2048 and score=100 [flv @ 0x7ff57f002e00] Before avformat_find_stream_info() pos: 13 bytes read:2266 seeks:0 [flv @ 0x7ff57f002e00] Unknown type |RtmpSampleAccess [flv @ 0x7ff57f002e00] video stream discovered after head already parsed [h264 @ 0x7ff580000000] no picture [flv @ 0x7ff57f002e00] All info found [flv @ 0x7ff57f002e00] rfps: 23.750000 0.014474 [flv @ 0x7ff57f002e00] rfps: 23.833333 0.006451 Last message repeated 1 times [flv @ 0x7ff57f002e00] rfps: 23.916667 0.001640 Last message repeated 1 times [flv @ 0x7ff57f002e00] rfps: 24.000000 0.000043 [flv @ 0x7ff57f002e00] rfps: 24.083333 0.001659 Last message repeated 1 times [flv @ 0x7ff57f002e00] rfps: 24.166667 0.006488 Last message repeated 1 times [flv @ 0x7ff57f002e00] rfps: 24.250000 0.014530 [flv @ 0x7ff57f002e00] rfps: 48.000000 0.000173 [flv @ 0x7ff57f002e00] rfps: 120.000000 0.001079 [flv @ 0x7ff57f002e00] rfps: 240.000000 0.004316 [flv @ 0x7ff57f002e00] rfps: 23.976024 0.000173 Last message repeated 1 times [flv @ 0x7ff57f002e00] rfps: 47.952048 0.000694 Last message repeated 1 times [flv @ 0x7ff57f002e00] After avformat_find_stream_info() pos: 345943 bytes read:345943 seeks:0 frames:256 Input #0, flv, from 'rtmp://stream-engine/myStream': Metadata: Server : NGINX RTMP (github.com/arut/nginx-rtmp-module) displayWidth : 1280 displayHeight : 544 fps : 24 profile : level : Duration: 00:00:00.00, start: 186.878000, bitrate: N/A Stream #0:0, 215, 1/1000: Audio: aac (LC), 48000 Hz, 5.1, fltp, 128 kb/s Stream #0:1, 41, 1/1000: Video: h264 (High), 4 reference frames, yuv420p(left), 1280x544 [SAR 1:1 DAR 40:17], 1/48, 24.42 fps, 24 tbr, 1k tbn, 48 tbc detected 4 logical cores [AVIOContext @ 0x7ff57e60cec0] Statistics: 345943 bytes read, 0 seeks [rtmp @ 0x7ff57e4028a0] Deleting stream...
一切都很好,我获得了视频和音轨。
5% 的时间里我会得到以下信息:
ffprobe version 3.0.2 Copyright (c) 2007-2016 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libvorbis --enable-libvpx --enable-vda libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [rtmp @ 0x7fe5cb407900] No default whitelist set [tcp @ 0x7fe5cb408100] No default whitelist set [rtmp @ 0x7fe5cb407900] Handshaking... [rtmp @ 0x7fe5cb407900] Type answer 3 [rtmp @ 0x7fe5cb407900] Server version 13.14.10.13 [rtmp @ 0x7fe5cb407900] Proto = rtmp, path = /source/myStream, app = source, fname = myStream [rtmp @ 0x7fe5cb407900] Server bandwidth = 5000000 [rtmp @ 0x7fe5cb407900] Client bandwidth = 5000000 [rtmp @ 0x7fe5cb407900] New incoming chunk size = 4096 [rtmp @ 0x7fe5cb407900] Creating stream... [rtmp @ 0x7fe5cb407900] Sending play command for 'myStream' [flv @ 0x7fe5cb800a00] Format flv probed with size=2048 and score=100 [flv @ 0x7fe5cb800a00] Before avformat_find_stream_info() pos: 13 bytes read:2288 seeks:0 [flv @ 0x7fe5cb800a00] Unknown type |RtmpSampleAccess [flv @ 0x7fe5cb800a00] max_analyze_duration 5000000 reached at 5019000 microseconds st:0 [flv @ 0x7fe5cb800a00] After avformat_find_stream_info() pos: 87188 bytes read:87188 seeks:0 frames:241 Input #0, flv, from 'rtmp://stream-engine/myStream': Metadata: Server : NGINX RTMP (github.com/arut/nginx-rtmp-module) displayWidth : 1280 displayHeight : 544 fps : 24 profile : level : Duration: 00:00:00.00, start: 343.593000, bitrate: N/A Stream #0:0, 241, 1/1000: Audio: aac (LC), 48000 Hz, 5.1, fltp, 128 kb/s [AVIOContext @ 0x7fe5cb604480] Statistics: 87188 bytes read, 0 seeks [rtmp @ 0x7fe5cb407900] Deleting stream...
我们尝试了很多选项、很多编码器。我们用不同的流源(ffmpeg、wowzaGoCoder、wirecast)和不同的流媒体引擎(wowza、nginx-rtmp)重现了它。有些配置使重现更加困难,但仍然会发生……
同一条流怎么会“有时”会有视频轨道?我们遗漏了什么?我们如何才能让它对这种(非常令人沮丧的)错误更具弹性?
编辑:
如果我们录制流,并且它没有检测到视频轨道,则日志会在一段时间后显示检测到视频轨道,但由于录制已经在没有视频轨道的情况下开始,因此录制的流没有视频轨道。
流录制日志ffmpeg -loglevel debug -y -i rtmp://stream-engine/myStream -c copy -f flv output.flv
:
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libvorbis --enable-libvpx --enable-vda libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 Splitting the commandline. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-i' ... matched as input file with argument 'rtmp://stream-engine/myStream'. Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'. Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'. Reading option 'output.flv' ... matched as output file. Finished splitting the commandline. Parsing a group of options: global . Applying option loglevel (set logging level) with argument debug. Applying option y (overwrite output files) with argument 1. Successfully parsed a group of options. Parsing a group of options: input file rtmp://stream-engine/myStream. Successfully parsed a group of options. Opening an input file: rtmp://stream-engine/myStream. [rtmp @ 0x7fa1a5d00c60] No default whitelist set [tcp @ 0x7fa1a5c0dac0] No default whitelist set [rtmp @ 0x7fa1a5d00c60] Handshaking... [rtmp @ 0x7fa1a5d00c60] Type answer 3 [rtmp @ 0x7fa1a5d00c60] Server version 13.14.10.13 [rtmp @ 0x7fa1a5d00c60] Proto = rtmp, path = /source/S1IwVWndb, app = source, fname = S1IwVWndb [rtmp @ 0x7fa1a5d00c60] Server bandwidth = 5000000 [rtmp @ 0x7fa1a5d00c60] Client bandwidth = 5000000 [rtmp @ 0x7fa1a5d00c60] New incoming chunk size = 4096 [rtmp @ 0x7fa1a5d00c60] Creating stream... [rtmp @ 0x7fa1a5d00c60] Sending play command for 'S1IwVWndb' [flv @ 0x7fa1a6801200] Format flv probed with size=2048 and score=100 [flv @ 0x7fa1a6801200] Before avformat_find_stream_info() pos: 13 bytes read:2271 seeks:0 [flv @ 0x7fa1a6801200] Unknown type |RtmpSampleAccess [flv @ 0x7fa1a6801200] max_analyze_duration 5000000 reached at 5019000 microseconds st:0 [flv @ 0x7fa1a6801200] After avformat_find_stream_info() pos: 87184 bytes read:87184 seeks:0 frames:241 Input #0, flv, from 'rtmp://stream-engine/myStream': Metadata: Server : NGINX RTMP (github.com/arut/nginx-rtmp-module) displayWidth : 1280 displayHeight : 544 fps : 24 profile : level : Duration: 00:00:00.00, start: 344.126000, bitrate: N/A Stream #0:0, 241, 1/1000: Audio: aac (LC), 48000 Hz, 5.1, fltp, 128 kb/s Successfully opened the file. Parsing a group of options: output file output.flv. Applying option c (codec name) with argument copy. Applying option f (force format) with argument flv. Successfully parsed a group of options. Opening an output file: output.flv. [file @ 0x7fa1a5c1cec0] Setting default whitelist 'file,crypto' Successfully opened the file. Output #0, flv, to 'output.flv': Metadata: Server : NGINX RTMP (github.com/arut/nginx-rtmp-module) displayWidth : 1280 displayHeight : 544 fps : 24 profile : level : encoder : Lavf57.25.100 Stream #0:0, 0, 1/1000: Audio: aac (LC) ([10][0][0][0] / 0x000A), 48000 Hz, 5.1, 128 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Press [q] to stop, [?] for help cur_dts is invalid (this is harmless if it occurs once at the start per stream) [flv @ 0x7fa1a6801200] video stream discovered after head already parsed [flv @ 0x7fa1a6801200] New video stream 0:1 at pos:144269 and DTS:352.667s size= 371kB time=00:00:22.57 bitrate= 134.6kbits/s speed= 1.3x video:0kB audio:353kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.082170% Input file #0 (rtmp://stream-engine/myStream): Input stream #0:0 (audio): 1058 packets read (361263 bytes); Total: 1058 packets (361263 bytes) demuxed Output file #0 (output.flv): Output stream #0:0 (audio): 1058 packets muxed (361263 bytes); Total: 1058 packets (361263 bytes) muxed 0 frames successfully decoded, 0 decoding errors [AVIOContext @ 0x7fa1a5c1cf80] Statistics: 3 seeks, 1061 writeouts [AVIOContext @ 0x7fa1a5d00fa0] Statistics: 2401247 bytes read, 0 seeks [rtmp @ 0x7fa1a5d00c60] Deleting stream..
答案1
感谢 mulvya 的评论:收到的流没有一致的视频轨道,增加 analyzeration 和probesize 的值可以使 ffmpeg 有更多机会检测到正确处理流所需的所有信息。
根据 ffmpeg 文档的默认值:https://ffmpeg.org/ffmpeg-formats.html#Format-Options是:
- 分析时长为 5s
- 探针大小为 5 MB
这对于高质量流来说还不够。