[英]Redirect ffmpeg console output to a string or a file in C++
我正在嘗試使用ffmpeg為我做一些操作。 現在真的很簡單。 我想在控制台中忽略ffmpeg輸出,將它們重定向到我可以控制的字符串或.txt文件。 我在Windows 10上。
我嘗試了_popen(以及和“ r”和“ w”)和系統(“ ffmpeg命令> 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返回值?),或者如果發生某些錯誤,則僅顯示最后一行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.