Get length of a video using regex and ffmpeg

后端 未结 6 1390
太阳男子
太阳男子 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:19

    This way you get the duration in seconds. I think this is more convenient.

    ffprobe -loglevel error -show_streams inputFile.mp3 | grep duration | cut -f2 -d=
    

    ffprobe comes with ffmpeg so you should have it.


    EDIT: For a more dedicated version you could use for example

    ffprobe -loglevel error -show_format -show_streams inputFile.extension -print_format json
    

    Instead of JSON you could also use e.g. CSV or XML. For more output options look here http://ffmpeg.org/ffprobe.html#Writers

提交回复
热议问题