开发者

Finding the length of a video in Java and ffmpeg

Is there a way to find a length of a video using Java? I understand we can ma开发者_C百科ke use of ffmpeg to generated thumbnails and encode videos. But can it be used to get the length of the video?

Thanks and Regards Abishek R Srikaanth


If you just call ffmpeg -i filename it will print information about the file and you can parse the output to get needed information.


You should use ffprobe utility for this purpose. FFProbe normally comes with your FFMpeg distribution, please check the /bin folder. You can specify in what format XML (there is even an XSD for FFProbe output http://www.ffmpeg.org/schema/ffprobe.xsd) or JSON you want FFProbe to give you info about the video file.

So, for example:

ffprobe -loglevel error -show_format -show_streams video.mp4 -print_format xml=x=1 -noprivate

will give you output in valid XML.

Please, look at the duration attribute of a 'video' stream section. This will be the duration of the video in seconds.



(avconv -i $FILE_NAME 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'

Use this command to get the duration in seconds

avconv and ffmpeg are same . In Ubuntu 13.10 and above ffmpeg is replaced by avconv

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜