Forum > Networking and Web Programming

How to download a video from an URL like *.m3u8 ?

(1/4) > >>

Hartmut:
Many videos in the internet have a mp4-Format, but sometimes the URL is like this:

* 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

* https://srf-vod-amd.akamaized.net/ch/hls/film/2024/03/film_20240320_005905_4753932_v_webcast_h264_,q40,q10,q20,q30,q50,q60,.mp4.csmil/index-f1-v1-a1.m3u8

* https://apasfiis.sf.apa.at/ipad/cms-worldwide_episodes/14220193_0005_Q6A.mp4/playlist.m3u8
When I download such an URL via 'TFPHTTPClient' or via synapse, then I only get a small textfile with a content like this:

Example1:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#EXTM3U#EXT-X-TARGETDURATION:10#EXT-X-ALLOW-CACHE:YES#EXT-X-PLAYLIST-TYPE:VOD#EXT-X-VERSION:3#EXT-X-MEDIA-SEQUENCE:1#EXTINF:4.000,segment-1-f1-v1-a1.ts#EXTINF:6.000,segment-2-f1-v1-a1.ts#EXTINF:10.000,segment-3-f1-v1-a1.ts...segment-35-f1-v1-a1.ts#EXTINF:10.000,segment-36-f1-v1-a1.ts#EXTINF:2.200,segment-37-f1-v1-a1.ts#EXT-X-ENDLIST
Example2:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#EXTM3U#EXT-X-TARGETDURATION:10#EXT-X-ALLOW-CACHE:YES#EXT-X-PLAYLIST-TYPE:VOD#EXT-X-VERSION:3#EXT-X-MEDIA-SEQUENCE:1#EXTINF:4.000,segment-1-f1-v1-a1.ts?caption=srf/c871f14e-cfd9-41a7-bc3a-bb7d09cda4d8/episode/de/vod/vod.m3u8:de:Deutsch:sdh&webvttbaseurl=subtitles.eai-general.aws.srf.ch#EXTINF:6.000,segment-2-f1-v1-a1.ts?caption=srf/c871f14e-cfd9-41a7-bc3a-bb7d09cda4d8/episode/de/vod/vod.m3u8:de:Deutsch:sdh&webvttbaseurl=subtitles.eai-general.aws.srf.ch#EXTINF:10.000,...#EXTINF:10.000,segment-830-f1-v1-a1.ts?caption=srf/c871f14e-cfd9-41a7-bc3a-bb7d09cda4d8/episode/de/vod/vod.m3u8:de:Deutsch:sdh&webvttbaseurl=subtitles.eai-general.aws.srf.ch#EXTINF:8.960,segment-831-f1-v1-a1.ts?caption=srf/c871f14e-cfd9-41a7-bc3a-bb7d09cda4d8/episode/de/vod/vod.m3u8:de:Deutsch:sdh&webvttbaseurl=subtitles.eai-general.aws.srf.ch#EXT-X-ENDLIST
Example3:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#EXTM3U#EXT-X-VERSION:3#EXT-X-STREAM-INF:BANDWIDTH=2254982,CODECS="avc1.64001f,mp4a.40.2",RESOLUTION=960x540chunklist.m3u8
My question is: how can my program download such a video? Must I reinvent the wheel or does FPC have some "library" for that?
Is this somehow possible via 'TFPHTTPClient' or via synapse? Or something other which needs no package installation? Then I would prefer that.

I'm on Linux Ubuntu 22.04 with FPC 3.2.2. Thanks in advance.

lainz:
You need to parse the text file and append at the URL the .ts file to download it.


--- Quote ---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/segment-1-f1-v1-a1.ts
--- End quote ---

Hartmut:
Thanks lainz. Yes, but then all possible formats have to be considered and all the single segments have to be concatenated together. I made a quick test and saw, that the sum of all downloaded segment files (1747 MB) is clearly bigger then if I download the same video by ffmpeg or by VLC-player (only 1706 MB). As said, I would reinvent the wheel...

Does FPC not have some unit or "library" for that?
Do 'TFPHTTPClient' or synapse have this feature? Or something other which needs no package installation? Then I would prefer that.

TRon:

--- Quote from: Hartmut on April 04, 2024, 06:23:02 pm ---I made a quick test and saw, that the sum of all downloaded segment files (1747 MB) is clearly bigger then if I download the same video by ffmpeg or by VLC-player (only 1706 MB). As said, I would reinvent the wheel...

--- End quote ---
You might want to consider reading up on MPEG transport.


--- Quote ---Does FPC not have some unit or "library" for that?

--- End quote ---
Sure. It is called ffmpeg  ;D

Kidding aside, no afaik there is not a native implementation for decoding mpeg streams. There are plenty of 3th party libraries that are able to do that for you (such as ffmpeg) and all solutions that are available for FPC/Lazarus uses such a 3th party library one way or another.

Hartmut:

--- Quote from: TRon on April 04, 2024, 06:32:47 pm ---
--- Quote from: Hartmut on April 04, 2024, 06:23:02 pm ---I made a quick test and saw, that the sum of all downloaded segment files (1747 MB) is clearly bigger then if I download the same video by ffmpeg or by VLC-player (only 1706 MB). As said, I would reinvent the wheel...

--- End quote ---
You might want to consider reading up on MPEG transport.

--- End quote ---

Do you mean, that each single downloaded segment file contains several control data from the MPEG transport stream (which must be deleted)? Looks like pure horror...


--- Quote ---
--- Quote ---Does FPC not have some unit or "library" for that?

--- End quote ---
Sure. It is called ffmpeg  ;D

--- End quote ---

I used ffmpeg manually in the past to download *.m3u8 videos. But multiple times these videos had gaps and were bumpy/jerky. Sometimes I saw messages like "HTTP error 404 Not Found" or "Failed to open segment of playlist" in the huge output of ffmpeg. It looks like ffmpeg does not retry on problems and simple continues... So I hesitate to trust on ffmpeg.

Navigation

[0] Message Index

[#] Next page

Go to full version