Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding with variable frame rate in ffmpeg

Tags:

ffmpeg

Till now I was doing all of my encoding using fixed frame (programmatically) using ffmpeg. Now I need to support variable frame rate. I started with just commenting the portion of my code which was setting frame rate. However it is not working. My function is failing at avcodec_open2. Please someone suggest me how to go about supporting the variable frame rate. Also I came to know not all codec support variable frame rate. So which codecs are normally used when encoding with variable frame rate. Please suggest.

Thanks Pradeep

like image 477
praks411 Avatar asked May 20 '13 09:05

praks411


1 Answers

I realize the post is pretty old, however I hope being able to help some folks having the same problem (I just did)...

Use the fps filter or the framerate filter. Being an ffpmeg n00b as well, there's no guarantee for 100% correctness, but at least this worked for me:

I created a filtergraph just like in the filtering_video.c example. For the filters argument of avfilter_graph_parse_ptr, I specified fps=fps=30:round=near, for example. Then I fed frames into the filtergraph whenever I got some, calculating the pts as

float fps = (float)( codecContext->time_base.num ) / codecContext->time_base.den;
this->frame->pts = (__int64)( ( timestamp - timestamp0 ) / fps );

where timestamp is the frame's time in seconds and timestamp0 is the time of the very first frame being recorded. Both are floating point values and result from my custom built timer. When you're using a library providing timestamps for your captured frames (such as DirectShow), you should of course use those.

like image 120
iko79 Avatar answered Nov 01 '22 09:11

iko79