8

I've got the project (ASP.NET Core, on Linux) where are the several tasks, which relate to the video converting and extracting frames from the video file.

I thought about the two possible options:

  1. using ffmpeg console utility
  2. using P/Invoke with the libavcodec library and others, which ffmpeg uses

The second option is miles harder and may be very impractical, because it reminds me developing the new wrapper/library, instead of using the ready products.

I've done googling, but there aren't well-done projects for the C#/ASP.NET Core on Linux platform. There are some good for C++ and Python, but NOT for the C# on Linux/.NET Core.

I decided to look at the first option, which I suppose would be more easier and practical. But, there are some weak places, which can produce many problems. We understand (I suppose), that using the 1st option, the end-developer shall use the process forking. So, there could be possible problems with the process idle and other possible issues...

I'm asking about your practice, because it's my first experience on Linux platform with the video converting/sampling using C#. I've used the Expression Encoder .NET library on Windows platform, but it's other story and it makes no sense, right now.

May be, there are other options, which I can't see right at the moment. I dislike the 1st option because of possible unhandled exceptions, because ffmpeg with such role becomes the black box for the ASP.NET Core backend.

  • 1
    I personally use 1st option. You need to redirect stdout strerr of course to capture output of ffmpeg to intercept errors (and inspect process exit code). You need to clatify what "many possible problems" you see in this case. That said I won't execute that directly from asp.net application, I'd have separate application to do video processing. – Evk Oct 30 '17 at 14:18
  • @Evk I see, that's an option, thanks. About possible problems... I understand, that to talk about the abstract options is rather silly, because to say such things is normal only from real practice. But, for example, video or audio was encoded with the errors, and ffmpeg may crash... Such situation may break the long video uploading process with generating previews... But, it also could be handled with stdin/stdout. I didn't think about this way, thanks. With such a way I'm able to handle all possible exceptions. –  Oct 30 '17 at 14:37
  • 1
    Well I didn't ever see ffmpeg to really crash, but even if it will - you will notice that too. Note that in such a case if you would have called in ffmpeg directly with pinvoke - _your_ process would crash instead. All in all I usually have separate applicaiton processing queue of video processing tasks (not necessary sequentially, may be using multiple threads or even multiple applications) and notifying interested parties (such as web application) about results. I'd never do such thing in asp.net web application process. – Evk Oct 30 '17 at 14:42
  • @Evk About monolithic architecture, I'm fully agree with you, that it's bad. This project is already using the service-oriented architecture (SOA) and there're already queues (with other tasks) and services communication (there is also, the separated OpenID Connect service in the project micro-services family). –  Oct 30 '17 at 14:46
  • 2
    In this case it's not even about monolithic architecture (though that too of course) but about this specific task of video processing. It might take long time to process video, so you cannot do that during http request (or it might be dropped by timeout) and you also don't want to spawn 1000 ffmpeg processes in case of high load, so you need a queue and in that case reasonable thing to do is to move that queue and its processing out of web application process (potentially video processing might take place on separate server even - here monolithic design will bite indeed). – Evk Oct 30 '17 at 14:50
  • @Evk I see, thank you for the good advice. –  Oct 30 '17 at 14:52

1 Answers1

0

I had the same problem and i created own minimal wrapper of FFMPEG based on FFmpeg.AutoGen. Wrapper working well on linux but this way need more time to undestand how FFMPEG libs working

A while ago for testing i created also youre first option by new Process(). Great thing in this way is is simplicity

        Process process = new Process();
        process.StartInfo.FileName = "ffmpeg.exe";
        process.StartInfo.Arguments = "example arguments";
        process.Start();

You need to decide by yourself but remember - Invoking C functions in C# is amazing thing

J. Doe
  • 2,651
  • 1
  • 13
  • 31