How to remove or edit Exif from mp4 video?

后端 未结 2 1970
遇见更好的自我
遇见更好的自我 2021-01-30 22:47

I recorded a Full HD video with Samsung Galaxy II, when I uploaded it to YouTube I found that it turned to 90 degrees like Portrait layout 1080x1920 NOT 1920x1080. I found the c

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 23:38

    Mp4 files (and many others) use the MPEG-4 standard, which arranges the data inside it in little boxes called atoms. You can find a great description of atoms in this Page. In short, atoms are organized in a tree like structure, where an atom can be either the parent of other atoms or a container of data, but not both (although some people break this rule)

    In particular the atom you are looking for is called "tkhd" (Track Header). You can find a list of atoms here.

    Within this atom you will find metadata of the video. The structure of the "tkhd" atom is specified here

    Finally the chunk of metadata you need (which is not an atom), is called "Matrix Structure". From developer.apple.com:

    All values in the matrix are 32-bit fixed-point numbers divided as 16.16, except for the {u, v, w} column, which contains 32-bit fixed-point numbers divided as 2.30.

    This is shown in the following image:

    The 9 byte matrix starts in byte 48 of the "tkhd" atom. An example of a "matrix structure" for an orientation of 0° would be 1 0 0 0 1 0 0 0 1 (the identity matrix)

    SO!

    After all that, what you need is to modify this matrix. The next parragraph is taken from developer.apple.com:

    A transformation matrix defines how to map points from one coordinate space into another coordinate space. By modifying the contents of a transformation matrix, you can perform several standard graphics display operations, including translation, rotation, and scaling. The matrix used to accomplish two-dimensional transformations is described mathematically by a 3-by-3 matrix.

    This means that the transformation matrix defines a function, that maps each coordinate into a new one.

    Since you only need to rotate the image, simply modify the left most 2 x 3 matrix, which is defined by the bytes 0, 1, 3, 4, 6 and 7.

    Here are the 2 x 3 matrices I use to represent each orientation (values 0, 1, 3, 4, 6 and 7 of the 3x3 matrix):

    0°: (x', y') = (x, y)
    1 0
    0 1
    0 0

    90°: (x', y') = (height - y, x)
    0 1
    -1 0
    height 0

    180°: (x', y') = (widht - x, height - y)
    -1 0
    0 -1
    width height

    270°: (x', y') = (y, width - x)
    0 -1
    1 0
    0 width

    If you don't have them, the width and height can be obtained just after the matrix structure. They are also fixed point numbers of 4 bytes (16.16).

    It is quite probable your video metadata contains the 90° Matrix

    (Thanks to Phil Harvey, creator of Exiftool for his help and a wonderful software)

提交回复
热议问题