异步启动ffmpeg.exe?

时间:2013-02-21 12:36:19

标签: c asynchronous process ffmpeg

是否可以从C程序中启动FFmpeg,然后不要等到进程终止,而是转到下一行代码。目前,我正在使用

int startFFmpeg()
{
    char cmd[100] = "D:\\ffmpeg\\bin\\ffmpeg.exe -i D:\\video.mpg -r 10 D:\\frames\\%d.jpg";
    int ff = system(cmd);
    return ff;
}

int main()
{
   int ff = startFFmpeg(); // great! ffmpeg has started, now immediately move to next part of code
   if(ff)
   {
       // execute code in this block simultaneously?
       // i.e. do not wait till ffmpeg closes
   }
   else
   {
      // error handling
   }

  return 0;
}

一些元数据

操作系统: Windows 7
语言: C
IDE: Dev C ++

更新

我尝试使用CreateProcess()。现在的问题是ffmpeg.exe列在任务栏中,但框架没有被提取。

char cmd[100] = "D:\\ffmpeg\\bin\\ffmpeg.exe -i D:\\video.mpg -r 10 D:\\frames\\%d.jpg";
PROCESS_INFORMATION pi;
STARTUPINFO si;
CreateProcess(cmd, "", 0, 0, 0, 0, 0, 0, &si, &pi);

1 个答案:

答案 0 :(得分:2)

我找到了解决方案。我对CreateProcees()使用了错误的论点。以下代码解决了它。

CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);