How to extract the Motion Picture (mp4-Video) from a Google Pixel 6a

Started by supertobi, January 19, 2023, 09:43:51 AM

Previous topic - Next topic

supertobi

Hello,

I have a Pixel 6a and it is able to create "Motion Pictures". That are JPEGs with an movie in the metadata embedded. I'd like to extract the video. I tried different ways, but never got an video that VLC was able to play. Do you have an hint how to extract the Motion Picture (mp4-Video) from the file?

An example image is attached.
PXL_20230118_124418216.MP.jpg

StarGeek

If I extract the trailer data
exiftool -b -Trailer PXL_20230118_124418216.MP.jpg >test.mp4

I can see the file signature (66 74 79 70 69 73 6F 6D) for an MP4 at an offset of 0x423d. Since this signature is offset by 4 from the start of the file, if I delete everything before 0x423A, then I get a valid MP4.

Extracted file
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

@StarGeek: Nice!

Here is a command that will extract the video from all jpg images in a directory and store the videos with the same file name as the jpg but with extension .mp4:

exiftool -b -p "${trailer;s/.*(\0\0\0\x1cftypisom)/$1/s}" -ext jpg -w mp4 DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

supertobi

Wow, thanks, that works. I would never have been able to figure that out myself. Would you be so kind as to explain the "-p" parameter to me, please?

-b
Output metadata in binary format. That's what I've tried.

-p "${trailer;s/.*(\0\0\0\x1cftypisom)/$1/s}"
What the hell are you doing here? I found this link but it doesn't help me:
https://exiftool.org/exiftool_pod.html#Advanced-formatting-feature

-ext jpg
Process files with the specified extension

-w mp4
New filename extension

DIR
Directory or filename

Phil Harvey

Quote from: supertobi on January 20, 2023, 03:36:33 AM-p "${trailer;s/.*(\0\0\0\x1cftypisom)/$1/s}"
What the hell are you doing here? I found this link but it doesn't help me:
https://exiftool.org/exiftool_pod.html#Advanced-formatting-feature

This uses the advanced formatting feature as you surmised to remove everything before the MP4 header.  The "\0\0\0\x1cftypisom" string is the binary MP4 header.  ".*" is everything before that.  The s/// is the Perl substitution operator (ie. search and replace), and it replaces everything up to and including the header with just the header ("$1" is everything inside the brackets in the search pattern of the substitution operator).  Read about "regular expressions" if you want to know more about the syntax.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).


wywh

I wondered why macOS Sonoma 14.6.1 QuickLook displays only a thumbnail from that command's output PXL_20230118_124418216.MP.mp4 while QuickTime Player can play it OK.

exiftool -b -p '${trailer;s/.*(\0\0\0\x1cftypisom)/$1/s}' -ext jpg -w mp4 PXL_20230118_124418216.MP.jpg
    1 output files created

ls
PXL_20230118_124418216.MP.jpg PXL_20230118_124418216.MP.mp4

I could fix that by losslessly selecting just the correct stream:

ffmpeg -i PXL_20230118_124418216.MP.mp4 -map 0:0 -c copy output.mp4
ffprobe7 PXL_20230118_124418216.MP.mp4
ffprobe version 7.0.1 Copyright (c) 2007-2024 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
  configuration: --cc=/usr/bin/clang --datadir=/opt/local/libexec/ffmpeg7/share/data --docdir=/opt/local/libexec/ffmpeg7/share/doc --progs-suffix=7 --prefix=/opt/local/libexec/ffmpeg7 --enable-audiotoolbox --disable-indev=jack --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libplacebo --disable-libvmaf --disable-libwebp --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-metal --enable-opencl --disable-outdev=xv --enable-sdl2 --disable-securetransport --enable-videotoolbox --disable-xlib --enable-avfilter --enable-fontconfig --enable-gnutls --enable-lcms2 --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libfribidi --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libzimg --enable-libzvbi --enable-lzma --enable-pthreads --enable-shared --enable-swscale --enable-zlib --enable-libaom --enable-libsvtav1 --arch=x86_64 --enable-x86asm --enable-gpl --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-postproc
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'PXL_20230118_124418216.MP.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 131072
    compatible_brands: isomiso2mp41
    creation_time   : 2023-01-18T12:44:18.000000Z
  Duration: 00:00:02.73, start: 0.000000, bitrate: 12705 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 1440x1080, 12461 kb/s, SAR 1:1 DAR 4:3, 26.38 fps, 90k tbr, 90k tbn (default)
      Metadata:
        creation_time   : 2023-01-18T12:44:18.000000Z
        handler_name    : VideoHandle
        vendor_id       : [0][0][0][0]
      Side data:
        displaymatrix: rotation of -90.00 degrees
  Stream #0:1[0x2](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 2048x1536, SAR 1:1 DAR 4:3, 90k tbn (default)
      Metadata:
        creation_time   : 2023-01-18T12:44:18.000000Z
        handler_name    : VideoHandle
        vendor_id       : [0][0][0][0]
      Side data:
        displaymatrix: rotation of -90.00 degrees
  Stream #0:2[0x3](eng): Data: none (mett / 0x7474656D), 94 kb/s (default)
      Metadata:
        creation_time   : 2023-01-18T12:44:18.000000Z
        handler_name    : MetaHandle
  Stream #0:3[0x4](eng): Data: none (mett / 0x7474656D), 0 kb/s (default)
      Metadata:
        creation_time   : 2023-01-18T12:44:18.000000Z
        handler_name    : MetaHandle
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3

ffprobe7 output.mp4                   
ffprobe version 7.0.1 Copyright (c) 2007-2024 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
  configuration: --cc=/usr/bin/clang --datadir=/opt/local/libexec/ffmpeg7/share/data --docdir=/opt/local/libexec/ffmpeg7/share/doc --progs-suffix=7 --prefix=/opt/local/libexec/ffmpeg7 --enable-audiotoolbox --disable-indev=jack --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libplacebo --disable-libvmaf --disable-libwebp --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-metal --enable-opencl --disable-outdev=xv --enable-sdl2 --disable-securetransport --enable-videotoolbox --disable-xlib --enable-avfilter --enable-fontconfig --enable-gnutls --enable-lcms2 --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libfribidi --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libzimg --enable-libzvbi --enable-lzma --enable-pthreads --enable-shared --enable-swscale --enable-zlib --enable-libaom --enable-libsvtav1 --arch=x86_64 --enable-x86asm --enable-gpl --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-postproc
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:02.77, start: 0.000000, bitrate: 12295 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 1440x1080, 12290 kb/s, SAR 1:1 DAR 4:3, 26.02 fps, 29.42 tbr, 90k tbn (default)
      Metadata:
        handler_name    : VideoHandle
        vendor_id       : [0][0][0][0]
      Side data:
        displaymatrix: rotation of -90.00 degrees

- Matti