0

I'm using the NReco to convert videos. I declare the converter like the following, and add a handler to ConvertProgress.

Dim vid_Convert As New FFMpegConverter
AddHandler vid_Convert.ConvertProgress, Sub(sender, e) vidConvertProgress(folder,fname,fext,fverdest,fint,fcount,fhost,e)
vid_Convert.ConvertMedia(file_temp, Nothing, file_dest, "mp4", cSettings)

The media is converted fine. The problem is in the handler where I declare a new converter and have it do a GetVideoThumbnail (when the prior conversion is completed), like this:

Dim vid_Extract As New FFMpegConverter
vid_Extract.GetVideoThumbnail(inputFile, outputFile, extractposition)

This produces the error "The specified executable is not a valid application for this OS platform". However, I've executed the GetVideoThumbnail method by itself elsewhere in my program with no problem. For some reason, it won't work if it's executed within the handler. Is there a way around this?

swabygw
  • 813
  • 1
  • 10
  • 22

1 Answers1

0

I assume you use NReco.VideoConverter nuget package which embeds ffmpeg.exe and extracts it on first use. Most likely you call "ConvertMedia" and "GetVideoThumbnail" in parallel and this may cause incorrect extraction of ffmpeg.exe.

Workaround for this issue may be calling new FFMpegConverter().ExtractFFmpeg(); on the application start (in Program.cs) to guarantee that on "ConvertMedia" and "GetVideoThumbnail" calls ffmpeg is already extracted.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • Thanks for the response - I found another solution: I upgraded to the latest version of the VideoConverter.dll and it worked okay. – swabygw Jul 18 '18 at 10:59
  • Btw, I posted a slightly related question here: https://stackoverflow.com/questions/51400594/net-threads-are-not-separate – swabygw Jul 18 '18 at 11:15
  • One other note - I moved the processing into a Thread and got the same error again. I used your suggestion of ExtractFFmpeg and it worked. Thanks again! – swabygw Jul 18 '18 at 22:11
  • I take it back - it worked a few times and the same error came back due to being in a thread. It produces the error right at the ConvertMedia command...sorry. :( – swabygw Jul 18 '18 at 23:21
  • Here's a post from someone with the same issue: https://stackoverflow.com/questions/29734440/c-sharp-the-specified-executable-is-not-a-valid-application-for-this-os-platform – swabygw Jul 18 '18 at 23:25
  • @swabygw ExtractFFmpeg method should be called only once on application start (from the main thread - this is important, without any other calls in parallel). – Vitaliy Fedorchenko Jul 19 '18 at 06:39
  • How would that work? Suppose I need to declare add'l instances if the user wants to make multiple conversions? For example, first: Public vid_Convert As FFMpegConverter. Then: vid_Convert = New FFMpegConverter. Then vid_Convert.ExractFFmpeg. Some video is converted and then: vid_Convert = Nothing. Now it's time to do a new conversion, so vid_Convert = New FFMpegConverter. Should I do another vid_Convert.ExtractFFmpeg? (I should also ask what that command does) – swabygw Jul 19 '18 at 19:19
  • ExtractFFMpeg method forces ffmpeg.exe extraction (it is embedded into DLL as resource), this is one-time action. 'Invalid executable error' might occur because ffmpeg.exe is extracted only partially because of concurrency. – Vitaliy Fedorchenko Jul 20 '18 at 14:46