Get length of a video using regex and ffmpeg

后端 未结 6 1385
太阳男子
太阳男子 2021-02-01 21:36

From the following ffmpeg -i output, how would I get the length (00:35)--

$ ffmpeg -i 1video.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from \'/Users/d         


        
6条回答
  •  盖世英雄少女心
    2021-02-01 22:12

    Do you want to do this in a bare shell pipeline, or read the result in a calling program?

    /\s+Duration: ((\d\d):(\d\d):(\d\d)\.(\d+))/
    

    … is a PCRE that will split the result up (replace the \. with [;:.] if ffmpeg might output the duration in frames rather than fractional seconds). In a Unix pipeline:

    | grep Duration: | cut -f2- -d: | cut -f1 -d, | tr -d ' '
    

    There are of course a billion other ways to express this.

提交回复
热议问题