create animated gif from video using ffmpeg and c#

1.7k Views Asked by At

I am trying to get animated gif from an video file.I cant create gif from below code. could any one help me in solving this problem.

      Process ffmpeg; // creating process
    string video;
    string thumb;
 //   string text = System.IO.File.ReadAllText(@"C:\xampp\htdocs\h\myText.txt");
    video = Page.MapPath("") + "\\o.avi";
    thumb = Page.MapPath("") + "\\output\\o.gif"; // thumb name with path !
    ffmpeg = new Process();
    int num = 3;
    int secpos = 1;

    // ffmpeg.StartInfo.Arguments = "ffmpeg -i o.avi -vf scale=320:-1,format=rgb8,format=rgb24 -t 10 -r 10 output.gif"; // arguments !
    ffmpeg.StartInfo.Arguments = " -i \"" + video + "\" -s 108*80 -ss " + secpos + " -t " + num + "\" -vf scale=320:-1,format=rgb8,format=rgb24 \"" + thumb + "\"";
    ffmpeg.StartInfo.FileName = Page.MapPath("ffmpeg//ffmpeg.exe");
    ffmpeg.Start(); // start !  

I think there is a mistake in ffmpeg.StartInfo.Arguments .

1

There are 1 best solutions below

0
On

Your code produces the argument string

-i "path" -s 108*80 -ss 1 -t 3" -vf scale=320:-1,format=rgb8,format=rgb24 "path"

3" looks like am obvious error.