Wednesday, December 13, 2017

Shell Script for getting total video duration of any video

In this Shell Script we can  get the total video duration of any video.

ffmpeg -i $f 2>&1 | grep -oP "(?<=Duration: ).*(?=, start.*)";

Here $f is the file name like myvideo.mp4

Example

ffmpeg -i myvideo.mp4 2>&1 | grep -oP "(?<=Duration: ).*(?=, start.*)";

00:03:59.93

The above time in string.

 If you want to calculate the video time in second then use the following command

ffmpeg -i myvideo.mp4 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] }'


result is

 239 second

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...