<p>After you have made concat with your method 2:</p>
<p>You need the decryption key value (not the KID) for each track (I will not explain how to find the key value;) and then from your video and audio files use mp4decrypt from bento4 (just google it if you don't have it yet):</p>
<p>mp4decrypt --key KID:00112233445566778899AABBCCDDEEFF audio.m4a audio_decrypted.mp4</p>
<p>mp4decrypt --key 1:00112233445566778899AABBCCDDEEFF video.mp4 video_decrypted.mp4</p>
<p>you will have to replace KID with your 16 bytes hex key ID and 00112233445566778899AABBCCDDEEFF with your real key value</p>
<p>then ffmpeg will work (as expected) with your decrypted tracks :</p>
<p>fmpeg -i video_decrypted.mp4 -i audio_decrypted.m4a -c copy output.mp4</p>

CC BY-SA 4.0
2020-12-15T14:52:41.337Z
2020-12-15T14:52:41.337Z
Xavave
<p>I have MPEG dash video files created with Bento4 mp4-dash.py.
The files have encription, but I have the MPD and the audio and video segments.
I am trying to get my original MP4 file back from those segments without success.</p>

<p>My tentatives:
1) Convert directly from the MPD file:</p>

<pre><code>ffmpeg -i stream.mpd  -c copy output.mp4
</code></pre>

<p>2) Concatenate audio and video and use ffmpeg to merge them:</p>

<pre><code>cat videos/init.mp4 $(ls -1v videos/seg*.m4s) &gt; video.mp4
cat audios/init.mp4 $(ls -1v audios/seg*.m4s) &gt; audio.m4a
ffmpeg -i video.mp4 -i audio.m4a -c copy output.mp4
</code></pre>

<p>The error:</p>

<pre><code>ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.0 (Alpine 8.3.0)
  configuration: --pkg-config-flags=--static --extra-cflags=-fopenmp --extra-ldflags='-static -fopenmp' --toolchain=hardened --disable-debug --disable-shared --disable-ffplay --enable-static --enable-gpl --enable-nonfree --enable-openssl --enable-iconv --enable-libxml2 --enable-libmp3lame --enable-libfdk-aac --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvpx --enable-libx264 --enable-libx265 --enable-libwebp --enable-libwavpack --enable-libspeex --enable-libaom --enable-libvidstab --enable-libkvazaar --enable-libfreetype --enable-fontconfig --enable-libfribidi --enable-libass --enable-libzimg --enable-libsoxr --enable-libopenjpeg --enable-libdav1d
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564ad840] Failed to seek for auxiliary info, will only parse senc atoms for encryption info
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] could not find corresponding trex (id 2)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] could not find corresponding track id 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] trun track id unknown, no tfhd was found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] error reading header
stream.mpd: Invalid data found when processing input
</code></pre>

<p>I tried a few other options I do not remember, but the error persists and I do not know what could be the causes. I believe the concatenation step will not work due to the encryption, but I do not know how to get the key information from the MPD file neither how to decrypt before.</p>

<p>The following link says it should be easy, but something is not working (probably missing a decryption step):
<a href="https://video.stackexchange.com/questions/24435/how-to-download-and-encode-a-video-from-a-mpd-manifest?newreg=c95b04b398e949939b73ef3339105c81">How to download and encode a video from a MPD manifest?</a></p>

<p>Could you help me to solve such issue?</p>

CC BY-SA 4.0
2019-11-18T09:29:48.483Z
I think you should also have an initialization file that you need to append to the chunks. I am also trying to do the same but in my case, I am trying to download the files manually using the `manifest.mpd` file and concatenate them together and eventually re-create the original file but so far, I was not able to make it.
Georgi Stoyanov
CC BY-SA 4.0
2019-11-18T11:30:30.763Z
@GeorgеStoyanov Lets try to help each other then :D I was trying to find the key to use with https://www.bento4.com/documentation/mp4decrypt/. I found the KID into the MPD file, but I do not know what is the key. Maybe it is possible to decrypt before appending the chunks. I do not know much about how it works, but the key must be in one of those files, or media players could not play such files.
saulotoledo
CC BY-SA 4.0
2019-11-18T12:38:00.357Z
if I am not wrong the URL to the keystore should be included in the manifest file from where you can download the key to decrypt the MPEG-Dash segments. I think you can only retrieve the key for the decryption if you have authorized the player in your case the ffmpeg by providing username and password or some other way for authorization.
Georgi Stoyanov
<ffmpeg><streaming><mpeg-dash>
How to convert encrypted mpeg dash created with Bento4 mp4-dash.py to MP4
saulotoledo
# How to convert encrypted mpeg dash created with Bento4 mp4-dash.py to MP4

(Asked by: username_0 on 2019-11-17)

I have MPEG dash video files created with Bento4 mp4-dash.py.
The files have encription, but I have the MPD and the audio and video segments.
I am trying to get my original MP4 file back from those segments without success.
My tentatives:
1) Convert directly from the MPD file:
ffmpeg -i stream.mpd  -c copy output.mp4

2) Concatenate audio and video and use ffmpeg to merge them:
cat videos/init.mp4 $(ls -1v videos/seg*.m4s) > video.mp4
cat audios/init.mp4 $(ls -1v audios/seg*.m4s) > audio.m4a
ffmpeg -i video.mp4 -i audio.m4a -c copy output.mp4

The error:
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.0 (Alpine 8.3.0)
  configuration: --pkg-config-flags=--static --extra-cflags=-fopenmp --extra-ldflags='-static -fopenmp' --toolchain=hardened --disable-debug --disable-shared --disable-ffplay --enable-static --enable-gpl --enable-nonfree --enable-openssl --enable-iconv --enable-libxml2 --enable-libmp3lame --enable-libfdk-aac --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvpx --enable-libx264 --enable-libx265 --enable-libwebp --enable-libwavpack --enable-libspeex --enable-libaom --enable-libvidstab --enable-libkvazaar --enable-libfreetype --enable-fontconfig --enable-libfribidi --enable-libass --enable-libzimg --enable-libsoxr --enable-libopenjpeg --enable-libdav1d
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564ad840] Failed to seek for auxiliary info, will only parse senc atoms for encryption info
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] could not find corresponding trex (id 2)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] could not find corresponding track id 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] trun track id unknown, no tfhd was found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5555564c4100] error reading header
stream.mpd: Invalid data found when processing input

I tried a few other options I do not remember, but the error persists and I do not know what could be the causes. I believe the concatenation step will not work due to the encryption, but I do not know how to get the key information from the MPD file neither how to decrypt before.
The following link says it should be easy, but something is not working (probably missing a decryption step):
How to download and encode a video from a MPD manifest?
Could you help me to solve such issue?

**Tags:** ffmpeg, streaming, mpeg-dash

> **Comments:**
> **username_1**: I think you should also have an initialization file that you need to append to the chunks. I am also trying to do the same but in my case, I am trying to download the files manually using the `manifest.mpd` file and concatenate them together and eventually re-create the original file but so far, I was not able to make it.  
> **username_0**: @GeorgеStoyanov Lets try to help each other then :D I was trying to find the key to use with https://www.bento4.com/documentation/mp4decrypt/. I found the KID into the MPD file, but I do not know what is the key. Maybe it is possible to decrypt before appending the chunks. I do not know much about how it works, but the key must be in one of those files, or media players could not play such files.  
> **username_1**: if I am not wrong the URL to the keystore should be included in the manifest file from where you can download the key to decrypt the MPEG-Dash segments. I think you can only retrieve the key for the decryption if you have authorized the player in your case the ffmpeg by providing username and password or some other way for authorization.  

---

## 1 answers

### Answer by username_2 on 2020-12-15. Score: 1

After you have made concat with your method 2:

You need the decryption key value (not the KID) for each track (I will not explain how to find the key value;) and then from your video and audio files use mp4decrypt from bento4 (just google it if you don't have it yet):

mp4decrypt --key KID:00112233445566778899AABBCCDDEEFF audio.m4a audio\_decrypted.mp4

mp4decrypt --key 1:00112233445566778899AABBCCDDEEFF video.mp4 video\_decrypted.mp4

you will have to replace KID with your 16 bytes hex key ID and 00112233445566778899AABBCCDDEEFF with your real key value

then ffmpeg will work (as expected) with your decrypted tracks :

fmpeg -i video\_decrypted.mp4 -i audio\_decrypted.m4a -c copy output.mp4


---

