Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpv not able to play encrypted-mp4 (cenc-aes-ctr) #4579

Closed
sschnug opened this issue Jul 5, 2017 · 12 comments
Closed

mpv not able to play encrypted-mp4 (cenc-aes-ctr) #4579

sschnug opened this issue Jul 5, 2017 · 12 comments

Comments

@sschnug
Copy link

sschnug commented Jul 5, 2017

Hi, new mpv-user here evaluating the player for some project of mine.

I'm having trouble playing encrypted-mp4 with mpv. Is there anything wrong (usage or misinterpretation of functionality) or is this a bug?

Example

Let's assume we got a sample-video: SampleVideo_1280x720_1mb.mp4 (actual video does not matter).

Play original

1:

ffplay SampleVideo_1280x720_1mb.mp4
-> OK

2:

mpv SampleVideo_1280x720_1mb.mp4
-> OK

Encrypt

Let's encrypt it using ffmpeg and cenc-aes-ctr:

3:

ffmpeg -i SampleVideo_1280x720_1mb.mp4 -vcodec copy -acodec copy -encryption_scheme cenc-aes-ctr -encryption_key 76a6c65c5ea762046bd749a2e632ccbb -encryption_kid a7e61c373e219033c21091fa607bf3b8 SampleVideo_1280x720_1mb_encrypted.mp4

Play encrypted:

4:

ffplay SampleVideo_1280x720_1mb_encrypted.mp4 -decryption_key 76a6c65c5ea762046bd749a2e632ccbb
-> OK

5: shinchiro build

mpv --demuxer-lavf-cryptokey=76a6c65c5ea762046bd749a2e632ccbb SampleVideo_1280x720_1mb_encrypted.mp4
mpv --demuxer-lavf-cryptokey=76A6C65C5EA762046BD749A2E632CCBB SampleVideo_1280x720_1mb_encrypted.mp4 (just to be sure)
-> No -> looks it's beeing interpreted as unencrypted-stream or decryption is broken
-> tons of bitstream errors

6: lachs0r build

mpv --demuxer-lavf-cryptokey=76a6c65c5ea762046bd749a2e632ccbb SampleVideo_1280x720_1mb_encrypted.mp4
mpv --demuxer-lavf-cryptokey=76A6C65C5EA762046BD749A2E632CCBB SampleVideo_1280x720_1mb_encrypted.mp4 (just to be sure)
-> No -> looks it's beeing interpreted as unencrypted-stream or decryption is broken
-> tons of bitstream errors

Version info

Everything tested on windows:

  • ffmpeg version N-86691-gc885356 Copyright (c) 2000-2017 the FFmpeg developers
    • zeranoe windows build
  • ffplay version N-86691-gc885356 Copyright (c) 2003-2017 the FFmpeg developers
    • zeranoe windows build
  • mpv 0.25.0-289-g69289aec6c (C) 2000-2017 mpv/MPlayer/mplayer2 projects
    • Windows build by shinchiro
  • mpv 0.25.0 (C) 2000-2017 mpv/MPlayer/mplayer2 projects
    • Windows build lachs0r

Edit:

  • same behaviour on Linux (ubuntu 16.04 LTS) using:
    • mpv 0.25.0-7bfeb8b-amended (C) 2000-2017 mpv/MPlayer/mplayer2 projects built on Sun Jun 25 04:29:14 UTC 2017 installed through (non-Vapoursynth-PPA)

Log-file

log @ gist

Remarks

Checking ffplay --help and searching for crypto-stuff, there are various entries and maybe this is the core of these problems.

Entries:

  • 1: AVFormatContext AVOptions:
    • cryptokey .D...... decryption key
  • 2: crypto AVOptions:
    • decryption_key .D...... AES decryption key
  • 3: mov,mp4,m4a,3gp,3g2,mj2 AVOptions:
    • decryption_key .D...... The media decryption key (hex)

I suppose my ffplay-command is using case 3, while mpv is using case 1. As the command i used for mpv is the only one i can imagine (only crypto-related) it's the only thing i tried.

I'm not that familiar with ffmpeg/ffplay (at this module-level), but i can imagine, that internally AVFormat and AVOptions are treated very differently.

@richardpl
Copy link
Contributor

Because you first need to read mpv manual to figure how to correctly set ffmpeg avoptions.

@sschnug
Copy link
Author

sschnug commented Jul 6, 2017

Fair enough. I can understand the frustration with lazy users, but for us it's not quite as simple as for you developers (the whole AVOptions vs. AVFormatContext vs. ... was realized later). So while i'm thankful for the hint, you could have also add a one-liner to show me what to do.

Nonetheless:

Working (and maybe correct usage):

mpv --demuxer-lavf-o=decryption_key=76a6c65c5ea762046bd749a2e632ccbb SampleVideo_1280x720_1mb_encrypted.mp4

@sschnug sschnug closed this as completed Jul 6, 2017
@ghost
Copy link

ghost commented Jul 6, 2017

Actually this option exists: https://mpv.io/manual/master/#options-demuxer-lavf-cryptokey

It's from ancient MPlayer times, and apparently it doesn't work.

@wiiaboo
Copy link
Member

wiiaboo commented Jul 6, 2017

@wm4 might as well remove it, to prevent confusion.

@sschnug
Copy link
Author

sschnug commented Jul 6, 2017

Thanks for the follow-up remarks!

ghost pushed a commit that referenced this issue Jul 6, 2017
The first time I saw a user try to use this option, and apparently it
didn't work. I'm not exactly sure why, but the code seems to be broken
anyway. Apart from not doing any error checking (neither mallocs nor
warning the user against invalid input), it forgets to add a 0
terminator.

Use the corresponding AVOption instead, which probably works.

See #4579.
@ghost
Copy link

ghost commented Jul 6, 2017

Actually replaced it with different code.

@haasn
Copy link
Member

haasn commented Jul 6, 2017

So what's this about multiple options? cryptokey and decryption_key? Maybe we should set both?

@ghost
Copy link

ghost commented Jul 6, 2017

Actually I think only cryptokey works. I used the option named @sschnug claimed to use though.

@sschnug
Copy link
Author

sschnug commented Jul 6, 2017

I can't follow your discussion, but the source of my usage of decryption_key (opposed to cryptokey) comes from this old commit to ffmpeg here.

@ghost
Copy link

ghost commented Jul 6, 2017

Oh, so it's a private mp4 option. Better to remove the mpv option then.

ghost pushed a commit that referenced this issue Jul 6, 2017
Was at least somewhat broken, and is misleading. I don't really have an
idea why FFmpeg as two AVOptions here anyway. We don't need to care, and
I'm only aware of 1 user trying this option ever.

See #4579.
@ghost
Copy link

ghost commented Jul 6, 2017

And it's gone.

ghost pushed a commit that referenced this issue Jul 6, 2017
Was at least somewhat broken, and is misleading. I don't really have an
idea why FFmpeg has two AVOptions here anyway. We don't need to care,
and I'm only aware of 1 user trying this option ever.

See #4579.
@MaZED-UP
Copy link

MaZED-UP commented Mar 4, 2023

How can I use multiple keys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants