1

I'm trying to take two videos and transform them with ffmpeg into a single video. It works great if you take the two videos, run them through ffmpeg and then serve that file up via an API. Unfortunately the upper range for these videos is ~20 minutes, and this method takes too long to create the full video (~30 seconds w/ ultrafast).

I had an idea to stream the output of the ffmpeg command to the client which would eliminate the need to wait for ffmpeg to create the whole video. I've tried to proof this out myself and haven't had much success. It could be my inexperience with streams, or this could be impossible.

Does anyone know if my idea to stream the in-progress output of ffmpeg is possible / feasible?

Inondle
  • 332
  • 1
  • 5
  • 16
  • *"I'm trying to take two videos and transform them with ffmpeg into a single video."* Show your command and the complete log. There might be a faster way to do it. – llogan Mar 03 '21 at 23:51
  • Yes it is possible - with a little code .... There's already a good article [on using FFMPEG in .NET](https://stackoverflow.com/questions/2527963/using-ffmpeg-in-net) – Mr R Mar 04 '21 at 04:49
  • @llogan here's the command I wrote up to combine 4 videos to play in a 2x2 grid: `.\ffmpeg.exe -i .\input1.mp4 -i .\input2.mp4 -i .\input3.mp4 -i ./input4.mp4 -filter_complex "[0:v][1:v]hstack=inputs=2[row1]; [2:v][3:v]hstack=inputs=2[row2]; [row1][row2]vstack=inputs=2[outv]" -map "[outv]" -preset ultrafast out.mp4` – Inondle Mar 04 '21 at 17:11
  • Which output protocol do you want to use? What format do you need to support? Is the client local or networked? – llogan Mar 04 '21 at 17:50
  • not sure what output protocol refers to, but I want the output file to be mp4. Client is networked, I'd like to stream the in-progress output of ffmpeg to the client somehow. My stream-foo isn't advanced enough to know if you can do that though – Inondle Mar 04 '21 at 18:08
  • One way is to use RTSP, check this link for more info https://www.codeproject.com/Articles/507218/Managed-Media-Aggregation-using-Rtsp-and-Rtp – Jimson James Mar 09 '21 at 01:59

2 Answers2

1

you should check hangfire. I used this for running the process on the background, and if it needs a notification, signalR will help you

0

What do you mean by "streaming" ? Serving the result of your command to an http client on the fly ? Or your client is some video player that play the video (like a VLC player receiving a tcp stream of 4 IP cameras) ?

Dealing with video isn't a simple task, and you need to choose your protocols, tools and even hardware carefully.

Based on the command that you send as an example, you probably need some jobs that convert your videos. Here's a complete article on how to use Azure Batch to process using ffmeg. You can use any batching solution if you want (another answer suggests Hangfire and it's ok too)

saad
  • 764
  • 4
  • 18