Fetch
Fetch copied to clipboard
Downloading M3U8 manifest file itself instead of Videos
Thank you for this beautiful library. I really appreciate your work. I am having an issue while downloading M3U8 videos. The library is downloading M3U8 manifest file itself instead of videos. How can I download videos that are mentioned in that manifest file? Thank you.
If HLS is not live stream, you might be able to read each segments relative path inside manifest, then download each segment one by one. But those segments are in .TS format probably and in small length (few seconds) .
Even after downloading the segment files you'll need ffmpeg to concact the segment files into a full video. This is certainly possible but I would imagine that it requires quite a lot changes around how downloads are scheduled or represented.
Even after downloading the segment files you'll need ffmpeg to concact the segment files into a full video. This is certainly possible but I would imagine that it requires quite a lot changes around how downloads are scheduled or represented.
Use FFmpeg is may not be the good idea. While I use my own downloader (before using Fetch2). I have just get multiple input stream (for each URL one stream) but only one output stream. I won't close output stream unless all file are downloaded. Consider a video file of size 4 bytes(ideally) then next video file adds on same file after 4th byte
Even after downloading the segment files you'll need ffmpeg to concact the segment files into a full video. This is certainly possible but I would imagine that it requires quite a lot changes around how downloads are scheduled or represented.
Use FFmpeg is may not be the good idea. While I use my own downloader (before using Fetch2). I have just get multiple input stream (for each URL one stream) but only one output stream. I won't close output stream unless all file are downloaded. Consider a video file of size 4 bytes(ideally) then next video file adds on same file after 4th byte
So instead of having individual files (playlist segments) and joining them at the end you just write each segment into one output stream (final file)? I have to say, I've never tried that before
Even after downloading the segment files you'll need ffmpeg to concact the segment files into a full video. This is certainly possible but I would imagine that it requires quite a lot changes around how downloads are scheduled or represented.
Use FFmpeg is may not be the good idea. While I use my own downloader (before using Fetch2). I have just get multiple input stream (for each URL one stream) but only one output stream. I won't close output stream unless all file are downloaded. Consider a video file of size 4 bytes(ideally) then next video file adds on same file after 4th byte
So instead of having individual files (playlist segments) and joining them at the end you just write each segment into one output stream (final file)? I have to say, I've never tried that before
First of all sorry for my bad English for the previous comment I made. But you got the point. Just append all playlist segments' data (byte[]) one after another sequential results in perfect Video Files.
@wax911 I have tried the same idea in windows but it results in a broken video file. Video plays but frames repeated, skipped etc. However, in android, it runs smoothly. I have no idea why. So don't follow my steps to download the HLS video. If you use FFmpeg there is a command:
ffmpeg -i "<M3U8URL>" -codec copy output.mp4
To download Video from the M3U8 file. No need to worry of downloading individual segment and merging them all-in-one command from FFmpeg.
Thanks for the heads up @Udhayarajan I am aware of the ffmpeg
command, but in this specific scenario if you use that then you'd be delegating the everything to ffmpeg
which would defeat the purpose of using fetch
combining ts files to full video without ffmpeg may be possible. Lets say we have all the ts file urls in the list. I am writing this code without IDE so there may be some syntax errors You probably should use this inside AsyncTask
//I am writing this code without IDE so there may be some syntax errors
//You probably should use this inside AsyncTask
ArrayList<String> urls = new ArrayList();
byte[] buf = new byte[512];
for(int i = 0; i < urls.size(); i++){
try{
URI uri = new URI(urls.get(i));
URL url = uri.toURL();
InputStream is = url.openStream();
String pathFile = Environment.getExternalStorageDirectory() + "/Download/test.mp4";
File file = new File(pathFile);
FileOutputStream fOut = new FileOutputStream(pathFile,file.exists());
int readBf;
while((readBf == is.read(buf)) >= 0){
fOut.write(buf,0,readBf);
}
is.close();
fOut.close();
}catch(IOException e){
e.printStackTrace();
}
}
@Serkali-sudo have you tested this though? Does the final output play properly
@Serkali-sudo have you tested this though? Does the final output play properly
i didnt tested but it should work and it will work only if you are already able to parse ts file links from m3u8.I can make full example and test it if you want .
@Serkali-sudo have you tested this though? Does the final output play properly
i didnt tested but it should work and it will work only if you are already able to parse ts file links from m3u8.I can make full example and test it if you want .
Please do, that would be great! 😺 your solution sounds similar to what's below
@wax911 I have tried the same idea in windows but it results in a broken video file. Video plays but frames repeated, skipped etc. However, in android, it runs smoothly. I have no idea why. So don't follow my steps to download the HLS video. If you use FFmpeg there is a command:
ffmpeg -i "<M3U8URL>" -codec copy output.mp4
To download Video from the M3U8 file. No need to worry of downloading individual segment and merging them all-in-one command from FFmpeg.