[FFmpeg-user] Get video duration programmatically for encoding

killkenny64 kennethjjgibson at gmail.com
Thu Feb 2 23:18:39 CET 2012


I'm trying to figure out the duration of a video that I have decoded so that
I can encode it correctly.

I noticed some fields in AVFormatContext and AVStream that seem to be useful
however I can't seem to make heads nor tails of the values I'm getting.

If I look at inputFormatCtx->streams[videoStream]->duration, the value seems
to change every time I run my program. I get values like 1220560, 505248,
1333280 etc.

inputFormatCtx->streams[videoStream]->time_base is always 1, so I'm not sure
how I can use it to calculate the duration.

inputFormatCtx->duration at least stays the same each time I run my program
but I get the value of 1336792 so I'm unsure how to use this value.

I know that I can use the frame rate and the total number of frames to
calculate the duration, but I dont know the total number of frames until
I've iterated through them all.

Any help would be much appreciated, thanks! =)

View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Get-video-duration-programmatically-for-encoding-tp4353031p4353031.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.

More information about the ffmpeg-user mailing list