How to extract the Photo/Video component of a MVIMG?

前端 未结 4 806
遥遥无期
遥遥无期 2021-02-13 23:17

The Google Pixel 2 and probably other phones since have the capability to cover \"Motion Photos\". These are saved as MVIMG and comparatively big.

I’m looking for a way

4条回答
  •  误落风尘
    2021-02-13 23:56

    The above suggestion using grep -F --byte-offset ... and dd does not work for me on macOS High Sierra as /usr/bin/grep outputs a wrong offset — I guess it yields the offset of the "line" which contains the word ftypmp4, i.e. the position of the previous LF character plus one. I might guess wrong, but anyway, this is my solution:

    for i in MVIMG*.jpg; do \
        perl -0777 -ne 's/^.*(....ftypmp4.*)$/$1/s && print' "$i" >"${i%.jpg}.mp4"; \
    done
    

    This uses the ability of perl to slurp in a whole file at once and treat it as one big string. If no ftypmp4 with at least four leading bytes is present, an empty file is created, if multiple are present, the last one is extracted.

    Similarly, to remove the video from all the files:

    for i in MVIMG*.jpg; do \
        perl -0777 -pi -e 's/^(.*?)....ftypmp4.*$/$1/s' "$i"; \
    done
    

    This uses the in-place editing feature of perl. Everything after the first occurrence of ftypmp4 with its four leading bytes is cut off. If there are no occurrences, the file is rewritten with its contents unchanged.

    (One might or might not need to set PERLIO=raw in the environment and/or unset the locale related variables to avoid UTF-8 interpretation, which could fail for binary files which happen to include byte sequences that violate the UTF-8 composition rules. In my tests with various MVIMG files no such problems occurred though.)

提交回复
热议问题