Recent

Author Topic: How to download a video from an URL like *.m3u8 ?  (Read 9264 times)

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: How to download a video from an URL like *.m3u8 ?
« Reply #15 on: April 26, 2024, 11:34:39 pm »
did you get something working?

i use sysutils.executeprocess with yt-dlp
https://github.com/yt-dlp


Hartmut

  • Hero Member
  • *****
  • Posts: 843
Re: How to download a video from an URL like *.m3u8 ?
« Reply #16 on: April 27, 2024, 07:42:50 am »
did you get something working?

i use sysutils.executeprocess with yt-dlp
https://github.com/yt-dlp

Yes, I wrote a small program which can download the single segment files of a m3u8 video and calls ffmpeg to concat them to a video file. If I'll get further problems, I'll give yt-dlp a try. Thank you toby for that suggestion.

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: How to download a video from an URL like *.m3u8 ?
« Reply #17 on: April 27, 2024, 06:41:13 pm »

i assume you are using curl to get the m3u8 to get the urls and number of
fragments and then curl to get the fragments?

sounds like you are doing in fpc what yt-dlp is doing but in python

would you be up to posting the code you have written in fpc?  it would be interesting to test it



this is what yt-dlp is doing (from cli but same with sysutils.executeprocess in fpc)

> yt-dlp https://srf-vod-amd.akamaized.net/ch/hls/film/2024/03/film_20240317_000539_4703373_v_webcast_h264_,q40,q10,q20,q30,q50,q60,.mp4.csmil/index-f1-v1-a1.m3u8
[generic] Extracting URL: https://srf-vod-amd.akamaized.net/ch/hls/film/2024/03/film_20240317_000539_4703373_v_webcast_h264.../index-f1-v1-a1.m3u8
[generic] index-f1-v1-a1: Downloading webpage
[generic] index-f1-v1-a1: Downloading m3u8 information
[generic] index-f1-v1-a1: Checking m3u8 live status
[info] index-f1-v1-a1: Downloading 1 format(s): 0
[hlsnative] Downloading m3u8 manifest
WARNING: Live HLS streams are not supported by the native downloader. If this is a livestream, please add "--downloader ffmpeg --hls-use-mpegts" to your command
[hlsnative] Total fragments: 37
[download] Destination: index-f1-v1-a1 [index-f1-v1-a1].mp4
[download] 100% of   91.77MiB in 00:01:38 at 954.51KiB/s        <-- gets each fragment then gives this total for downloads
[FixupM3u8] Fixing MPEG-TS in MP4 container of "index-f1-v1-a1 [index-f1-v1-a1].mp4"






Hartmut

  • Hero Member
  • *****
  • Posts: 843
Re: How to download a video from an URL like *.m3u8 ?
« Reply #18 on: April 28, 2024, 10:47:31 am »
i assume you are using curl to get the m3u8 to get the urls and number of
fragments and then curl to get the fragments?

No, I use class 'TFPHttpClient' to download each file.

Quote
would you be up to posting the code you have written in fpc?  it would be interesting to test it

I am sorry, no, for two reasons. 1st this program was a quick hack and is no recommendation to publish it. 2nd the program uses several common libraries, which I don't have the rights to publish them.

But if you are deeply interested, I could extract for you 1 procedure (which downloads 1 URL from type *.m3u8 into a small textfile and then extracts all needed segments into an array) and send it by PM to you.

But as said, that procedure would not compile (because of missing libraries) and all comments are in German.

phoenix27

  • Jr. Member
  • **
  • Posts: 91
Re: How to download a video from an URL like *.m3u8 ?
« Reply #19 on: August 14, 2024, 01:18:07 am »
Why don't you show us that routine? Do you want us to reinvent the wheel?

akdev000

  • Newbie
  • Posts: 1
Re: How to download a video from an URL like *.m3u8 ?
« Reply #20 on: October 11, 2024, 06:26:54 pm »
This method seems to work when you receive 403 Forbidden errors while downloading the video (it emulates the same headers that your browser sends):

Using Firefox, open Developer Tools using Ctrl + Shift + I, or click on the 3-line hamburger menu in the top-right (1.) > More Tools (2.) > Web Developer Tools (3.).

Screenshot of Firefox: 3-line Hamburger Menu > More Tools:
https://i.sstatic.net/GP1U7fWQ.png

Screenshot of Firefox: More Tools > Developer Tools:
https://i.sstatic.net/x2mulkiI.png

Go to the Network tab (4.), reload the page, find the appropriate .m3u8 entry, typically named stream.m3u8 or something similar (5.), right-click on it, Copy Value (6.) > Copy as cURL (7.).

Screenshot of Firefox: right-click on stream.m3u8: Copy Value > Copy as cURL
https://i.sstatic.net/jYTZbyFd.png

Then paste the resulting cURL command into here: https://windyakin.github.io/curl2ffmpeg. Download and install the free, open source FFMpeg tool from https://www.ffmpeg.org/ if you don't already have it, paste the resulting ffmpeg command into your commandline (you may have to add a .exe suffix, eg: ffmpeg becomes ffmpeg.exe if you are using Windows) and enjoy the video!

 

TinyPortal © 2005-2018