我有一個視頻,它具有23.98 fps,這可以從命令行中的Quicktime和ffmpeg中看到。錯誤地,OpenCV認爲它有23 fps。我有興趣從ffmpeg中找到一個編程方式來查找視頻fps'。ffmpeg,C++ - 在程序中獲取fps
1
A
回答
1
快速查看OpenCV的來源顯示如下:
double CvCapture_FFMPEG::get_fps()
{
double fps = r2d(ic->streams[video_stream]->r_frame_rate);
#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;
}
所以看起來很正確。也許通過這個部分運行一個調試會話來驗證這個值? AVStream的avg_frame_rate
是AVRational
,所以它應該能夠保持精確的值。也許如果你的代碼使用第二個if塊,由於舊的ffmpeg版本time_base
設置不正確?
編輯
如果調試看看,如果r_frame_rate
和avg_frame_rate
不同,因爲至少根據this他們往往基於用於編解碼器不同。由於您沒有提及視頻格式,所以很難猜測,但似乎至少在H264中,您應該直接使用avg_ frame_rate
,並且從r_frame_rate
獲得的值可能會造成混亂。
0
從libavformat
版本55.1.100
發佈於2013-03-29,av_guess_frame_rate()
已添加。
/**
* Guess the frame rate, based on both the container and codec information.
*
* @param ctx the format context which the stream is part of
* @param stream the stream which the frame is part of
* @param frame the frame for which the frame rate should be determined, may be NULL
* @return the guessed (valid) frame rate, 0/1 if no idea
*/
AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame);
1
要使用FFMPEG-C++
/* find first stream */
for(int i=0; i<pAVFormatContext->nb_streams ;i++)
{
if(pAVFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
/* if video stream found then get the index */
{
VideoStreamIndx = i;
break;
}
}
/* if video stream not availabe */
if((VideoStreamIndx) == -1)
{
std::cout<<"video streams not found"<<std::endl;
return -1;
}
/* get video fps */
int videoFPS = av_q2d(ptrAVFormatContext->streams[VideoStreamIndx]->r_frame_rate);
std::cout<<"fps :"<<videoFPS<<std::endl;
相關問題
- 1. 在錄製視頻中增加fps ffmpeg
- 2. 從ffmpeg獲取不正確的輸出分辨率或FPS
- 3. 正則表達式:從FFMPEG獲取FPS日誌
- 4. 在iOS中獲取視頻的FPS
- 5. Windows窗體,獲取FPS?
- 6. 在C#中獲取程序圖標?
- 7. 在C中獲取KB修補程序#
- 8. 在C程序中獲取方法
- 9. 在C程序中獲取MX記錄
- 10. 在C中獲取和安裝程序#
- 11. 如何在Android上使用FFMPEG APIs以30 fps提取幀?
- 12. 從C++程序中調用ffmpeg
- 13. 獲取當前OpenCV的FPS
- 14. C - FFmpeg流媒體從C程序?
- 15. C++ videoplayer ffmpeg:獲取像素數據?
- 16. 更改fps while循環導出ffmpeg
- 17. ffmpeg -r/fps隨着時間的推移?
- 18. FPS延遲調度程序?
- 19. 使用ffmpeg將mp4轉換爲gif時使用ffmpeg下載fps
- 20. ffmpeg C++和AVFormatContext
- 21. 獲取MPI程序中的節點C
- 22. 獲取在C#應用程序
- 23. 有沒有辦法在spritekit中讀取/獲取fps swift
- 24. FPS在FFMPEG流媒體流程中從生產服務器下載到FB
- 25. C++ linux - 在C++ linux應用程序中獲取IP
- 26. 在c程序中獲取指向C++函數庫的指針
- 27. 在我的iphone應用程序中使用C庫(ffmpeg)
- 28. 有沒有在c#應用程序中使用ffmpeg的方法?
- 29. ANSI C:在恆定的FPS
- 30. 使用NVENC編解碼器在60 fps下使用FFmpeg進行桌面抓取
命令行版本的ffmpeg的FPS我用的就是每秒(fps)的值的視頻幀'的ffmpeg -i yourfilenamehere.avi -vcodec複製-acodec副本-f null/dev/null 2>&1 | grep'frame ='| cut -f 2 -d'''in linux或'ffmpeg -i yourfilenamehere.avi -vcodec copy -acodec copy -f null/dev/null 2>&1 | findstr'frame =''在窗口中(xp向上) – GMasucci