Keepalivetypes和频率在ffmpeg

我的公司有一大堆我们分发的IP摄像机,特别是Grandstream,制造商已经改变了他们的固件。 ffmpeg用于rtspstream(ff_rtsp_send_cmd_async(s,“GET_PARAMETER”,rt-> control_uri,NULL)或ff_rtsp_send_cmd_async(s,“OPTIONS”,“*”,NULL)的常规保持活动;都位于libavformat / rtspdec中.c)不再有效,原因有二:

1)新的Grandstream固件现在正在检查接收器报告,以确定读取stream的程序是否是实时的,而不仅仅是任何事情。

2)新的Grandstream固件要求接收器报告至less每25秒保持一次连接,而audiostream目前只发生约30秒左右的事件(video每7秒钟左右收到一次)。

因此,ffmpeg连接大约一分钟后,摄像机停止发送audiostream,ffmpeg上的audiostream读取文件结束,然后ffmpegclosures所有内容。

由于我无法更改固件,我试图挖掘ffmpeg代码,使它发送适当的接收器报告保持活着…但我没有得到任何地方。 我已经在接收器报告中添加了一小段代码,所以我知道在debugging时调用ffmpeg的时候他们正在运行,但是… …不好。

testing命令:ffmpeg -loglevel debug -i rtsp:// admin:[email protected]:554/0 -acodec libmp3lame -ar 22050 -vcodec copy -y -f flv / dev / null&> test.txt

testing输出:

`[root@localhost ffmpeg]# cat test.txt ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers built on Aug 21 2013 14:24:28 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-3) configuration: --datadir=/usr/share/ffmpeg --bindir=/usr/local/bin --libdir=/usr/local/lib --incdir=/usr/local/include --shlibdir=/usr/lib --mandir=/usr/share/man --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables' --enable-avfilter --enable-libx264 --enable-gpl --enable-version3 --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-x11grab --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-static --enable-libgsm --enable-libxvid --enable-libvpx --enable-libvorbis --enable-libvo-aacenc --enable-libmp3lame libavutil 52. 38.100 / 52. 38.100 libavcodec 55. 18.102 / 55. 18.102 libavformat 55. 12.100 / 55. 12.100 libavdevice 55. 3.100 / 55. 3.100 libavfilter 3. 79.101 / 3. 79.101 libswscale 2. 3.100 / 2. 3.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 Splitting the commandline. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-i' ... matched as input file with argument 'rtsp://admin:[email protected]:554/0'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'libmp3lame'. Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '22050'. Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'. Reading option '/dev/null' ... 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 rtsp://admin:[email protected]:554/0. Successfully parsed a group of options. Opening an input file: rtsp://admin:[email protected]:554/0. [rtsp @ 0x9d9ccc0] SDP: v=0 o=StreamingServer 3331435948 1116907222000 IN IP4 192.168.4.3 s=h264.mp4 c=IN IP4 0.0.0.0 t=0 0 a=control:* m=video 0 RTP/AVP 96 a=control:trackID=0 a=rtpmap:96 H264/90000 a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LgHtoCgPRA,aM4wpIA= m=audio 0 RTP/AVP 0 a=control:trackID=1 a=rtpmap:0 PCMU/8000 a=ptime:20 m=application 0 RTP/AVP 107 a=control:trackID=2 a=rtpmap:107 vnd.onvif.metadata/90000 [rtsp @ 0x9d9ccc0] video codec set to: h264 [NULL @ 0x9d9f400] RTP Packetization Mode: 1 [NULL @ 0x9d9f400] Extradata set to 0x9d9f900 (size: 22)! [rtsp @ 0x9d9ccc0] audio codec set to: pcm_mulaw [rtsp @ 0x9d9ccc0] audio samplerate set to: 8000 [rtsp @ 0x9d9ccc0] audio channels set to: 1 [rtsp @ 0x9d9ccc0] hello state=0 [h264 @ 0x9d9f400] Current profile doesn't provide more RBSP data in PPS, skipping Last message repeated 1 times [rtsp @ 0x9d9ccc0] All info found Guessed Channel Layout for Input Stream #0.1 : mono Input #0, rtsp, from 'rtsp://admin:[email protected]:554/0': Metadata: title : h264.mp4 Duration: N/A, start: 0.000000, bitrate: 64 kb/s Stream #0:0, 28, 1/90000: Video: h264 (Constrained Baseline), yuv420p, 640x480, 1/180000, 10 tbr, 90k tbn, 180k tbc Stream #0:1, 156, 1/8000: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s Successfully opened the file. Parsing a group of options: output file /dev/null. Applying option acodec (force audio codec ('copy' to copy stream)) with argument libmp3lame. Applying option ar (set audio sampling rate (in Hz)) with argument 22050. Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy. Applying option f (force format) with argument flv. Successfully parsed a group of options. Opening an output file: /dev/null. Successfully opened the file. detected 2 logical cores [graph 0 input from stream 0:1 @ 0x9f15380] Setting 'time_base' to value '1/8000' [graph 0 input from stream 0:1 @ 0x9f15380] Setting 'sample_rate' to value '8000' [graph 0 input from stream 0:1 @ 0x9f15380] Setting 'sample_fmt' to value 's16' [graph 0 input from stream 0:1 @ 0x9f15380] Setting 'channel_layout' to value '0x4' [graph 0 input from stream 0:1 @ 0x9f15380] tb:1/8000 samplefmt:s16 samplerate:8000 chlayout:0x4  Setting 'sample_fmts' to value 's32p|fltp|s16p'  Setting 'sample_rates' to value '22050'  Setting 'channel_layouts' to value '0x4|0x3'  auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format for output stream 0:1' [AVFilterGraph @ 0x9f15980] query_formats: 4 queried, 9 merged, 3 already done, 0 delayed [auto-inserted resampler 0 @ 0x9dfada0] ch:1 chl:mono fmt:s16 r:8000Hz -> ch:1 chl:mono fmt:s16p r:22050Hz Output #0, flv, to '/dev/null': Metadata: title : h264.mp4 encoder : Lavf55.12.100 Stream #0:0, 0, 1/1000: Video: h264 ([7][0][0][0] / 0x0007), yuv420p, 640x480, 1/90000, q=2-31, 1k tbn, 90k tbc Stream #0:1, 0, 1/1000: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 22050 Hz, mono, s16p Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (pcm_mulaw -> libmp3lame) Press [q] to stop, [?] for help Current profile doesn't provide more RBSP data in PPS, skippingrate= 135.4kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 134.4kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 135.0kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 135.5kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 136.9kbits/s Queue input is backward in time= 233kB time=00:00:13.69 bitrate= 139.4kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 136.3kbits/s [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 13926; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 13952; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 13979; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14005; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14031; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14057; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14083; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14109; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14135; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14161; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14188; changing to 14239. This may result in incorrect timestamps in the output file. [flv @ 0x9de1200] Non-monotonous DTS in output stream 0:1; previous: 14239, current: 14214; changing to 14239. This may result in incorrect timestamps in the output file. Current profile doesn't provide more RBSP data in PPS, skippingrate= 141.5kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 142.0kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 142.5kbits/s Receiver Report delay: 469789, gettime: -1527669086, last_recep: 322446, timebase: -1534837492 Current profile doesn't provide more RBSP data in PPS, skippingrate= 141.5kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 141.7kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 141.1kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 140.6kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 140.7kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.9kbits/s Receiver Report delay: 132993, gettime: -1516538925, last_recep: 322446, timebase: -1518568234 Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.6kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.6kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.7kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.4kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 140.0kbits/s Receiver Report delay: 897727, gettime: -1504870331, last_recep: 322446, timebase: -1518568552 [NULL @ 0x9d9f400] Current profile doesn't provide more RBSP data in PPS, skipping Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.4kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.1kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.0kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 139.0kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 138.6kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 138.5kbits/s Current profile doesn't provide more RBSP data in PPS, skippingrate= 138.2kbits/s EOF on sink link output stream 0:1:default.time=00:00:58.40 bitrate= 139.6kbits/s No more output streams to write to, finishing. [libmp3lame @ 0x9dfa580] Trying to remove 344 more samples than there are in the queue frame= 589 fps= 11 q=-1.0 Lsize= 1003kB time=00:00:58.85 bitrate= 139.5kbits/s video:724kB audio:231kB subtitle:0 global headers:0kB muxing overhead 4.955356% 2959 frames successfully decoded, 0 decoding errors [AVIOContext @ 0x9e021c0] Statistics: 3 seeks, 2860 writeouts [root@localhost ffmpeg]# 

而且…我想我find了。 有趣的是能够做到这一点全职工作。 我现在正在进行一些testing,但是我明确地说明了与之前一起工作的一分钟的时间(很多 – 当我打字的时候,我长达一个小时45分钟):

在libavformat / rtpdec.c函数ff_rtp_check_and_send_back_rr中,有一行表示“rtcp_bytes / = 50;” – 这个数字似乎控制了发送接收者报告的频率。 降低它会更频繁地发生。