Problem retrieving correct fps while streaming cameras
Hi everyone, Hopefully it's the right palce to ask this kind of questions. I've have been trying to retrieve the fps information from different cameraz stream via RTSP. This is done using the OpenCV library which uses the libavormat provided by ffmpeg. However it seems I can't rely on the information returned by libav depending on the codec or the camera used. I would like to get a better understanding about how this frame rate are computed etc... OpenCV is trying to retrieve the fps of the stream using different properties of AVStream, r_frame_rate, avg_frame_rate and time_base. ////////// Code ////////// double CvCapture_FFMPEG::get_fps() const { #if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54, 1, 0) double fps = r2d(ic->streams[video_stream]->avg_frame_rate); #else double fps = r2d(ic->streams[video_stream]->r_frame_rate); #endif #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0) if (fps < eps_zero) { fps = r2d(ic->streams[video_stream]->avg_frame_rate); } #endif if (fps < eps_zero) { fps = 1.0 / r2d(ic->streams[video_stream]->codec->time_base); } return fps; } ///////////////////////////// I tried two different camera brands and two different codecs H264, and JPEG. Here are the results, I get: *Camera 1 running at 15fps (default value)* *camera 1, jpeg* r_frame_rate = 15/1 avg_frame_rate = 0/0 time_base = 1/ 90000 tick_per_frame = 1 *camera 1, h264* r_frame_rate = 15/1 avg_frame_rate = 15/2 time_base = 1/ 90000 tick_per_frame = 2 *Camera 2 running at 25fps default but the fps is changed within the rtsp url to 12* *camera 2, jpeg * r_frame_rate = 12/1 avg_frame_rate = 0/0 time_base = 1/ 90000 tick_per_frame = 1 *camera 2, h264 running at 12fps* r_frame_rate = 25/1 avg_frame_rate = 0/0 time_base = 1/ 90000 tick_per_frame = 2 Also i tried streaming using ffmpeg command line *CODE: **SELECT ALL* ffmpeg -i rtsp://url and it seems that only jpeg can return the expected fps. Here are the questions have been asking myself: 1/* what's really r_frame_rate? * It says in the api "[i]it is the smallest frame rate that can accurately represent all timestamps. For example, if you have mixed 25 and 30 fps content, then will be 150 (it is the least common multiple).[/i]" I doesn't make sense to me that it the same time the smallest frame rate (25) and the least common multiple (150). *2/ How is the avg_frame_rate computed? * I had a look at the code but couldn't really figure out how is this average computed. It seems that most of the time this is returning 0. *3/ Is there a bug getting the frame rate while using h264?* Using jpeg, it looks like r_frame_RATE can return the actual fps value, but h264 will not work. Are those information not available using h264? Any help would be appreciated, I spent two days trying to understand why i wasn't getting the correct values but at this point i'm pretty stuck. Thanks in advance! Romanzo
Corentin Hamel <corentin.hamel69 <at> gmail.com> writes:
Hopefully it's the right palce to ask this kind of questions. I've have been trying to retrieve the fps information from different cameraz stream via RTSP.
Please (also) test with ffmpeg, the application. Carl Eugen
If by application you mean command line, I've already tested it as mentioned in the previous post. ffmpeg streaming the rtsp retrieves only the correct frame rate for jpeg not for h264. Thanks On Tue, Apr 19, 2016 at 7:56 AM, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Corentin Hamel <corentin.hamel69 <at> gmail.com> writes:
Hopefully it's the right palce to ask this kind of questions. I've have been trying to retrieve the fps information from different cameraz stream via RTSP.
Please (also) test with ffmpeg, the application.
Carl Eugen
_______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user
-- Corentin Hamel
Corentin Hamel <corentin.hamel69 <at> gmail.com> writes:
ffmpeg streaming the rtsp retrieves only the correct frame rate for jpeg
not for h264.
Please show your command line together with the complete, uncut console output. Please do not top-post here, Carl Eugen
Here are the outputs, it looks like i made a mistake saying a could only retrieve correct fps with jpeg. Both jpeg and h264 give the expect fps. However still unable to get it using the ffmpeg API - *jpeg and 12fps* ffmpeg -i "rtsp:// root:pass@192.168.100.21:554/axis-media/media.amp?resolution=704x576&fps=12&camera=1&videocodec=jpeg" test.avi ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 7.0.2 (clang-700.1.81) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.1 --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-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 [mjpeg @ 0x7f8753000600] Changing bps to 8 Input #0, rtsp, from 'rtsp:// root:pass@192.168.100.21:554/axis-media/media.amp?resolution=704x576&fps=12&camera=1&videocodec=jpeg ': Metadata: title : Media Presentation Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 704x576 [SAR 1:1 DAR 11:9], 25 tbr, 90k tbn, 90k tbc [swscaler @ 0x7f8752833200] deprecated pixel format used, make sure you did set range correctly Output #0, avi, to 'test.avi': Metadata: INAM : Media Presentation ISFT : Lavf57.25.100 Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 704x576 [SAR 1:1 DAR 11:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc Metadata: encoder : Lavc57.24.102 mpeg4 Side data: unknown side data type 10 (24 bytes) Stream mapping: Stream #0:0 -> #0:0 (mjpeg (native) -> mpeg4 (native)) Press [q] to stop, [?] for help frame= 389 fps= 13 q=10.8 size= 905kB time=00:00:32.48 bitrate= 228.2kbits/s speed=1.06x - *h264 and 12pfs* fmpeg -i "rtsp:// root:pass@192.168.100.21:554/axis-media/media.amp?resolution=704x576&fps=12&camera=1&videocodec=h264" test2.avi ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 7.0.2 (clang-700.1.81) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.1 --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-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 Input #0, rtsp, from 'rtsp:// root:pass@192.168.100.21:554/axis-media/media.amp?resolution=704x576&fps=12&camera=1&videocodec=h264 ': Metadata: title : Media Presentation Duration: N/A, start: 0.079067, bitrate: N/A Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709), 704x576 [SAR 1:1 DAR 11:9], 25 tbr, 90k tbn, 180k tbc Output #0, avi, to 'test2.avi': Metadata: INAM : Media Presentation ISFT : Lavf57.25.100 Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 704x576 [SAR 1:1 DAR 11:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc Metadata: encoder : Lavc57.24.102 mpeg4 Side data: unknown side data type 10 (24 bytes) Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native)) Press [q] to stop, [?] for help frame= 303 fps= 13 q=9.5 size= 837kB time=00:00:25.12 bitrate= 273.1kbits/s speed=1.05x thanks On Tue, Apr 19, 2016 at 6:04 PM, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Corentin Hamel <corentin.hamel69 <at> gmail.com> writes:
ffmpeg streaming the rtsp retrieves only the correct frame rate for jpeg
not for h264.
Please show your command line together with the complete, uncut console output.
Please do not top-post here, Carl Eugen
_______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user
-- Corentin Hamel
participants (2)
-
Carl Eugen Hoyos -
Corentin Hamel