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

mp4: Properly use trun data offset #294

Merged
merged 1 commit into from
Jun 7, 2022
Merged

mp4: Properly use trun data offset #294

merged 1 commit into from
Jun 7, 2022

Conversation

wader
Copy link
Owner

@wader wader commented Jun 7, 2022

Each trun has it's own data offset, before the last offset was wrongly used
for all truns. Could also cause sample ranges to be beyond EOF.

tenc: Decode default constant iv

Fixes #292

Each trun has it's own data offset, before the last offset was wrongly used
for all truns. Could also cause sample ranges to be beyond EOF.

tenc: Decode default constant iv

Fixes #292
@wader wader merged commit f46e7df into master Jun 7, 2022
@wader wader deleted the trun-data-offset branch June 7, 2022 16:40
@wader
Copy link
Owner Author

wader commented Jun 7, 2022

You mean only the first trak box has a sinf box? i don't know that much about cenc either but yes i think so. Looks like only the first track uses encryption?

@wader
Copy link
Owner Author

wader commented Jun 7, 2022

Ah yes probably only the "content" part of the packets aka samples are encrypted. But i would have guessed the first few bytes (header with key frame info etc) are not encrypted followed by encrypted content bytes? the senc box has info about what bytes are encrypted and not.

With some luck and some google-fu you find the relevant specs ISOBMFF filetype:pdf "iso/iec 14496-12" CENC filetype:pdf "iso/iec 23001-7" and or look at implementations like ffmpeg, shaka-packager etc.

@wader
Copy link
Owner Author

wader commented Jun 7, 2022

So I bet the ones without senc are the subtitle, which can probably just be ignored, then decrypt the ones with senc.

Yes think your right. The traf without senc has a tfhd that says track 2 which is the subtitle track. If you want to look at the raw samples you can do something like this with fq fq '.tracks[] | select(.id==2) | d' file.mp4.

Have some plans to add more crypto things to fq at some point, like ciphers, block/stream modes etc, then it would be possible to trial and error decrypt cbcs samples and such things. If useful maybe should even should be added to the mp4 demuxer in go somehow?

@wader
Copy link
Owner Author

wader commented Jun 7, 2022

BTW the subtitles seems to be this format https://en.wikipedia.org/wiki/EIA-608 somehow. Notice that the codepoints are more or less ASCII with highest bit being a parity bit:

$ fq '.tracks[1].samples[] | tobytes[8:] | explode | map(band(0x7f;.)) | implode' file.mp4
"\u0014 \u0014 \u0014,\u0014,\u0000\u0000\u0000\u0000\u0014/\u0014/"
"\u0014,\u0014,"
"\u0014 \u0014 \u0014t\u0014t[birds chirping]\u0014,\u0014,\u0000\u0000\u0000\u0000\u0014/\u0014/"
"\u0014 \u0014 \u0014r\u0014r\u0017\"\u0017\"[soft music playing]\u0014,\u0014,\u0000\u0000\u0000\u0000\u0014/\u0014/"
"\u0014,\u0014,"

:)

@wader
Copy link
Owner Author

wader commented Jun 7, 2022

If useful maybe should even should be added to the mp4 demuxer in go somehow?

what is that? Does Go have an official MP4 demuxer?

Sorry should have been more clear, i meant the mp4 demuxer in fq written in go.

@wader
Copy link
Owner Author

wader commented Jun 16, 2022

👍 nice, thanks for sharing

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

Successfully merging this pull request may close these issues.

None yet

1 participant