How to extract orientation information from videos?

后端 未结 6 1923
谎友^
谎友^ 2020-11-30 04:49

After surfing through tons of documentation on the web it seems that the iPhone always shoots the video at a 480x360 aspect ratio and applies a transformation matrix on the

6条回答
  •  日久生厌
    2020-11-30 05:47

    You can use ffprobe. No need for any grep, or any other additional processes, or any regex operations to parse the output as shown in other answers.

    If you want the rotate metadata:

    Command:

    ffprobe -loglevel error -select_streams v:0 -show_entries stream_tags=rotate -of default=nw=1:nk=1 input.mp4
    

    Example output:

    90
    

    If you want the display matrix rotation side data:

    Command:

    ffprobe -loglevel error -select_streams v:0 -show_entries side_data=rotation -of default=nw=1:nk=1 input.mp4
    

    Example output:

    -90
    

    If you want the display matrix:

    Command:

    ffprobe -loglevel error -select_streams v:0 -show_entries side_data=displaymatrix -of default=nw=1:nk=1 input.mp4
    

    Example output:

    00000000:            0       65536           0
    00000001:       -65536           0           0
    00000002:     15728640           0  1073741824
    

    What the options mean

    • -loglevel error Omit the header and other info from output.

    • -select_streams v:0 Only process the first video stream and ignore everything else. Useful if your input contains multiple video streams and you only want info from one.

    • -show_entries stream_tags=rotate Chooses to output the rotate tag from the video stream.

    • -of default=nw=1:nk=1 Use default output format, but omit including the section header/footer wrappers and each field key.

    Output format

    The output from ffprobe can be formatted in several ways. For example, JSON:

    ffprobe -loglevel error -show_entries stream_tags=rotate -of json input.mp4
    {
        "streams": [
            {
                "tags": {
                    "rotate": "90"
                },
                "side_data_list": [
                    {
    
                    }
                ]
            }
        ]
    

提交回复
热议问题