I want to download HLS videos from a site that needs to be logged in using FFmpeg, meaning I have to enter my username and password to access the videos, and I do not know how to enter the login information through FFmpeg... Can anyone help me?
-
2if its basic auth I would think you could use something like `http://username:password@somesite/vid.mp4` – Dirk V Sep 17 '20 at 10:46
-
Hi @FastOFF could you give us more detail on this issue ? Screenshot of the situation, maybe the link if sharable, what have you tried ? – Paulo Sep 13 '21 at 11:51
3 Answers
First login to site using puppeteer or any other automation tool and grab all related cookies.
then use command like that
ffplay -cookies "nlqptid=nltid=tsn; path=/; domain=somedomain.com;" http://somedomain.com/somestream.m3u8
for more details view this url
- 944
- 8
- 16
HLS is an adaptive streaming protocol, which means that the video streaming can be automatically adjusted for better video playback experience by dividing the video file into multiple smaller chunks with different data rates. Because now you have many small chunks you cannot directly download the video. In fact, you cannot even find the direct download link to the video file.
But if you closely look at the network requests using your developer tools in your browser, you can get the manifest file with .M3U8 extension. This is the file which contains the url to all the smaller chunks of the video.
If the video is not drm protected, which in most cases will be drm protected, you can use ffmpeg as shown below:
ffmpeg -i "http://xyz.domain.com/video_url.m3u8" -c copy -bsf:a aac_adtstoasc "output.mp4"
But based on your explanation, it looks like there is some kind of authentication mechanism to this website to watch the content, which means most probably the video will be drm protected.
In this situation you will need to find the keyID and the key from the developer tools in browser by manually going through the manifest file. This can be done programtically by creating a manifest parser methid which will return all the video segments. audio segments, video keyIds, and audio keyIds.
Then store the keyIds and keys in a dict for later retrieval.
So now you have the keyID and key, then you can decrypt each segment using the key as shown below using ffmpeg:
ffmpeg -y -decryption_key {key} -i {segment_filename} -codec copy -metadata title={video_title} dec_{filename}
Most probably you will need to do this separately for the video and audio and then decrypt and then mux them back together to get the original file with audio and video.
Please not this is not an easy task, but will require a bit of manual investigation into the specific service providers requests and responses.
Please also note that the solution/idea proposed is strictly for research purposes and should not be used for any illegal activities.
- 6,315
- 11
- 53
- 82
As per our knowledge, it's not possible because I am unable to get any method on FFmpeg from where we can set the password.
Trick: you can create a password protucted page and where implemnet video downloads logic like this: download.php
<?php
/* Your password */
$password = 'MYPASSWORD';
if (isset($_POST['password']) && $_POST['password'] == $password) {
// Download video logic here....
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Password protected</title>
</head>
<body>
<div style="text-align:center;margin-top:50px;">
You must enter the password to view this content.
<form method="POST">
<input type="text" name="password">
</form>
</div>
</body>
</html>
- 1,724
- 1
- 6
- 23
