Skip to content

Commit

Permalink
Merge pull request #84 from DoTheSneedful/longPathFixes
Browse files Browse the repository at this point in the history
Fix for ffmpeg/ffprobe long paths not working
  • Loading branch information
argorar authored Jun 5, 2024
2 parents 368b40b + 9f34dd1 commit c8d7893
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions Components/FFprobe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FFprobe : Process

public FFprobe(string inputFile, string format = "-f avisynth", List<string> dataToProbe = null, string argument = null)
{
inputFile = Utility.ExtendedLenPath(inputFile);
if (argument == null) // No override arguments, time to construct this bad boy
{
if (dataToProbe == null)
Expand Down
7 changes: 4 additions & 3 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@ void SetFile(string path)
string streamInfo = prober.Probe();
Program.SubtitleTracks = new Dictionary<int, Tuple<string, SubtitleType, string>>();
Program.AttachmentList = new List<string>();
var workingFile = Utility.ExtendedLenPath(Program.InputFile);

using (var s = new StringReader(streamInfo))
{
Expand Down Expand Up @@ -1890,12 +1891,12 @@ void SetFile(string path)
if (type == SubtitleType.VTTSub && !File.Exists(file))
{
logIndexingProgress("Extracting vtt...");
ExecuteFFmpegCommand($@" -i ""{Program.InputFile}"" -map 0:{streamindex} ""{file}""");
ExecuteFFmpegCommand($@" -i ""{workingFile}"" -map 0:{streamindex} ""{file}""");
}
else if (!File.Exists(file)) // If we didn't extract it already
{
logIndexingProgress("Extracting...");
using (var mkvextract = new MkvExtract($@"tracks ""{Program.InputFile}"" ""{streamindex}:{file}"""))
using (var mkvextract = new MkvExtract($@"tracks ""{workingFile}"" ""{streamindex}:{file}"""))
{
mkvextract.Start();
mkvextract.WaitForExit();
Expand Down Expand Up @@ -1946,7 +1947,7 @@ void SetFile(string path)
}

logIndexingProgress("Extracting...");
using (var mkvextract = new MkvExtract($@"attachments ""{Program.InputFile}"" ""{attachindex}:{file}"""))
using (var mkvextract = new MkvExtract($@"attachments ""{workingFile}"" ""{attachindex}:{file}"""))
{
mkvextract.Start();
mkvextract.WaitForExit();
Expand Down
18 changes: 17 additions & 1 deletion Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static string GetCompatiblePath(string input)
{
// AviSynth and various plugins can't deal with utf-8 paths, so we convert the possibly weird path into 8.3 notation
var compatible = new StringBuilder(255);
NativeMethods.GetShortPathName(@"\\?\" + input, compatible, compatible.Capacity);
NativeMethods.GetShortPathName(ExtendedLenPath(input), compatible, compatible.Capacity);
// the \\?\ is added because GetShortPathName will fail if input is longer than 256 characters otherwise.
return compatible.ToString();
}
Expand Down Expand Up @@ -438,6 +438,22 @@ public static System.Drawing.Font CreateFontFromString(String data)
return new Font(fontName, fontSize, fontStyle);
}

public static string ExtendedLenPath(string path)
{
string pathWithPrefix;
// ffmpeg + tools only support long paths when using the \\?\ prefix
// https://trac.ffmpeg.org/ticket/8885
// https://learn.microsoft.com/en-gb/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
if (path.StartsWith(@"\\"))
{
pathWithPrefix = @"\\?\UNC" + path.Substring(1);
}
else
{
pathWithPrefix = @"\\?\" + path;
}
return pathWithPrefix;
}
}

public enum FileType
Expand Down

0 comments on commit c8d7893

Please sign in to comment.