DavidBuchanan314 / DeCENC

Tools for decrypting MPEG-CENC files without knowledge of the key
https://phrack.org/issues/71/6.html#article
MIT License
99 stars 6 forks source link

AssertionError when running testall.sh or server.py #3

Open Vitaspiros opened 1 month ago

Vitaspiros commented 1 month ago

When trying to run ./testall.sh this is the output I get:

+ ffmpeg -y -hide_banner -loglevel error -fflags +genpts -i - -vcodec copy -movflags frag_keyframe+empty_moov+default_base_moof -bsf:v h264_metadata=video_full_range_flag=0 -f mp4 -
+ python3 splice_metadata.py test.db /dev/stdin /dev/stdout video
y4m [info]: 128x64p 1:1 @ 60/1 fps (cfr)
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x264 [info]: profile High, level 1.1, 4:2:0, 8-bit
x264 [info]: frame I:222   Avg QP:19.39  size: 12399                           
x264 [info]: mb I  I16..4..PCM:  0.0%  0.0%  0.0% 100.0%
x264 [info]: 8x8 transform intra:0.0%
x264 [info]: coded y,uvDC,uvAC intra: 100.0% 100.0% 100.0%
x264 [info]: kb/s:5951.36

encoded 222 frames, 1980.99 fps, 5951.36 kb/s
+ screen_record_mp4
+ ffmpeg -y -hide_banner -loglevel error -decryption_key 00000000000000000000000000000000 -i ./test_files/spliced.mp4 -vf 'scale=iw:ih,pad=iw+16:ih+24:(ow-iw)/2:(oh-ih)/2' -pix_fmt yuvj420p ./test_files/recorded.y4m
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5632176377c0] leftover packet bytes after subsample processing
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5632176377c0] Incorrect number of samples in encryption info
./test_files/spliced.mp4: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
+ process_recording
+ python3 -m lib.process_recording /dev/stdin test.db
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/spiros/Documents/wvdump/DeCENC/lib/process_recording.py", line 197, in <module>
    asyncio.run(main())
  File "/home/spiros/.local/share/pyenv/versions/3.12.6/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/spiros/.local/share/pyenv/versions/3.12.6/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/spiros/.local/share/pyenv/versions/3.12.6/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/spiros/Documents/wvdump/DeCENC/lib/process_recording.py", line 191, in main
    success = await process_y4m(con, f, hevc_mode=False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/spiros/Documents/wvdump/DeCENC/lib/process_recording.py", line 37, in process_y4m
    assert(magic == b"YUV4MPEG2")
           ^^^^^^^^^^^^^^^^^^^^^
AssertionError
+ '[' 1 -eq 0 ']'
+ true
+ craft_mp4
+ ./mp4gen.sh finite
+ DB_FILE=test.db
+ '[' 1 -eq 0 ']'
+ ENDLESS=
++ mktemp -u -t mp4gen_XXXXXXXXXXXXXX.y4m
+ Y4MPIPE=/tmp/mp4gen_mXmZVjKXuJkJD8.y4m
+ mkfifo /tmp/mp4gen_mXmZVjKXuJkJD8.y4m
+ python3 yuvgen.py test.db
+ sleep 1
+ ./x264/x264 --force-pcm -I 0 --input-range pc --output-csp i420 -o /dev/stdout /tmp/mp4gen_mXmZVjKXuJkJD8.y4m
+ ffmpeg -y -hide_banner -loglevel error -fflags +genpts -i - -vcodec copy -movflags frag_keyframe+empty_moov+default_base_moof -bsf:v h264_metadata=video_full_range_flag=0 -f mp4 -
+ python3 splice_metadata.py test.db /dev/stdin /dev/stdout video

(this continues repeatedly)

Also, when I am running python3 server.py and click start recording in OBS (with the Settings applied) I get the same error:

started http server
started y4m server
starting mp4gen
Handling Y4M stream input
Unhandled exception in client_connected_cb
transport: <_SelectorSocketTransport closed fd=9>
Traceback (most recent call last):
  File "/home/spiros/Documents/wvdump/DeCENC/server.py", line 167, in y4m_handle_client
    success = await process_y4m(con, reader, hevc_mode=False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/spiros/Documents/wvdump/DeCENC/lib/process_recording.py", line 37, in process_y4m
    assert(magic == b"YUV4MPEG2")
           ^^^^^^^^^^^^^^^^^^^^^
AssertionError

I have applied the patches on both x264 and kvazaar and compiled them both. These are my OBS Settings: Screenshot_20240917_194240

Also my specs:

Can you help me figure out why this is happening?

Thanks in advance!

Also, your work is very good and I hope to see more in the future!

DavidBuchanan314 commented 1 month ago

Weird, I'd guess this is related to your ffmpeg version. I've tested it on ffmpeg 6.1.2 (on Fedora 39)

It looks like you haven't posted the full output of ./testall.sh, it would help if you did.

Did you definitely build x264 with the supplied patches?

Vitaspiros commented 1 month ago

It was the ffmpeg version! Updating to 7.0.2 fixed the issue. Now I have another problem though. When playing the resulting video file, mpv crashes and always throws these errors at 00:06:

[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Incorrect number of samples in encryption info
[lavf] error reading packet: Invalid data found when processing input.
[lavf] ...treating it as fatal error.

and exits at 00:07 with the message:

Exiting... (End of file)

(also, the video is unplayable with vlc)

Though that's another problem. Should I open another issue to discuss this or should we continue here?

DavidBuchanan314 commented 1 month ago

What version of ffmpeg were you on before?

Vitaspiros commented 1 month ago

I was on version 5.1.6. Since that was the latest version on my repositories, I installed a newer one by downloading a prebuilt binary of the updated version and adding it to PATH.

Vitaspiros commented 1 month ago

Also I noticed that even with the updated ffmpeg version, when trying the "Open Loop" demo, the same AssertionError shows at the logs of python3 server.py. So maybe it wasn't the ffmpeg version after all.