c++ - 将 ffmpeg 控制台输出重定向到 C++ 中的字符串或文件

标签 c++ windows ffmpeg output popen

我正在尝试使用 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 返回值?)或者如果发生某些错误则只显示最后一行。

最佳答案

我成功了。 在解决方案1中,我在字符串的末尾添加了“2>&1”。

在这里找到:ffmpeg command line write output to a text file 输出到文本文件

谢谢!

关于c++ - 将 ffmpeg 控制台输出重定向到 C++ 中的字符串或文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57128993/

相关文章:

java - 识别文件中的音频样本

shell - 使用 ffmpeg 提取特定帧的列表

c# - 所有音频频率

c++ - std::find 使用用户定义的结构

c++ - 同时迭代两个或多个容器的最佳方法是什么

ffmpeg - 为什么带有 libfdk_aac 编码的 ffmpeg 会在音频文件的开头减少 25 毫秒?

python - 可以用 python 捕获 ffmpeg 错误吗?

c - 将 C 代码从一个操作系统移植到另一个操作系统时处理静态库

windows - 为什么 Windows Server 2019 和 Azure 之间的站点到站点 VPN 连接突然无法路由?

windows - 如何在 Windows 下的 cmd 窗口中显示日文汉字?