Getting video dimension / resolution / width x height from ffmpeg

前端 未结 8 1574
粉色の甜心
粉色の甜心 2020-11-27 05:33

How would I get the height and width of a video from ffmpeg\'s information output. For example, with the following output:

$ ffmpeg -i video.mp4         


        
8条回答
  •  青春惊慌失措
    2020-11-27 05:58

    without re module

    out = error_message.split()               # make a list from resulting error string
    out.reverse()
    for index, item in enumerate(out):        # extract the item before item= "[PAR"
        if item == "[PAR":                      #
            dimension_string = out[i+1]          #
            video_width, video_height = dimension_string.split("x")
    

    Edit: not a good answer because not all videos have that "PAR" information :(

提交回复
热议问题