I needed a library to perform basic functions such as length, size, etc of a video file (i\'m guessing through the metadata or tags) so I chose ffmpeg. Vali
I had to add a call to
avformat_find_stream_info(pFormatCtx,NULL)
after avformat_open_input
to get mgiuca's answer to work. (can't comment on it)
#include
...
av_register_all();
AVFormatContext* pFormatCtx = avformat_alloc_context();
avformat_open_input(&pFormatCtx, filename, NULL, NULL);
avformat_find_stream_info(pFormatCtx,NULL)
int64_t duration = pFormatCtx->duration;
// etc
avformat_close_input(&pFormatCtx);
avformat_free_context(pFormatCtx);
The duration is in uSeconds, divide by AV_TIME_BASE to get seconds.