簡體   English   中英

將ffmpeg控制台輸出重定向到C ++中的字符串或文件

[英]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返回值?),或者如果發生某些錯誤,則僅顯示最后一行。

我已經做到了。 在解決方案1中,我在字符串的末尾添加了“ 2>&1”。

在這里找到它: ffmpeg命令行將輸出寫入文本文件 output-to-a-text-file

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM