Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.

Commit 1f0d6c9

Browse files
committed
Select opengl and vulkan devices in ffmpeg
1 parent c136121 commit 1f0d6c9

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

Av1ador/Encoder.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal class Encoder : ICloneable
2020
private string speed_str;
2121
public static bool Libfdk { get; set; }
2222
public static bool Libplacebo { get; set; }
23+
public static string OCL_Device { get; set; }
24+
public static string Vkn_Device { get; set; }
2325
public string[] Resos { get; set; }
2426
public int Max_crf { get; set; }
2527
public int Crf { get; set; }
@@ -106,6 +108,12 @@ public Encoder()
106108
Vf = new List<string>();
107109
Af = new List<string>();
108110
Multipass = "";
111+
112+
string[] exes = Func.Exes();
113+
OCL_Device = exes[1];
114+
Vkn_Device = exes[2];
115+
Libfdk = exes[0].Contains("enable-libfdk-aac");
116+
Libplacebo = exes[0].Contains("enable-libplacebo") && Vkn_Device != "";
109117
}
110118
private string[] CheckNvidia(string[] vtags)
111119
{
@@ -683,12 +691,12 @@ public string Build_vstr(bool predict = false)
683691
{
684692
if (s.Contains("libplacebo") && Libplacebo)
685693
{
686-
str += " -init_hw_device vulkan";
694+
str += " -init_hw_device vulkan:" + Vkn_Device;
687695
break;
688696
}
689697
if (s.Contains("opencl"))
690698
{
691-
str += " -init_hw_device opencl=gpu -filter_hw_device gpu";
699+
str += " -init_hw_device opencl=" + OCL_Device + " -filter_hw_device " + OCL_Device;
692700
break;
693701
}
694702
}

Av1ador/Form1.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class Form1 : Form
2525
[DllImport("user32.dll")]
2626
static extern bool GetCursorPos(ref Point point);
2727

28-
private readonly string title = "Av1ador 1.2.11";
28+
private readonly string title = "Av1ador 1.2.12";
2929
private readonly Regex formatos = new Regex(".+(mkv|mp4|avi|webm|ivf|m2ts|wmv|mpg|mov|3gp|ts|mpeg|y4m|vob|m2v|m4v|flv|asf|png)$", RegexOptions.IgnoreCase);
3030
private Player mpv;
3131
private Video primer_video, segundo_video;
@@ -75,11 +75,8 @@ private void Form1_Load(object sender, EventArgs e)
7575
{
7676
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
7777
Text = title;
78-
string exes = Func.Exes();
7978

8079
encoder = new Encoder();
81-
Encoder.Libfdk = exes.Contains("enable-libfdk-aac");
82-
Encoder.Libplacebo = exes.Contains("enable-libplacebo");
8380
workersUpDown.Maximum = encoder.Cores;
8481
workersgroupBox.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(workersgroupBox, true, null);
8582
listBox1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(listBox1, true, null);

Av1ador/Function.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public class Func
1515
{
1616
public static readonly string bindir = "bin\\";
1717

18-
public static string Exes()
18+
public static string[] Exes()
1919
{
2020
string msg = "";
21-
string output = "";
21+
string[] output = new string[3];
2222
Process process = new Process();
2323
Setinicial(process, 3);
2424
try
2525
{
2626
process.Start();
27-
output = process.StandardError.ReadToEnd();
27+
output[0] = process.StandardError.ReadToEnd();
2828
}
2929
catch
3030
{
@@ -53,6 +53,21 @@ public static string Exes()
5353
if (msg != "")
5454
if (MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
5555
Environment.Exit(0);
56+
Setinicial(process, 3, " -hide_banner -init_hw_device list");
57+
process.Start();
58+
string types = process.StandardOutput.ReadToEnd();
59+
if (types.Contains("opencl"))
60+
{
61+
process.StartInfo.Arguments = " -hide_banner -v debug -init_hw_device opencl";
62+
process.Start();
63+
output[1] = new Regex(@"[0-9]+\.[0-9]+: ").Match(process.StandardError.ReadToEnd()).Value.Replace(":", "").Trim();
64+
}
65+
if (types.Contains("vulkan"))
66+
{
67+
process.StartInfo.Arguments = " -hide_banner -v debug -init_hw_device vulkan";
68+
process.Start();
69+
output[2] = new Regex(@"[0-9\.]+:").Match(new Regex(@"GPU listing:[\n\r]*.*[0-9]+: ").Match(process.StandardError.ReadToEnd()).Value).Value.Replace(":", "").Trim();
70+
}
5671
return output;
5772
}
5873

Av1ador/Video.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,22 +469,22 @@ internal void Grain_detect(NumericUpDown gsupdown, Label status, int maxgs, Labe
469469
Process ffmpeg = new Process();
470470
Func.Setinicial(ffmpeg, 3);
471471
int ss = (int)(Duration * i / (loop + 2));
472-
string cmd = " -loglevel panic -init_hw_device opencl=gpu -filter_hw_device gpu -ss " + ss + " -i \"" + File + "\" -an -sn -frames:v 1 -vf \"" + crop + "thumbnail=n=" + frames + ",scale=w=1920:h=1080:force_original_aspect_ratio=decrease:force_divisible_by=2";
472+
string cmd = " -loglevel panic -init_hw_device opencl=" + Encoder.OCL_Device + " -filter_hw_device " + Encoder.OCL_Device + " -ss " + ss + " -i \"" + File + "\" -an -sn -frames:v 1 -vf \"" + crop + "thumbnail=n=" + frames + ",scale=w=1920:h=1080:force_original_aspect_ratio=decrease:force_divisible_by=2";
473473
if (Hdr == 1)
474474
cmd += ",format=p010,hwupload,tonemap_opencl=tonemap=hable:r=tv:p=bt709:t=bt709:m=bt709:format=nv12,hwdownload,format=nv12";
475475
else if (Hdr == 2 && Encoder.Libplacebo)
476476
{
477-
cmd = cmd.Replace("opencl=gpu -filter_hw_device gpu", "vulkan");
477+
cmd = cmd.Replace("opencl=" + Encoder.OCL_Device + " -filter_hw_device " + Encoder.OCL_Device + "", "vulkan:" + Encoder.Vkn_Device);
478478
cmd += ",format=yuv420p10le,hwupload,libplacebo=tonemapping=reinhard:range=tv:color_primaries=bt709:color_trc=bt709:colorspace=bt709:format=yuv420p,hwdownload,format=yuv420p";
479479
}
480480
cmd += "\" -lossless 1 -compression_level 1 -y \"" + name + "_th.webp\"";
481481
ffmpeg.StartInfo.Arguments = cmd;
482482
ffmpeg.Start();
483483
ffmpeg.WaitForExit(-1);
484-
ffmpeg.StartInfo.Arguments = " -loglevel panic -init_hw_device opencl=gpu -filter_hw_device gpu -i \"" + name + "_th.webp\" -frames:v 1 -vf pad=(iw+16):(ih+16):8:8,format=pix_fmts=yuv420p,hwupload,nlmeans_opencl=s=1.8:p=7:r=9,hwdownload,format=pix_fmts=yuv420p,crop=(iw-16):(ih-16):8:8 -lossless 1 -compression_level 1 -y \"" + name + "_th_dns.webp\"";
484+
ffmpeg.StartInfo.Arguments = " -loglevel panic -init_hw_device opencl=" + Encoder.OCL_Device + " -filter_hw_device " + Encoder.OCL_Device + " -i \"" + name + "_th.webp\" -frames:v 1 -vf pad=(iw+16):(ih+16):8:8,format=pix_fmts=yuv420p,hwupload,nlmeans_opencl=s=1.8:p=7:r=9,hwdownload,format=pix_fmts=yuv420p,crop=(iw-16):(ih-16):8:8 -lossless 1 -compression_level 1 -y \"" + name + "_th_dns.webp\"";
485485
ffmpeg.Start();
486486
ffmpeg.WaitForExit(-1);
487-
ffmpeg.StartInfo.Arguments = " -loglevel panic -init_hw_device opencl=gpu -filter_hw_device gpu -i \"" + name + "_th.webp\" -frames:v 1 -vf pad=(iw+12):(ih+12):6:6,format=pix_fmts=yuv420p,hwupload,nlmeans_opencl=s=4:p=5:r=15,hwdownload,format=pix_fmts=yuv420p,crop=(iw-10):(ih-12):6:6 -lossless 1 -compression_level 1 -y \"" + name + "_th_dnb.webp\"";
487+
ffmpeg.StartInfo.Arguments = " -loglevel panic -init_hw_device opencl=" + Encoder.OCL_Device + " -filter_hw_device " + Encoder.OCL_Device + " -i \"" + name + "_th.webp\" -frames:v 1 -vf pad=(iw+12):(ih+12):6:6,format=pix_fmts=yuv420p,hwupload,nlmeans_opencl=s=4:p=5:r=15,hwdownload,format=pix_fmts=yuv420p,crop=(iw-10):(ih-12):6:6 -lossless 1 -compression_level 1 -y \"" + name + "_th_dnb.webp\"";
488488
ffmpeg.Start();
489489
ffmpeg.WaitForExit(-1);
490490
double s1 = new FileInfo(name + "_th.webp").Length;

0 commit comments

Comments
 (0)