VideoHelp Forum


Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!


Try StreamFab Downloader and download streaming video from Youtube, Netflix, Amazon! Download free trial.


+ Reply to Thread
Results 1 to 14 of 14
Thread
  1. Hi.
    I'm looking for a .bat script that will decrypt video and audio (mp4, m4a) using keys stored in a txt file.
    I came across sth like this:

    Code:
    setlocal enabledelayedexpansion
    
    for /f "delims=" %%a in ('dir /B *.mp4') do (
        set /a counter=0
        for /f "delims=" %%b in (keys.txt) do (
            set /a counter+=1
            mp4decrypt --key %%b --show-progress "%%a" "%%~na_!Counter!.mp4"
        )
    )
    The above script is not too good because it runs each key separately and creates redundant files. So If I have 20 keys in txt, the will script create 20 videos (one decrypted among them).

    Can you guys come up with sth better?
    Quote Quote  
  2. put on same folder key.txt, mp4decrypt, decrypt.bat, video.mp4, audio.aac, ffmpeg
    audio and video are encrypted
    edit key.txt with your key:
    Code:
    video,xxxx:xxxx
    audio,xxxx:xxxx
    edit decrypt.bat with:
    Code:
    @echo off
    pushd "%~dp0"
    
    md ".\decode" >nul 2>nul
    for /f "tokens=1,2 delims=," %%a in (key.txt) do (
        for %%c in (mp4 aac) do (
            if exist ".\%%a.%%c" (
                 mp4decrypt.exe --key %%b   "%%a.%%c"  "____tmp.%%c"
                 move /y ".\____tmp.%%c"  ".\Decode\%%a.%%c"
           )
    
            if exist ".\%%a(Audio).%%c" (
                 mp4decrypt.exe --key %%b   "%%a(Audio).%%c"  "____tmp.%%c"
                 move /y ".\____tmp.%%c"  ".\Decode\%%a(Audio).%%c"
           )
       )
    )
    echo,ok
    pause>nul
    create new bat join_audio_video_ffmpeg.bat
    Code:
    echo off
    ffmpeg.exe -i ..Decode\video.mp4 -i --Decode\audio.aac -c copy muxed.mp4
    Quote Quote  
  3. Doesn't work.
    Besides my keys txt file looks like this:

    Code:
    0100c6ff9e3c64f14ba77e3bbb6a82dc:20bc0db1734e4a368af98f8340cc37c6
    0105e2531122ec62ae1adbfcd2d30e84:3787f7c1fbbc8b6494e3411ddeae23a3
    010280d0df7acf79502606dc4fd1ec46:4d7519e64031a171a01422fb84a7b6fe
    01011b0127298b4a0ffb2862b321aca7:b9bfd3f6417f902ce8fd6899fbb210b5
    I don't know which key is correct so I need the script to find it out.
    mp4decrypt does that automatically.
    Last edited by m0ck; 14th Mar 2022 at 11:49.
    Quote Quote  
  4. If python is ok this can be achieved easily.....

    keys.txt
    Code:
    eb676abbcb345e96bbcf616630f1a3da:100b6c20940f779a4589152b57d2dacb
    0294b9599d755de2bbf0fdca3fa5eab7:3bda2f40344c7def614227b9c0f03e26
    639da80cf23b55f3b8cab3f64cfa5df6:229f5f29b643e203004b30c4eaf348f4
    test.py
    Code:
    import subprocess
    
    kid = input('Enter the KID:')
    with open('keys.txt') as f:
        for line in f:
            stripped = line.strip()
            if stripped[0:32] == kid:
                key = stripped[-32:]            
    key_pair = kid+':'+key
    #print(key_pair)    
    subprocess.run([mp4decrypt, "--key", str(key_pair),"video_encrypted.mp4","video_decrypted.mp4"])
    Set the path of mp4decrypt,video input and output according to your needs..If you want to fully automate pass the kid from your script instead of manually entering
    Quote Quote  
  5. Originally Posted by m0ck View Post
    Doesn't work.
    Besides my keys txt file looks like this:
    0100c6ff9e3c64f14ba77e3bbb6a82dc:20bc0db1734e4a368 af98f8340cc37c6
    0105e2531122ec62ae1adbfcd2d30e84:3787f7c1fbbc8b649 4e3411ddeae23a3
    010280d0df7acf79502606dc4fd1ec46:4d7519e64031a171a 01422fb84a7b6fe
    01011b0127298b4a0ffb2862b321aca7:b9bfd3f6417f902ce 8fd6899fbb210b5
    yes not work. for you. look better my key.txt:
    Code:
    video,xxxx:xxxx
    audio,xxxx:xxxx
    video,kid:key
    and same for audio. replace kid:key with your data like 0105e2531122ec62ae1adbfcd2d30e84:3787f7c1fbbc8b649 4e3411ddeae23a3
    but need video, first where video, is the name of your video file encrypted.
    if you don't follow this syntax the command does not work
    Quote Quote  
  6. But as I said, I don't know which key is for video and which is for audio and keys txt contains lots of keys so unfortunately your script won't do in my case.
    Quote Quote  
  7. Originally Posted by m0ck View Post
    But as I said, I don't know which key is for video and which is for audio and keys txt contains lots of keys so unfortunately your script won't do in my case.
    do you know the kid for the video and audio?
    if not, you can get it from the video/audio file with mp4dump.
    (alot of smaller streaming sites only use the one kid per content)
    eg.
    Code:
    mp4dump <encrypted_file> | findstr /I kid
    default_KID = [59 d5 c7 a1 e3 6d 1c d7 0c b7 4c 51 ca b5 ac e1]
    that way you can pkp's script which finds the line with the kid in the key.txt file and uses the kid:key in the decryption.

    the other way is to add all the kid:keys to the mp4decrypt command and it will use the one that matches the kid of the file.
    ie.
    Code:
    mp4decrypt --key <kid1:key1> --key <kid2:key2> --key <kid3:key3> --key <kid4:key4> --key <kid5:key5> <encrypted_filename> <decrypted_filename>
    Quote Quote  
  8. Originally Posted by ElCap View Post
    ie.
    Code:
    mp4decrypt --key <kid1:key1> --key <kid2:key2> --key <kid3:key3> --key <kid4:key4> --key <kid5:key5> <encrypted_filename> <decrypted_filename>
    That is EXACTLY what I want to achieve. But instead of copying each key to the command line, I want the script to take them from txt file.
    That's all.

    Concept:
    mp4decrypt --key keys.txt encrypted.mp4 decrypted.mp4

    In keys.txt thare might be lots of different keys and only one is correct (don't know which).

    Is sth like this even possible in batch script?
    Quote Quote  
  9. Originally Posted by m0ck View Post
    Originally Posted by ElCap View Post
    ie.
    Code:
    mp4decrypt --key <kid1:key1> --key <kid2:key2> --key <kid3:key3> --key <kid4:key4> --key <kid5:key5> <encrypted_filename> <decrypted_filename>
    That is EXACTLY what I want to achieve. But instead of copying each key to the command line, I want the script to take them from txt file.
    That's all.

    Concept:
    mp4decrypt --key keys.txt encrypted.mp4 decrypted.mp4

    In keys.txt thare might be lots of different keys and only one is correct (don't know which).

    Is sth like this even possible in batch script?

    This is what you are looking for

    Code:
    @echo off
    :start
    setlocal enableextensions enabledelayedexpansion
    echo.
    set dec=dec.mp4
    set enc=enc.mp4
    
    for /f "delims=" %%a in (keys.txt) do (
    	set /a totalKeys += 1
    	set "keys=!keys! --key %%a"
    )
    echo Found total %totalKeys% keys
    
    :decrypt_process
    set mp4dec_args="mp4decrypt.exe" --show-progress !keys! "!enc!" "!dec!"
    echo MP4DECRYPT ARGUMENTS & echo !mp4dec_args! & echo.
    !mp4dec_args!
    echo.
    endlocal
    pause
    Quote Quote  
  10. @zackmark29 This is AWESOME and exactly waht I was looking for!
    Thanks a ton!
    One more thing though.
    How to change the script to also decrypt audio?
    There are two files in a folder.
    encrypted.mp4 (video) and encrypted.m4a (audio)
    Quote Quote  
  11. Originally Posted by m0ck View Post
    @zackmark29 This is AWESOME and exactly waht I was looking for!
    Thanks a ton!
    One more thing though.
    How to change the script to also decrypt audio?
    There are two files in a folder.
    encrypted.mp4 (video) and encrypted.m4a (audio)
    Code:
    @echo off
    :start
    setlocal enableextensions enabledelayedexpansion
    echo.
    set enc_v=enc_v.mp4
    set dec_v=dec_v.mp4
    set enc_a=enc_a.m4a
    set dec_a=dec_a.m4a
    
    for /f "delims=" %%a in (keys.txt) do (
    	set /a totalKeys += 1
    	set "keys=!keys! --key %%a"
    )
    echo Found total %totalKeys% keys
    
    :decrypt_process
    echo DECRYPTING VIDEO TRACK
    mp4decrypt.exe --show-progress !keys! "!enc_v!" "!dec_v!"
    echo.
    echo DECRYPTING AUDIO TRACK
    mp4decrypt.exe --show-progress !keys! "!enc_a!" "!dec_a!"
    echo.
    endlocal
    pause
    Quote Quote  
  12. your a star! working like a charm!
    Quote Quote  
  13. Thank you so much!
    Quote Quote  
  14. hi there, batch script from @zackmark29 is awesome and work perfectly but i want more comfortable to use

    i've read this thread from @A_n_g_e_l_a (thank for your python) and i see the way to improve zackmark script "Copy stream URL as 'Table Entry' from The Stream Detector"

    read keys from key.txt and use Table Entry for set a filename and MPD_URL (using with N_m3u8DL-RE)

    i try to implement zackmark batch script but it gave me more error when query string from Table Entry to filename , mpdurl , timestamp

    can anyone help me ? thanks a lot.
    Last edited by Biggy4; 14th Feb 2023 at 10:05. Reason: typo
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!