Comments (3)
FFmpeg can parse M3U8 files, so you could just pass the m3u8 link directly to FFmpeg.
Something like this:
using System;
using CryMediaAPI;
using System.Collections.Generic;
var links = new List<string> {
"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8",
"http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8"
};
int fileCounter = 0;
foreach (var l in links)
{
var output_file = $"video_{fileCounter++}.mp4";
var process = FFmpegWrapper.ExecuteCommand("ffmpeg", $"-i \"{l}\" -c copy {output_file}");
process.WaitForExit();
Console.WriteLine($"Downloaded video from '{l}' --> {output_file}");
}
This will run FFmpeg for every link and save it to file video_0.mp4
and then video_1.mp4
and so on...
To avoid transcoding, I just used the flag -c copy
to copy all the content. Sometimes you may also want to transcode it. If you want H.264, you could just replace it with -c:v libx264
(the audio is converted automatically as well)
If you want to run multiple clients at the same time, you could easily paralize this. Or just take away the Process.WaitForExit()
and first start all the FFmpegs - and later wait for all of them.
from crymedia.
Hello:
Thanks for your reply, I have tested with the links, and they worked.
However, I need other code samples for parallel clients.
For example, I have the following 2 live streaming URL for Olympic games, which is underway at the same time, which will be finished within one hour time.
var links = new List {
"https://video.maxline.by:444/n1/stream61/chunks.m3u8?nimblesessionid=4798699",
"https://video1.maxline.by:444/o1/stream09/chunks.m3u8?nimblesessionid=3015537" };
I have to download the both URL at the same time.
Your code above now only download the first, and after the first is done, continue the second.
Please advise!
Thanks,
from crymedia.
Either create separate threads, or tasks ...
But I think the easiest way with the existing code is to just replace the foreach loop with Parallel.ForEach
and limit number of parallelism with ParallelOptions
like this:
// add these to the existing usings
using System.Threading.Tasks;
using System.Threading;
int fileCounter = 0;
Parallel.ForEach(links, new ParallelOptions
{
// we want max. 2 clients running in parallel
MaxDegreeOfParallelism = 2
}, l =>
{
var fileCount = Interlocked.Increment(ref fileCounter);
var output_file = $"video_{fileCount}.mp4";
var process = FFmpegWrapper.ExecuteCommand("ffmpeg", $"-i \"{l}\" -c copy {output_file}");
process.WaitForExit();
Console.WriteLine($"Downloaded video from '{l}' --> {output_file}");
});
OR you could also store all processes and wait for them to exit like this:
// add this to existing usings
using System.Diagnostics;
var processes = new List<Process>();
int fileCounter = 0;
foreach (var l in links)
{
var output_file = $"video_{fileCounter++}.mp4";
var process = FFmpegWrapper.ExecuteCommand("ffmpeg", $"-i \"{l}\" -c copy {output_file}");
processes.Add(process);
}
// wait for all processes to finish
foreach (var p in processes) p.WaitForExit();
from crymedia.
Related Issues (8)
- I would like to play mp4 video using memory stream HOT 2
- subscribing to event ErrorDataReceived does not allow to update UI, kindly suggest HOT 2
- Invalid duration specification for ss:30 (ffmpeg) HOT 2
- Can i use this library to achieve .mp4 to hls HOT 3
- Record stream to mp4 HOT 1
- License file. HOT 1
- issue with ProgressTracker HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crymedia.