dash-mpd-cli icon indicating copy to clipboard operation
dash-mpd-cli copied to clipboard

Incomplete protected videos

Open vidasi opened this issue 1 year ago • 1 comments
trafficstars

Hello. I have tried several times to download protected content to which I have access to the protection key. However, every time I complete the download and check the final .MP4, I find that the content is incomplete, often with seconds missing.

Upon further analysis, I've found that it's always the last fragment that doesn't download, for reasons I don't know.

The MPD manifest header follows the example below

<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:cenc="urn:mpeg:cenc:2013" xmlns:mspr="urn:microsoft:playready" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" type="static" minBufferTime="PT30S" profiles="urn:mpeg:dash:profile:isoff-main:2011" mediaPresentationDuration="PT5M44.512S">
  <Period start="PT0S" duration="PT5M44.512S" id="1">
    <AdaptationSet mimeType="video/mp4" frameRate="50/1" segmentAlignment="true" subsegmentAlignment="true" startWithSAP="1" subsegmentStartsWithSAP="1" bitstreamSwitching="false">

Can you help, any hints as to what might be going on?

vidasi avatar Jul 28 '24 13:07 vidasi

Can you attach the MPD? There are different types of segment addressing (number-based, time-based) and I'd need to see what type of addressing is used. You can remove URLs in the manifest if you want.

If you download with "-v -v -v" dash-mpd-cli will print each downloaded segment, which makes it easier to see what is going wrong.

emarsden avatar Jul 28 '24 14:07 emarsden

Hi, sorry for the delay, I've been very busy with personal matters. Here's the manifest.

Em dom., 28 de jul. de 2024 às 11:40, Eric Marsden @.***> escreveu:

Can you attach the MPD? There are different types of segment addressing (number-based, time-based) and I'd need to see what type of addressing is used. You can remove URLs in the manifest if you want.

If you download with "-v -v -v" dash-mpd-cli will print each downloaded segment, which makes it easier to see what is going wrong.

— Reply to this email directly, view it on GitHub https://github.com/emarsden/dash-mpd-cli/issues/82#issuecomment-2254542327, or unsubscribe https://github.com/notifications/unsubscribe-auth/BKE6N422K4ZXP2G73JJJQULZOT7FTAVCNFSM6AAAAABLSZK5GKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJUGU2DEMZSG4 . You are receiving this because you authored the thread.Message ID: @.***>

vidasi avatar Aug 23 '24 21:08 vidasi

@emarsden this manifest file

<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:cenc="urn:mpeg:cenc:2013"
xmlns:mspr="urn:microsoft:playready"
xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011
http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
type="static" minBufferTime="PT30S"
profiles="urn:mpeg:dash:profile:isoff-main:2011"
mediaPresentationDuration="PT9M48.900S">
<Period start="PT0S" duration="PT9M48.900S" id="1">
<AdaptationSet mimeType="video/mp4" frameRate="30/1"
segmentAlignment="true" subsegmentAlignment="true" startWithSAP="1"
subsegmentStartsWithSAP="1" bitstreamSwitching="false">
<ContentProtection cenc:default_KID="KID"
schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc"/>
<ContentProtection cenc:default_KID="KID" schemeIdUri="urn:uuid:UUID"
value="2.0">
<mspr:pro>BASE64_KEY</mspr:pro>
<cenc:pssh>PSSH_KEY</cenc:pssh>
</ContentProtection>
<ContentProtection cenc:default_KID="KID" schemeIdUri="urn:uuid:UUID">
<cenc:pssh>BASE64_KEY</cenc:pssh>
</ContentProtection>
<SegmentTemplate timescale="90000" duration="2700000" startNumber="1"/>
<Representation id="1" width="1920" height="1080" bandwidth="2000000"
codecs="avc1.4d4028">
<SegmentTemplate media="stream_video_1920_1080_$Number%09d$.mp4"
initialization="stream_video_1920_1080init.mp4" duration="2700000"
startNumber="1"/>
</Representation>
<Representation id="2" width="1280" height="720" bandwidth="1000000"
codecs="avc1.4d401f">
<SegmentTemplate media="stream_video_1280_720_$Number%09d$.mp4"
initialization="stream_video_1280_720init.mp4" duration="2700000"
startNumber="1"/>
</Representation>
<Representation id="3" width="1024" height="576" bandwidth="800000"
codecs="avc1.4d401f">
<SegmentTemplate media="stream_video_1024_576_$Number%09d$.mp4"
initialization="stream_video_1024_576init.mp4" duration="2700000"
startNumber="1"/>
</Representation>
</AdaptationSet>
<AdaptationSet mimeType="audio/mp4" lang="und" segmentAlignment="0">
<ContentProtection cenc:default_KID="KID"
schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc"/>
<ContentProtection cenc:default_KID="KID" schemeIdUri="urn:uuid:UUID"
value="2.0">
<mspr:pro>BASE64_KEY</mspr:pro>
<cenc:pssh>PSSH_KEY</cenc:pssh>
</ContentProtection>
<ContentProtection cenc:default_KID="KID" schemeIdUri="urn:uuid:UUID">
<cenc:pssh>BASE64_KEY</cenc:pssh>
</ContentProtection>
<SegmentTemplate timescale="48000" media="stream_audio_96_$Number%09d$.mp4"
initialization="stream_audio_96init.mp4" duration="1440000"
startNumber="1"/>
<Representation id="4" bandwidth="128000" audioSamplingRate="48000"
codecs="mp4a.40.2">
<AudioChannelConfiguration
schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011"
value="2"/>
</Representation>
</AdaptationSet>
</Period>
</MPD>

vidasi avatar Aug 23 '24 21:08 vidasi

I've tried downloading using docker or directly via dash-mpd-cli and the same result. The last segment is always missing.

Here's the syntax I'm using to perform the downloads

Using dash-mpd-cli

dash-mpd-cli --key DECRYPT KEY -v http://URL_STREAM/stream.mpd -o
FILENAME.mp4 --quality best

Using docker

docker run --rm -v .:/content ghcr.io/emarsden/dash-mpd-cli --user-agent
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/120.0.0.0 Safari/537.36" --key DECRYPT KEY -v
http://URL_STREAM/stream.mpd -o FILENAME.mp4 --quality best

vidasi avatar Aug 23 '24 21:08 vidasi

OK, thanks for the details. This manifest is using a quite simple form of addressing, and I don't see any logic error in the parts of dash-mpd-cli that are handling this. Can you send me the MPD URL and decryption key so that I can look at it? (email: [email protected]).

emarsden avatar Aug 24 '24 08:08 emarsden

OK, there was indeed an off-by-one error in calculating the number of segments to download for this type of addressing: the initialization segment was being counted towards the number of segments, but should not be. Fixed in the latest release, thanks!

emarsden avatar Aug 26 '24 07:08 emarsden