Bento4 icon indicating copy to clipboard operation
Bento4 copied to clipboard

mp4decrypt regression: Bento4 1.6 can no longer output correct file while Bento4 1.5.1.0 works

Open fireattack opened this issue 3 years ago • 5 comments

Hi,

I have a file that I can decrypt successfully using mp4decrypt.exe binary from Bento4 1.5.1.0, but the one in Bento4 1.6 or in master (downloaded from CI) will generate broken file that I can't play.

Trying to remux with ffmpeg cannot fix it (actually, ffmpeg will complain and drop the video stream entirely).

The file is attached.

enc_test.zip

The key is

b35ba32acf43e2865cb0771219af08d5:989d4b0938b6902471a10d77c0db753b.

My command is

mp4decrypt.exe --key "b35ba32acf43e2865cb0771219af08d5:989d4b0938b6902471a10d77c0db753b" "enc_test.mp4" "dec.mp4"

fireattack avatar Jun 29 '22 06:06 fireattack

I have just tried with release 1.5.1.0 and that also produces an unplayable output. I suspect that the key isn't the right one (unfortunately, there's no way to tell if they key is correct or not, other than the output being wrong). Can you double-check that you are indeed able to decrypt with that specific key and version 1.5.1.0 of the toolset?

barbibulle avatar Jul 17 '22 16:07 barbibulle

The output file isn't exactly perfect, but yeah, I can play it.

To play it better, you can use ffmpeg to remux it one more time.

fireattack avatar Jul 17 '22 18:07 fireattack

Here are all the logs:

E:\dedrm>test.bat

E:\dedrm>mp4decrypt1500.exe --key "b35ba32acf43e2865cb0771219af08d5:989d4b0938b6902471a10d77c0db753b" "enc_test.mp4" "dec1500.mp4"

E:\dedrm>ffmpeg -i "dec1500.mp4" -c copy "dec_1500_fixed.mp4"
ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dec1500.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41iso5iso6
  Duration: 08:10:12.01, start: 29393.993000, bitrate: 0 kb/s
  Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 0 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
    Side data:
      unknown side data type 24 (1159 bytes)
Output #0, mp4, to 'dec_1500_fixed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41iso5iso6
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 0 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
    Side data:
      unknown side data type 24 (1159 bytes)
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  540 fps=0.0 q=-1.0 Lsize=    3035kB time=00:00:17.97 bitrate=1383.4kbits/s speed=1.12e+03x
video:2600kB audio:416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.641947%

E:\dedrm>mp4decrypt1510.exe --key "b35ba32acf43e2865cb0771219af08d5:989d4b0938b6902471a10d77c0db753b" "enc_test.mp4" "dec1510.mp4"

E:\dedrm>ffmpeg -i "dec1510.mp4" -c copy "dec_1510_fixed.mp4"
ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dec1510.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41iso5iso6
  Duration: 08:10:12.01, start: 29393.993000, bitrate: 0 kb/s
  Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 0 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
    Side data:
      unknown side data type 24 (1159 bytes)
Output #0, mp4, to 'dec_1510_fixed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41iso5iso6
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 0 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
    Side data:
      unknown side data type 24 (1159 bytes)
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  540 fps=0.0 q=-1.0 Lsize=    3035kB time=00:00:17.97 bitrate=1383.4kbits/s speed=1.22e+03x
video:2600kB audio:416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.641947%

E:\dedrm>mp4decrypt1600.exe --key "b35ba32acf43e2865cb0771219af08d5:989d4b0938b6902471a10d77c0db753b" "enc_test.mp4" "dec1600.mp4"

E:\dedrm>ffmpeg -i "dec1600.mp4" -c copy "dec_1600_fixed.mp4"
ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[aac @ 0000020382730480] Number of scalefactor bands in group (55) exceeds limit (49).
[h264 @ 0000020382732c80] Invalid NAL unit size (1601270753 > 289310).
[h264 @ 0000020382732c80] Error splitting the input into NAL units.
[h264 @ 0000020382732c80] Invalid NAL unit size (217746675 > 807).
[h264 @ 0000020382732c80] Error splitting the input into NAL units.
[h264 @ 0000020382732c80] Invalid NAL unit size (217746675 > 116).
[h264 @ 0000020382732c80] Error splitting the input into NAL units.

...

[h264 @ 0000020382732c80] Invalid NAL unit size (217746675 > 73).
[h264 @ 0000020382732c80] Error splitting the input into NAL units.
[h264 @ 0000020382732c80] Invalid NAL unit size (217746675 > 289310).
[h264 @ 0000020382732c80] Error splitting the input into NAL units.
[h264 @ 0000020382732c80] Invalid NAL unit size (217746675 > 807).
[h264 @ 0000020382732c80] Error splitting the input into NAL units.
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002038271ae00] decoding for stream 1 failed
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002038271ae00] Could not find codec parameters for stream 1 (Video: h264 (avc1 / 0x31637661), none, 1920x1080, 0 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dec1600.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41iso5iso6
  Duration: 08:10:12.01, start: 29393.993000, bitrate: 0 kb/s
  Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Video: h264 (avc1 / 0x31637661), none, 1920x1080, 0 kb/s, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
    Side data:
      unknown side data type 24 (1159 bytes)
[mp4 @ 0000020382be0740] track 1: codec frame size is not set
Output #0, mp4, to 'dec_1600_fixed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41iso5iso6
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 0 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
    Side data:
      unknown side data type 24 (1159 bytes)
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)
    Metadata:
      handler_name    : Brightcove m4f generator
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  540 fps=0.0 q=-1.0 Lsize=    3035kB time=00:00:17.97 bitrate=1383.4kbits/s speed=1.71e+03x
video:2600kB audio:416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.642206%
E:\dedrm>

You can see that only 1600 generates broken output that ffmpeg can't even read properly.

All the output files:

dec_outputs.zip

fireattack avatar Jul 17 '22 18:07 fireattack

I see what's going on. A change made between 1.5.0 and 1.6.0 includes an improvement to how the decrypter complies with the spec. Prior to the change, the decrypter would first look for sample encryption IVs in the senc box, when present, and only look for saio and saiz boxes (sample aux info size and offset) when no senc is found. But saio and saiz are actually authoritative, and senc is purely a Microsoft PIFF data structure (older versions of the MS tools didn't use saio and saiz). In this file, the saio offsets are not correct, but the senc box is correct. So after the change, when the decrypter relies on the saio offsets, it gets the wrong IVs. I don't know how your encrypted file was generated, and if it was edited after being generated, but the result is that its saio offsets are incorrect. As a result, any compliant decrypted will fail to decrypt it.

barbibulle avatar Jul 17 '22 21:07 barbibulle

The file was directly ripped (without any modification) from an HLS stream served by commercial solution Brightcove (https://www.brightcove.com/en/).

fireattack avatar Aug 25 '22 15:08 fireattack

This seems to be fixed in v1.6.0-640.

Not sure which commit did it though, maybe 6ab668d60a897291644b7e184b1b8a47204cec9e?

fireattack avatar Jun 05 '23 12:06 fireattack