Working mp4 joiner
This commit is contained in:
parent
770d6cf264
commit
a7e8ff1924
@ -44,7 +44,7 @@ namespace TaskRunner
|
|||||||
Console.WriteLine($"Got task {task.TaskId}");
|
Console.WriteLine($"Got task {task.TaskId}");
|
||||||
Console.WriteLine($"Source: {src.MimeType}");
|
Console.WriteLine($"Source: {src.MimeType}");
|
||||||
Console.WriteLine($"Dest: {dest.MimeType}");
|
Console.WriteLine($"Dest: {dest.MimeType}");
|
||||||
|
var mp4Parts = new List<string>();
|
||||||
foreach (var strUri in src.Uris)
|
foreach (var strUri in src.Uris)
|
||||||
{
|
{
|
||||||
var uri = new Uri(strUri["Uri"]);
|
var uri = new Uri(strUri["Uri"]);
|
||||||
@ -61,10 +61,17 @@ namespace TaskRunner
|
|||||||
Console.WriteLine("RunFfmpeg");
|
Console.WriteLine("RunFfmpeg");
|
||||||
await taskManager.swfRawToMp4(destSwf, destMp4);
|
await taskManager.swfRawToMp4(destSwf, destMp4);
|
||||||
File.Delete(destSwf);
|
File.Delete(destSwf);
|
||||||
var location = await server.UploadFile(destMp4);
|
mp4Parts.Add(destMp4);
|
||||||
//File.Delete(destMp4);
|
|
||||||
Console.WriteLine($"New location is {location}");
|
|
||||||
}
|
}
|
||||||
|
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) {
|
} catch (FailedToGetTaskException) {
|
||||||
Console.WriteLine("No tasks available");
|
Console.WriteLine("No tasks available");
|
||||||
return;
|
return;
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace TaskRunner
|
namespace TaskRunner
|
||||||
{
|
{
|
||||||
@ -39,8 +40,8 @@ namespace TaskRunner
|
|||||||
{
|
{
|
||||||
StartInfo =
|
StartInfo =
|
||||||
{
|
{
|
||||||
FileName = "avconv",
|
FileName = "ffmpeg",
|
||||||
Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p \"{dest}\"",
|
Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p -y \"{dest}\"",
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
UseShellExecute = false
|
UseShellExecute = false
|
||||||
},
|
},
|
||||||
@ -59,21 +60,35 @@ namespace TaskRunner
|
|||||||
|
|
||||||
public Task Mp4Join(IList<string> src, string dest)
|
public Task Mp4Join(IList<string> src, string dest)
|
||||||
{
|
{
|
||||||
|
if (src.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("src list is empty");
|
||||||
|
}
|
||||||
var task = new TaskCompletionSource<bool>();
|
var task = new TaskCompletionSource<bool>();
|
||||||
var process = new Process
|
var process = new Process
|
||||||
{
|
{
|
||||||
StartInfo =
|
StartInfo =
|
||||||
{
|
{
|
||||||
FileName = "avconv",
|
FileName = "ffmpeg",
|
||||||
Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p \"{dest}\"",
|
Arguments = $"-f concat -safe \"0\" -protocol_whitelist \"file,http,https,tcp,tls,pipe\" -i - -codec copy -y \"{dest}\"",
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
UseShellExecute = false
|
RedirectStandardInput = true,
|
||||||
|
UseShellExecute = false,
|
||||||
},
|
},
|
||||||
EnableRaisingEvents = true
|
EnableRaisingEvents = true
|
||||||
};
|
};
|
||||||
process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data);
|
process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data);
|
||||||
process.Start();
|
process.Start();
|
||||||
process.BeginOutputReadLine();
|
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) =>
|
process.Exited += (sender, args) =>
|
||||||
{
|
{
|
||||||
task.SetResult(true);
|
task.SetResult(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user