我尝试了这个参数:
"-r 1 -i" + ts + " -r 1" + _infilepath+"\"$filename%03d.png"
但它什么也不做,它没有在输出窗口中提取任何帧:
原始参数为:
"-ss " + ts + " "
+ "-i \"" + _infilepath + "\" "
+ "-frames:v 1 "
+ "-hide_banner -y -sn "
+ "\"" + outfile + "\""
但这仅提取第一帧。
_ffpath 包含 ffmpeg exe 文件 _infilepath 包含 mp4 视频文件 outfile 包含保存的帧文件
CommandRunner 方法位于底部。
private void Extract(){
if (_infilepath.Length == 0) {
MessageBox.Show(this, "The input file cannot be empty", "Validation error", MessageBoxButtons.OK,
MessageBoxIcon.None);
return;
}
if (_outfilepath.Length == 0) {
MessageBox.Show(this, "The output file cannot be empty", "Validation error", MessageBoxButtons.OK,
MessageBoxIcon.None);
return;
}
File.Delete(_outfilepath);
var exf = new ExtractProgressForm();
exf.Show(this);
string ts = tsin.Text.Replace(" ", "0");
string outfile = _outfilepath.Replace("%t", ts.Replace(":", "-").Replace(".", "_"));
_extractcr = new CommandRunner(
_ffpath,
"-r 1 -i" + ts + " -r 1" + _infilepath+"\"$filename%03d.png"
/*"-ss " + ts + " "
+ "-i \"" + _infilepath + "\" "
+ "-frames:v 1 "
+ "-hide_banner -y -sn "
+ "\"" + outfile + "\""*/,
false
);
CommandRunner 方法:
public CommandRunner(string fname, string args = "", bool autostart = true){
_fname = fname;
_args = args;
if (!_fileExists())
throw new FileNotFoundException(fname + " cannot be found");
Proc = new Process();
Proc.StartInfo.RedirectStandardOutput = true;
Proc.StartInfo.RedirectStandardError = true;
Proc.StartInfo.FileName = _fname;
if (_args.Length > 0)
Proc.StartInfo.Arguments = _args;
Proc.StartInfo.UseShellExecute = false;
Proc.StartInfo.CreateNoWindow = true;
if (autostart)
Start();
}
答案1
提取所有帧非常容易:
创建一个名为 Frames.... 的文件夹并:
ffmpeg -i input.mp4 "Frames\%07d.jpg"