tytd-server/TYTD.Api/Server/Functions/ffmpeg.cs

119 lines
3.6 KiB
C#
Raw Normal View History

2021-09-27 05:52:31 +00:00
using System;
2021-06-24 01:10:20 +00:00
using System.Diagnostics;
using System.IO;
2021-12-08 01:07:43 +00:00
namespace TYTD.Server.Functions
2021-06-24 01:10:20 +00:00
{
internal class ffmpeg
{
internal static string FFMPEG = ffmpeg.get_ffmpeg();
private static string get_ffmpeg()
{
2021-10-24 12:52:24 +00:00
Directory.CreateDirectory("config");
string ffmpgloc = Path.Combine(Environment.CurrentDirectory, "config", "ffmpeg.txt");
if (File.Exists(ffmpgloc))
2021-06-24 01:10:20 +00:00
{
2021-10-24 12:52:24 +00:00
return File.ReadAllText(ffmpgloc);
2021-06-24 01:10:20 +00:00
}
2021-10-24 12:52:24 +00:00
2021-06-24 01:10:20 +00:00
return "ffmpeg";
}
2021-09-27 05:52:31 +00:00
public static void on_video_done(string id,int res)
{
2021-06-24 01:10:20 +00:00
string path_to_video_id = Path.Combine("Info",$"{id}.json");
2021-09-27 05:52:31 +00:00
Directory.CreateDirectory("config");
2021-11-08 01:42:56 +00:00
2021-09-27 05:52:31 +00:00
string vdone= Path.Combine(Environment.CurrentDirectory, "config", "done");
try
{
2021-11-08 01:42:56 +00:00
2021-09-27 05:52:31 +00:00
using (var p = new Process())
{
p.StartInfo.FileName = vdone;
p.StartInfo.Arguments = $"\"{id}\" \"{path_to_video_id}\" {res}";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
}
}
catch (Exception ex)
{
_ = ex;
}
}
2021-06-24 01:10:20 +00:00
internal static void mux(string mypath, string mypathCompleteAudio, string mypathIncompleteConverting)
{
using (var p = new Process())
{
p.StartInfo.FileName = FFMPEG;
2021-06-24 03:17:29 +00:00
p.StartInfo.Arguments = $"-i \"{mypath}\" -i \"{mypathCompleteAudio}\" -c copy -map 0:v -map 1:a \"{mypathIncompleteConverting}\"";
2021-06-24 01:10:20 +00:00
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (p.Start())
{
p.WaitForExit();
}
}
}
//internal static async Task download_thumb2(string )
2021-06-24 01:10:20 +00:00
internal static void download_thumbnail(string tnail, string p2)
{
using (var p = new Process())
{
2021-06-28 14:13:03 +00:00
p.StartInfo.FileName = "/bin/bash";
p.StartInfo.Arguments = $"\"config/thumbs\" \"{tnail}\" \"{p2}\"";
2021-06-24 01:10:20 +00:00
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (p.Start())
{
p.WaitForExit();
}
}
}
}
public class ProgressTwo
{
double vanda;
double v;
double a;
double vval=0;
double aval=0;
IProgress<double> report;
public ProgressTwo(double vsize,double asize,IProgress<double> p)
{
vanda = vsize + asize;
v = vsize / vanda; //v = 0.1 if vsize == 20 and vanda=200
a = asize / vanda;
Video = new Progress<double>(ProgressVideo);
Audio = new Progress<double>(ProgressAudio);
report = p;
}
private void ProgressAudio(double d)
{
aval = d * a;
Process();
}
private void ProgressVideo(double d)
{
vval = d * v;
Process();
}
private void Process()
{
report.Report(aval + vval);
}
public Progress<double> Video { get; set; }
public Progress<double> Audio { get; set; }
}
}