There are several methods to do that. I'd like to post one of the easiest way how I can find out the length of a video(media) file by using.
First of all, you need to install 'FFMPEG' with homebrew on mac (if you are using it). if you don't know how to install homebrew on MAC, you can check it on my blog link below
Here we go~,
Something similar to:
ffmpeg -i input 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//
This will deliver: HH:MM:SS.ms
. You can also use ffprobe
, which is supplied with most FFmpeg installations:
ffprobe -show_format input | sed -n '/duration/s/.*=//p'
… or:
ffprobe -show_format input | grep duration | sed 's/.*=//'
To convert into seconds (and retain the milliseconds), pipe into:
awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'
To convert it into milliseconds, pipe into:
awk '{ split($1, A, ":"); print 3600000*A[1] + 60000*A[2] + 1000*A[3] }'
If you want just the seconds without the milliseconds, pipe into:
awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'
EXAMPLES)
'Programming > Bash' 카테고리의 다른 글
[BASH] Make multiple screenshots into one image(tile, mosaic) by using ffmpeg (0) | 2017.02.06 |
---|---|
관리자권한으로 cron 설정하기. It's easy to use. (0) | 2016.06.10 |
나만의 유튜브 영상 다운로더 by using bash (0) | 2016.01.10 |
[BASH] 기본 BASH 업그레이드 및 활용하기 (1) | 2015.11.11 |
[Bash] Photos, Files auto sorting script on Windows,Linux,Mac by dates (0) | 2015.08.03 |