fileduration.c 334 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <libavformat/avformat.h>

#include "../util.h"

double fileduration(char *path)
{
	double res;
	AVFormatContext *demux;
	demux = 0;
	if (avformat_open_input(&demux, path, 0, 0) < 0)
		return 0;
	avformat_find_stream_info(demux, 0);
	res = demux->duration*av_q2d(AV_TIME_BASE_Q);
	avformat_close_input(&demux);
	return res;
}