-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting packet duration #32
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I'm learning to use FFmpeg and I have a question regarding this packet duration calculation:
pkt->duration = stream->time_base.den / stream->time_base.num / stream->avg_frame_rate.num * stream->avg_frame_rate.den;
https://github.com/Raveler/ffmpeg-cpp/blob/master/source/ffmpeg-cpp/ffmpeg-cpp/Muxing/VideoOutputStream.cpp#L82
I have also experienced the incorrect total duration/frame rate with h264/mp4, if packet duration is not set.
When encoding, I have just set packets' duration to 1 as they come out of the encoder (fair enough for CFR content) and then call
av_packet_rescale_ts()
to rescale it to the stream timebase.Your calculation appears to be
(1/Tb) * (1/Fr)
, where Tb is the stream timebase and Fr is the stream average framerate.This will be constant for CFR streams, and equivalent to setting the duration to 1 before the rescale. So what is the benefit of doing this more complex calculation? If the stream is VFR isn't this duration pretty much always wrong? Isn't it kind of just a guess of the average frame duration so far/
Also, wouldn't it be better to use the AVRational math functions to do this calculation to prevent overflow and other potential issues.
e.g.:
pkt->duration = av_mul_q(av_inv_q(stream->time_base), av_inv_q(stream->avg_frame_rate));
I'd appreciate if you could offer any insight into this, and maybe explain why this line of code is the way it is.
Thank you!
-Nathan
The text was updated successfully, but these errors were encountered: