1

I'm trying to use ffmpeg to do some operations for me. It's really simple for now. I want to omit the ffmpeg output in my console, either redirecting them to strings or a .txt file that I can control. I'm on Windows 10.

I have tried _popen (with and "r" and "w") and system("ffmpeg command > output.txt")', with no success.

#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;
}

Further in the development, I would like to know when the ffmpeg process finished (maybe I can monitor the ffmpeg return value?) or to display only the last line if the some error occurred.

EylM
  • 5,967
  • 2
  • 16
  • 28
NeoFahrenheit
  • 347
  • 5
  • 16
  • ffmpeg takes the output file as an argument. No redirection is needed – stark Jul 20 '19 at 22:28
  • According to the docs of `_popen`, you should use open mode "r", which enables you to read the output of the spawned process. What are the exact errors you get? Check the value of `errno` immediately after failed function call. – zett42 Jul 20 '19 at 22:31
  • To capture the error you need to capture `stderr`, which `_popen` cannot do. See [here](https://stackoverflow.com/questions/191842/how-do-i-get-console-output-in-c-with-a-windows-program) for a Windows solution. – rustyx Jul 20 '19 at 22:37
  • Thanks @stark for the tip, I'll try it. zett42, I don't get any errors, just the output appearing on my console. I've tried with "r" and "w". rustyx hmm, Ok. Thanks. :) – NeoFahrenheit Jul 20 '19 at 22:48
  • If you use `CreateProcess` with no console window switch instead of _popen, you can redirect both stdoutput and stderr to a pipe which can be parsed. – seccpur Jul 21 '19 at 00:11

1 Answers1

0

I have made it to work. In the solution 1, I added " 2>&1" to the end of the string.

Found it here: ffmpeg command line write output to a text file output-to-a-text-file

Thanks!

NeoFahrenheit
  • 347
  • 5
  • 16