Cleanup instantiation of FFmpegDownloaderForm and FFmpegService
This commit is contained in:
parent
73a780674d
commit
a149b7e033
|
@ -47,8 +47,7 @@ namespace BizHawk.Client.DiscoHawk
|
|||
try
|
||||
{
|
||||
File.WriteAllBytes(tempfile, waveData);
|
||||
var ffmpeg = new FFmpegService();
|
||||
ffmpeg.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path);
|
||||
FFmpegService.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -94,8 +94,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
//make sure it worked
|
||||
if (!new FFmpegService().QueryServiceAvailable())
|
||||
throw new Exception("download failed");
|
||||
if (!FFmpegService.QueryServiceAvailable()) throw new Exception("download failed");
|
||||
|
||||
succeeded = true;
|
||||
}
|
||||
|
@ -110,12 +109,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public static void Run(IDialogParent parent)
|
||||
{
|
||||
var form = new FFmpegDownloaderForm();
|
||||
parent.ShowDialogWithTempMute(form);
|
||||
}
|
||||
|
||||
private void btnDownload_Click(object sender, EventArgs e)
|
||||
{
|
||||
btnDownload.Text = "Downloading...";
|
||||
|
|
|
@ -209,18 +209,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public IDisposable AcquireVideoCodecToken(IDialogParent parent, Config config)
|
||||
{
|
||||
if (new FFmpegService().QueryServiceAvailable())
|
||||
if (!FFmpegService.QueryServiceAvailable())
|
||||
{
|
||||
return FFmpegWriterForm.DoFFmpegWriterDlg(parent.SelfAsHandle, config);
|
||||
using var form = new FFmpegDownloaderForm();
|
||||
parent.ShowDialogWithTempMute(form);
|
||||
if (!FFmpegService.QueryServiceAvailable()) return null;
|
||||
}
|
||||
|
||||
FFmpegDownloaderForm.Run(parent);
|
||||
if (new FFmpegService().QueryServiceAvailable())
|
||||
{
|
||||
return FFmpegWriterForm.DoFFmpegWriterDlg(parent.SelfAsHandle, config);
|
||||
}
|
||||
|
||||
return null;
|
||||
return FFmpegWriterForm.DoFFmpegWriterDlg(parent.SelfAsHandle, config);
|
||||
}
|
||||
|
||||
/// <exception cref="ArgumentException"><paramref name="token"/> does not inherit <see cref="FFmpegWriterForm.FormatPreset"/></exception>
|
||||
|
|
|
@ -8,7 +8,7 @@ using System.IO;
|
|||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
public class FFmpegService
|
||||
public static class FFmpegService
|
||||
{
|
||||
public static string FFmpegPath = string.Empty; // always updated in DiscoHawk.Program/EmuHawk.Program
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace BizHawk.Common
|
|||
//note: accepts . or : in the stream stream/substream separator in the stream ID format, since that changed at some point in FFMPEG history
|
||||
//if someone has a better idea how to make the determination of whether an audio stream is available, I'm all ears
|
||||
private static readonly Regex rxHasAudio = new Regex(@"Stream \#(\d*(\.|\:)\d*)\: Audio", RegexOptions.Compiled);
|
||||
public AudioQueryResult QueryAudio(string path)
|
||||
public static AudioQueryResult QueryAudio(string path)
|
||||
{
|
||||
var ret = new AudioQueryResult();
|
||||
string stdout = Run("-i", path).Text;
|
||||
|
@ -42,7 +42,7 @@ namespace BizHawk.Common
|
|||
/// <summary>
|
||||
/// queries whether this service is available. if ffmpeg is broken or missing, then you can handle it gracefully
|
||||
/// </summary>
|
||||
public bool QueryServiceAvailable()
|
||||
public static bool QueryServiceAvailable()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -61,7 +61,7 @@ namespace BizHawk.Common
|
|||
public int ExitCode;
|
||||
}
|
||||
|
||||
public RunResults Run(params string[] args)
|
||||
public static RunResults Run(params string[] args)
|
||||
{
|
||||
args = Escape(args);
|
||||
StringBuilder sbCmdline = new StringBuilder();
|
||||
|
@ -92,7 +92,7 @@ namespace BizHawk.Common
|
|||
}
|
||||
|
||||
/// <exception cref="InvalidOperationException">FFmpeg exited with non-zero exit code or produced no output</exception>
|
||||
public byte[] DecodeAudio(string path)
|
||||
public static byte[] DecodeAudio(string path)
|
||||
{
|
||||
string tempfile = Path.GetTempFileName();
|
||||
try
|
||||
|
|
|
@ -20,12 +20,7 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
{
|
||||
}
|
||||
|
||||
private bool CheckForAudio(string path)
|
||||
{
|
||||
FFmpegService ffmpeg = new FFmpegService();
|
||||
var qa = ffmpeg.QueryAudio(path);
|
||||
return qa.IsAudio;
|
||||
}
|
||||
private bool CheckForAudio(string path) => FFmpegService.QueryAudio(path).IsAudio;
|
||||
|
||||
/// <summary>
|
||||
/// finds audio at a path similar to the provided path (i.e. finds Track01.mp3 for Track01.wav)
|
||||
|
@ -59,7 +54,7 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
}
|
||||
|
||||
/// <exception cref="AudioDecoder_Exception">could not find source audio for <paramref name="audioPath"/></exception>
|
||||
public byte[] AcquireWaveData(string audioPath) => new FFmpegService()
|
||||
public byte[] AcquireWaveData(string audioPath) => FFmpegService
|
||||
.DecodeAudio(FindAudio(audioPath) ?? throw new AudioDecoder_Exception($"Could not find source audio for: {Path.GetFileName(audioPath)}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,9 +327,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
|
|||
//check whether processing was available
|
||||
if (needsCodec)
|
||||
{
|
||||
FFmpegService ffmpeg = new FFmpegService();
|
||||
if (!ffmpeg.QueryServiceAvailable())
|
||||
Warn("Decoding service will be required for further processing, but is not available");
|
||||
if (!FFmpegService.QueryServiceAvailable()) Warn("Decoding service will be required for further processing, but is not available");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,8 +114,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
|
|||
}
|
||||
case CompiledCueFileType.DecodeAudio:
|
||||
{
|
||||
FFmpegService ffmpeg = new FFmpegService();
|
||||
if (!ffmpeg.QueryServiceAvailable())
|
||||
if (!FFmpegService.QueryServiceAvailable())
|
||||
{
|
||||
throw new DiscReferenceException(ccf.FullPath, "No decoding service was available (make sure ffmpeg.exe is available. Even though this may be a wav, ffmpeg is used to load oddly formatted wave files. If you object to this, please send us a note and we'll see what we can do. It shouldn't be too hard.)");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue