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 _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user