From a7e8ff19249b45482af5e4f1e5f121d186974683 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Thu, 25 May 2017 17:42:34 +0300 Subject: [PATCH] Working mp4 joiner --- TaskRunner/Program.cs | 15 +++++++++++---- TaskRunner/TaskManager.cs | 25 ++++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/TaskRunner/Program.cs b/TaskRunner/Program.cs index 3ba7993..a060146 100644 --- a/TaskRunner/Program.cs +++ b/TaskRunner/Program.cs @@ -44,7 +44,7 @@ namespace TaskRunner Console.WriteLine($"Got task {task.TaskId}"); Console.WriteLine($"Source: {src.MimeType}"); Console.WriteLine($"Dest: {dest.MimeType}"); - + var mp4Parts = new List(); foreach (var strUri in src.Uris) { var uri = new Uri(strUri["Uri"]); @@ -61,10 +61,17 @@ namespace TaskRunner Console.WriteLine("RunFfmpeg"); await taskManager.swfRawToMp4(destSwf, destMp4); File.Delete(destSwf); - var location = await server.UploadFile(destMp4); - //File.Delete(destMp4); - Console.WriteLine($"New location is {location}"); + mp4Parts.Add(destMp4); } + var outFile = $"/tmp/out.mp4"; + await taskManager.Mp4Join(mp4Parts, outFile); + var location = await server.UploadFile(outFile); + File.Delete(outFile); + foreach(var file in mp4Parts) + { + File.Delete(file); + } + Console.WriteLine($"New location is {location}"); } catch (FailedToGetTaskException) { Console.WriteLine("No tasks available"); return; diff --git a/TaskRunner/TaskManager.cs b/TaskRunner/TaskManager.cs index fe9d5e2..b195f84 100644 --- a/TaskRunner/TaskManager.cs +++ b/TaskRunner/TaskManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using System.IO; namespace TaskRunner { @@ -39,8 +40,8 @@ namespace TaskRunner { StartInfo = { - FileName = "avconv", - Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p \"{dest}\"", + FileName = "ffmpeg", + Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p -y \"{dest}\"", RedirectStandardOutput = true, UseShellExecute = false }, @@ -59,21 +60,35 @@ namespace TaskRunner public Task Mp4Join(IList src, string dest) { + if (src.Count == 0) + { + throw new Exception("src list is empty"); + } var task = new TaskCompletionSource(); var process = new Process { StartInfo = { - FileName = "avconv", - Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p \"{dest}\"", + FileName = "ffmpeg", + Arguments = $"-f concat -safe \"0\" -protocol_whitelist \"file,http,https,tcp,tls,pipe\" -i - -codec copy -y \"{dest}\"", RedirectStandardOutput = true, - UseShellExecute = false + RedirectStandardInput = true, + UseShellExecute = false, }, EnableRaisingEvents = true }; process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data); process.Start(); process.BeginOutputReadLine(); + foreach (var filename in src) + { + var l = $"file '{filename}'"; + Console.WriteLine(l); + process.StandardInput.WriteLine(l); + } + process.StandardInput.WriteLine(); + process.StandardInput.Flush(); + process.StandardInput.Close(); process.Exited += (sender, args) => { task.SetResult(true);