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
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