Using FFmpeg in C# project

21,336

Solution 1

This is my sample, hope this help

You can use .exe file like this:

ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.FileName = Server.MapPath("~/Video_Clips/ffmpeg.exe");

ffmpeg.StartInfo.Arguments = String.Format(@"-i ""{0}"" -threads 8 -f webm -aspect 16:9 -vcodec libvpx -deinterlace -g 120 -level 216 -profile 0 -qmax 42 -qmin 10 -rc_buf_aggressivity 0.95 -vb 2M -acodec libvorbis -aq 90 -ac 2 ""{1}""",
                                           Server.MapPath("~/Video_Clips/" + sNameWithoutExtension + ".wmv"),
                                           Server.MapPath("~/Video_Clips/" + sNameWithoutExtension + ".webm"));
ffmpeg.Start();

ffmpeg.WaitForExit();

Solution 2

I know it's a bit old thread but if I get here other people see this too. You shoudn't use it process info to start ffmpeg. It is a lot to do with it. Just use any wrapper. I did this mistake and waste almost year of my life... In Xabe.FFmpeg you could do this by running just

await Conversion.New().Start(@"-i ""{0}"" -threads 8 -f webm -aspect 16:9 -vcodec libvpx -deinterlace -g 120 -level 216 -profile 0 -qmax 42 -qmin 10 -rc_buf_aggressivity 0.95 -vb 2M -acodec libvorbis -aq 90 -ac 2 ""{1}");

but this is just a basic usage because it provide fluent API to use FFmpeg.

Share:
21,336
JustLogin
Author by

JustLogin

Updated on August 18, 2020

Comments

  • JustLogin
    JustLogin almost 4 years

    I'm trying to create a desktop live-streaming app in C#. The program must run under Windows and stream image from user's desktop to rtmp. There must also be options of framerate, video size, quality and codec (h263 and h264). I think FFmpeg is the best choise for this (if it is not so, please write a comment). I've managed to do everything I mentioned above with ffmpeg.exe using console. So I wish to know, can I include FFmpeg library into C# project (as a .lib or .dll) to use it instead of .exe, saving suitable functionality for my task? I'll be very grateful for any examples.

    P.S. Here are some examples of commands I use:

    ffmpeg -f dshow -i video=UScreenCapture -vcodec h264 -pix_fmt yuv420p -s 320x240 -f flv rtmp://[my adr]/desc
    
    ffmpeg -f dshow -i video=UScreenCapture -vcodec h264 -r 15 -t 0:1:00 -q 12 -pix_fmt yuv420p -s 320x240 -f flv rtmp://[my adr]/desc