Reputation: 751
I am using ffmpeg in C# to discard a movie to its frame images and save each frame as a .png image. However, I can not save the frames! the code operates, but then I can not save them to a folder! I would like to know how can I save the output of ffmpeg to a folder.
public static void GetVideoFrames(string saveTo)
{
string mpegpath = @"E:\Csharp\ffvideo\";
string ffmpegPath = Path.Combine(mpegpath, "ffmpeg.exe");
string inputMovie = @"E:\Csharp\ffvideo\test.mp4";
string parameters = string.Format("ffmpeg -i {0} -f image2 frame-%1d.png -y {1}",
inputMovie, saveTo);
Process proc = new Process();
proc.StartInfo.FileName = ffmpegPath;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Arguments = parameters;
proc.Start();
}
Upvotes: 1
Views: 2561
Reputation: 14938
You are setting proc.StartInfo.FileName = ffmpegPath;
, but then your parameters
string is
string.Format("ffmpeg -i {0} -f image2 frame-%1d.png -y {1}", inputMovie, saveTo);
Try taking the ffmpeg
out of this string so it instead looks like:
string.Format("-i {0} -f image2 frame-%1d.png -y {1}", inputMovie, saveTo);
What I would suggest is happening here is that the command that is actually being executed is:
\path\to\ffmpeg.exe ffmpeg -i E:\Csharp\ffvideo\test.mp4 -f image2 frame-%1d.png -y \output\dir\path\
where the EXE is not liking that second ffmpeg
.
Edit:
I was able to segment a video into individual images with the following command:
ffmpeg.exe -i Test.mp4 -f image2 frame-1%d.png
The -y
option actually indicates that ffmpeg
will overwrite the files without asking.
From the description
Anything found on the command line which cannot be interpreted as an option is considered to be an output filename.
Meaning that ffmpeg
is treating \output\dir\path\
as the output file, which won't work in your case.
I think your best bet might be to try setting proc.StartInfo.WorkingDirectory
to the
directory you want the images written to. Note: the edit below is probably a better approach.
Edit 2:
To get them going in the chosen directory, change your format string from this:
frame-%1d.png
to this:
\output\path\frame-%1d.png
Upvotes: 1