Using ffmpeg to obtain video durations in python

后端 未结 7 1113
故里飘歌
故里飘歌 2020-12-10 06:46

I\'ve installed ffprobe using the pip ffprobe command on my PC, and installed ffmpeg from here.

However, I\'m still having trouble running the code listed here.

7条回答
  •  长情又很酷
    2020-12-10 07:00

    There is no need to iterate though the output of FFprobe. There is one simple command which returns only the duration of the input file:

    ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 
    

    You can use the following method instead to get the duration:

    def get_length(input_video):
        result = subprocess.run(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', input_video], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        return float(result.stdout)
    

提交回复
热议问题