0

I am trying to convert a .flac-file to a .wav-file using NReco.VideoConverter, but I keep getting an error and I do not know why. This is the piece of code I am using for the conversion:

        //Create the NReco.VideoConverter.FFMpegConverter object
        var ffmpeg = new FFMpegConverter();

        //inputFile will be something like this:
        //type: string, "C:\\some\\folder\\fullTrackName" + ".flac"
        var inputFile = Path.Combine(downloadFolder + fullTrackNameNoExtension + ".flac");

        //outputFile will be something like this:
        //type: string, "C:\\some\\folder\\musicfile" + ".wav"
        var outputFile = Path.Combine(downloadFolder + fullTrackNameNoExtension + ".wav");

        //Convert the file using NReco.VideoConverter.FFMpegConverter
        ffmpeg.ConvertMedia(inputFile, outputFile, null);

inputFile/outputFile would be like this, this is what I see when I insert a breakpoint and check the values of in/outputFile:

string, inputFile/outputFile: "Z:\\Downloads\\Audio - File (Original Mix).flac" (or .wav)

And this is the error I receive when I run ffmpeg.ConvertMedia:

System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.File.InternalGetLastWriteTimeUtc(String path, Boolean checkHost)
   at NReco.VideoConverter.FFMpegConverter.EnsureFFMpegLibs()
   at NReco.VideoConverter.FFMpegConverter.ConvertMedia(Media input, Media output, ConvertSettings settings)
   at NReco.VideoConverter.FFMpegConverter.ConvertMedia(String inputFile, String inputFormat, String outputFile, String outputFormat, ConvertSettings settings)
   at NReco.VideoConverter.FFMpegConverter.ConvertMedia(String inputFile, String outputFile, String outputFormat)
   at APPLICATION_Name.APPLICATION_Class.ConvertFile(String downloadFolder, String fullTrackName, String fullTrackNameNoExtension, String downloadQuality, String downloadType) in X:\APPLICATION_Name\DownloadTrack.cs:line 244

1 Answers1

0

Exception is thrown from "FFMpegConverter.EnsureFFMpegLibs" method that extracts ffmpeg binaries on first use (by default to app bin folder) and I may assume that for some reason it is determined incorrectly (or maybe network path is used).

You can try to change the location for ffmpeg.exe by specifying FFMpegConverter.FFMpegToolPath property (.net app should have enough rights to write to this folder).

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • Thanks a lot! ffmpeg.exe was saved in the bin-folder. When I delete the ffmpeg.exe, and try to convert the media again, it places ffmpeg.exe again into the folder, which is fine. The first conversion goes fine, but the second one fails (when ffmpeg.exe already exists). So, it looks like ffmpeg.exe should not exist when I do a ConvertMedia. I can do a File.Delete(ffmpegexePath);, but that is a dirty solution. Can I solve this? Or is it an problem in NReco? –  Jan 26 '17 at 17:53
  • 1
    @Dyon ffmpeg.exe is extracted on first use and this is correct behavior. Definitely you don't need to delete ffmpeg.exe each time. It seems the problem is not with ffmpeg.exe location itself, but with code that compares assembly's date with ffmpeg.exe date: File.GetLastWriteTime(thisAssembly.Location). It is very strange why this code leads to "The path is not of a legal form" -- I'll provide a hotfix for this case in the next verison. Until that you may use LT version (please contact NReco support on this). – Vitaliy Fedorchenko Jan 27 '17 at 07:10