How to manipulate video in .NET using ffmpeg

March 12th, 2008

In this case I’m resizing the video and convertingĀ it to FLV format. For more ffmpeg commandline optionsĀ - http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html

private void ConvertVideo(string srcURL, string destURL)
{
    string ffmpegURL = “~/project/tools/ffmpeg.exe”;
    DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    startInfo.Arguments = string.Format(“-i \”{0}\” -s 368×216 -aspect 1.7777 \”{1}\”", srcURL, destURL);
    startInfo.WorkingDirectory = directoryInfo.FullName;
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardOutput = true;
    startInfo.RedirectStandardInput = true;
    startInfo.RedirectStandardError = true;

    using (Process process = new Process())
    {
        process.StartInfo = startInfo;

        try
        {
            process.Start();
            StreamReader standardOutput = process.StandardOutput;
            StreamWriter standardInput = process.StandardInput;
            StreamReader standardError = process.StandardError;
            process.WaitForExit();

            lblError.Text = standardError.ReadToEnd();
            lblOutput.Text = standardOutput.ReadToEnd();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}

Programming | Comments | Trackback Jump to the top of this page

7 comments on “How to manipulate video in .NET using ffmpeg”

  1. 01

    hi all,

    i worked out the above given code. its not working if the file size is large for example the file size is greater than 750kb. its not to convert flv format. plz reply me

    Balaji at April 9th, 2008 around 6:29 am
    Jump to the top of this page
  2. 02

    […] a release showing just how to do transcoding using FFMPEG in VB.Net.  Another individual made this work in c# too! Filed under: […]

    Coding4Fun : FFmpeg to transcode at April 16th, 2008 around 4:13 pm
    Jump to the top of this page
  3. 03

    What configuration to be made to make it work in online?
    it is working fine in local but it is n’t working in server..urgent

    sekar at April 19th, 2008 around 12:19 am
    Jump to the top of this page
  4. 04

    sekar - Make sure you have the right permissions. The directory in which you have FFMPEG files need to have read and execute permissions (all files!) and the directory where you intend to put the converted files need to have write permissions. If that doesn’t work then try commenting out - process.WaitForExit(); - I’ve had problems with it in shared hosting environment where it just hangs the process every now and then.

    J at April 19th, 2008 around 12:35 am
    Jump to the top of this page
  5. 05

    The hangs are caused by your way of handling the redirected streams. while the program runs you have to read from them because if there is to much unread data in them ffmpeg cant write to them anymore. you can listen for the StandardOutputReceived event to mitigate this issue.

    name at April 20th, 2008 around 8:14 am
    Jump to the top of this page
  6. 06

    name - Thanks for your comment, that makes sense. I’ll give it a try.

    J at April 21st, 2008 around 9:58 am
    Jump to the top of this page
  7. 07

    […] on the reader comments on my previous entry on this topic I was able to fix some of the issues that others were […]

    Jump to the top of this page

Leave a Reply

  •  
  •  
  •  

You can keep track of new comments to this post with the comments feed.


Recently on Flickr

  • IMG_0514
  • IMG_0506
  • IMG_0505
  • IMG_0503
  • IMG_0497
  • IMG_0495
  • IMG_0494
  • IMG_0493

Switch Theme

Meta