tytd-server/Server/Functions/ffmpeg.cs

113 lines
3.5 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;
namespace youtube_downloader.Server.Functions
{
internal class ffmpeg
{
internal static string FFMPEG = ffmpeg.get_ffmpeg();
private static string get_ffmpeg()
{
if (File.Exists("ffmpeg.txt"))
{
return File.ReadAllText("ffmpeg.txt");
}
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
2021-09-27 05:52:31 +00:00
string path_to_video_id = Path.Combine(Downloader.DL.StorageLocation,"Info",$"{id}.json");
Directory.CreateDirectory("config");
string vdone= Path.Combine(Environment.CurrentDirectory, "config", "done");
try
{
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 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 = $"\"{Downloader.DL.GetPath(true, "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; }
}
}