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

前端 未结 4 894
遥遥无期
遥遥无期 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-14 00:11

    The non-perl shell scripts at the top of the post worked on my Linux system. I merged them into a single shell script that preserves the input file (like MVIMG_20191216_153039.jpg) and creates two output files (like IMG_20191216_153039.jpg and IMG_20191216_153039.mp4):

    #!/bin/bash
    # extract-mvimg: Extract .mp4 video and .jpg still image from a Pixel phone
    # camera "motion video" file with a name like MVIMG_20191216_153039.jpg
    # to make files like IMG_20191216_153039.jpg and IMG_20191216_153039.mp4
    #
    # Usage: extract-mvimg MVIMG*.jpg [MVIMG*.jpg...]
    
    for srcfile
    do
      case "$srcfile" in
      MVIMG_*_*.jpg) ;;
      *)
        echo "extract-mvimg: skipping '$srcfile': not an MVIMG*.jpg file?" 2>&1
        continue
        ;;
      esac
    
      # Get base filename: strip leading MV and trailing .jpg
      # Example: MVIMG_20191216_153039.jpg becomes IMG_20191216_153039
      basefile=${srcfile#MV}
      basefile=${basefile%.jpg}
    
      # Get byte offset. Example output: 2983617:ftypmp4
      offset=$(grep -F --byte-offset --only-matching --text ftypmp4 "$srcfile")
      # Strip trailing text. Example output: 2983617
      offset=${offset%:*}
    
      # If $offset isn't an empty string, create .mp4 file and
      # truncate a copy of input file to make .jpg file.
      if [[ $offset ]]
      then
        dd status=none "if=$srcfile" "of=${basefile}.mp4" bs=$((offset-4)) skip=1
        cp -ip "$srcfile" "${basefile}.jpg" || exit 1
        truncate -s $((offset-4)) "${basefile}.jpg"
      else
        echo "extract-mvimg: can't find ftypmp4 in $srcfile; skipping..." 2>&1
      fi
    done
    

    The status=none suppresses the "1+1 records in" and "1+1 records out" status output from dd. If your dd doesn't understand, you can remove that.

提交回复
热议问题