Last active
March 10, 2023 19:09
-
-
Save alexrecuenco/5d0ac7d66fded304485fb7a8b3f4898b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you are putting all sources from file, | |
```bash | |
ffmpeg -i file.m3u8 -codec copy output.mp4 | |
``` | |
# If you are downloading from a website you have to add the protocols it will be using | |
This list should work | |
```bash | |
ffmpeg -protocol_whitelist file,https,tcp,tls,crypto -i file.m3u8 -codec copy output.mp4 | |
``` | |
# If you are downloading from a website manually and putting them together. | |
We assume the m3u8 file doesn't have aes encryption applied to it. | |
```bash | |
# Make a new directory, since there is going to be a lot of files | |
mkdir <dirname> | |
cd <dirname> | |
# Find the m3u8 file (Sometimes it is base64 encoded, and place it in `file.m3u8`) | |
# place it inside the folder. | |
# Modify the file adding the <https://...> absolute url | |
aria2c -x 10 -s 10 -i file.m3u8 | |
# Modify the file removing all comments, leaving only the file names (save it on files.txt) | |
cat $(grep -v '^#' files.txt) > output.ts | |
# I prefer to do this manually, just to make sure there was no neferiaous information or link, since we are publishing this code on a public gist | |
``` | |
## Note on getting .m3u8 | |
Many times, a m3u8 file that you download is not accessible again from the same url. | |
In that case, open the dev console and wait for that video to start and then pause javascript execution, and look through all the requests the one that is the m3u8. The response within the developer tools should contain the whole content of the file in the response, that you can just copy paste into a file locally (And review it if you don't trust it...) | |
## Alternatives | |
An alternative is `aria2c` which has multiconnections etc. https://aria2.github.io | |
See https://gist.github.com/patrickgill/130bf9eaa76138596137c7234e80f339 | |
# download | |
aria2c -x 5 -i file.m3u8 | |
# join all ts files | |
cat *.ts > out.ts | |
# convert ts output file | |
# This will re-encode the video and stream copy the audio: | |
# ffmpeg -i input -c:v libx264 -c:a copy -bsf:a aac_adtstoasc output.mp4 | |
ffmpeg -i d_out.ts-vcodec copy -acodec copy -bsf:a aac_adtstoasc d_out.mp4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment