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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With