Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added call to GlobalFFOptions.Configure when setting FFprobeFolder. #1333

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions SIL.Media/MediaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ public class MediaInfo

/// <summary>
/// The folder where FFprobe should be found. An application can use this to set
/// the location before making any calls.
/// the location before making calls to obtain media info. Note that this sets a global
/// setting in FFmpegCore. If the application uses FFmpegCore to call FFprobe or FFmpeg
/// for other purposes, this folder will also be used for those calls.
/// </summary>
/// <exception cref="DirectoryNotFoundException">Folder does not exist</exception>
/// <exception cref="FileNotFoundException">Folder does not contain the ffprobe
/// executable</exception>
/// <exception cref="ArgumentException">FFMpegCore failed to set the requested
/// FFprobe folder.</exception>
/// <remarks>If set to <see cref="Empty"/>, indicates to this library that
/// FFprobe is not installed, and therefore methods to retrieve media info will
/// fail unconditionally (i.e. they will throw an exception)</remarks>
Expand All @@ -51,6 +55,16 @@ public static string FFprobeFolder
throw new FileNotFoundException(
"Path is not a folder containing FFprobe.exe: " + value);
}

// Configure tells FFMpegCore to remember the folder where it should find
// FFprobe (and also FFmpeg).
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = value });
var testResult = Path.GetDirectoryName(GlobalFFOptions.GetFFProbeBinaryPath());
// If it couldn't find FFprobe in the requested folder, GetFFProbeBinaryPath
// returns the filename with no folder (meaning that it hopes to find it
// somewhere on the system path).
if (testResult == null)
throw new ArgumentException("FFMpegCore failed to set the requested FFprobe folder.");
}

s_ffProbeFolder = value;
Expand Down Expand Up @@ -103,16 +117,9 @@ private static string GetPresumedFFprobeFolder()
GetFileDistributedWithApplication(true, "ffmpeg", FFprobeExe) ??
GetFileDistributedWithApplication(true, "ffprobe", FFprobeExe);

folder = !IsNullOrEmpty(withApplicationDirectory) ?
folder = (!IsNullOrEmpty(withApplicationDirectory) ?
Path.GetDirectoryName(withApplicationDirectory) :
GetFFmpegFolderFromChocoInstall(FFprobeExe);

if (folder != null)
{
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = folder });
}
else
folder = Empty;
GetFFmpegFolderFromChocoInstall(FFprobeExe)) ?? Empty;
}
}

Expand Down