我正在尝试使用 ffmpeg 为我做一些操作。现在真的很简单。我想在我的控制台中省略 ffmpeg 输出,将它们重定向到字符串或我可以控制的 .txt 文件。我在 Windows 10 上。
我已经尝试过 _popen(with and "r"and "w")和 system("ffmpeg command > output.txt")',但没有成功。
#include <iostream>
#include <stdio.h>
using namespace std;
#define BUFSIZE 256
int main()
{
/* 1.
x = system("ffmpeg -i video.mp4 -i audio.mp4 -c copy output.mp4 > output.txt");
*/
/* 2.
FILE* p;
p = _popen("ffmpeg -i video.mp4 -i audio.mp4 -c copy output.mp4", "w");
_pclose(p);
*/
/* 3.
char cmd[200] = { "ffmpeg -i video.mp4 -i audio.mp4 -c copy output.mp4" };
char buf[BUFSIZE];
FILE* fp;
if ((fp = _popen(cmd, "r")) == NULL) {
printf("Error opening pipe!\n");
return -1;
}
while (fgets(buf, BUFSIZE, fp) != NULL) {
// Do whatever you want here...
// printf("OUTPUT: %s", buf);
}
if (_pclose(fp)) {
printf("Command not found or exited with error status\n");
return -1;
}
*/
return 0;
}
在进一步的开发中,我想知道 ffmpeg 进程何时完成(也许我可以监视 ffmpeg 返回值?)或者如果发生某些错误则只显示最后一行。
最佳答案
关于c++ - 将 ffmpeg 控制台输出重定向到 C++ 中的字符串或文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57128993/