Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Getting ffmpeg output with QProccess



  • I have this code in QT:

    #include <QCoreApplication>
    #include <QProcess>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QProcess p;
        QString ba;
        QString exec = "ffmpeg.exe";
        QStringList params;
        params << " -i S01E01.mp4 2>&1";
        p.start(exec, params);
        p.waitForFinished(); // sets current thread to sleep and waits for p end
        QString output(p.readAllStandardOutput());
        qDebug()<<output;
        return a.exec();
    }
    

    When I ran the command directly I get this:
    ffmpeg.exe -i S01E01.mp4 2>&1
    ffmpeg version git-2020-04-24-a501947 Copyright (c) 2000-2020 the FFmpeg developers
    built with gcc 9.3.1 (GCC) 20200328
    configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
    libavutil 56. 42.102 / 56. 42.102
    libavcodec 58. 81.100 / 58. 81.100
    libavformat 58. 42.101 / 58. 42.101
    libavdevice 58. 9.103 / 58. 9.103
    libavfilter 7. 79.100 / 7. 79.100
    libswscale 5. 6.101 / 5. 6.101
    libswresample 3. 6.100 / 3. 6.100
    libpostproc 55. 6.100 / 55. 6.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'S01E01.mp4':
    Metadata:
    major_brand : mp42
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    creation_time : 2017-01-01T15:13:24.000000Z
    title : The Simpsons S01E01 Simpsons Roasting on an Open Fire
    encoder : HandBrake 0.10.5 2016021100
    Duration: 00:23:12.98, start: 0.000000, bitrate: 247 kb/s
    Chapter #0:0: start 0.000000, end 18.282000
    Metadata:
    title : Chapter 1
    Chapter #0:1: start 18.282000, end 334.488000
    Metadata:
    title : Chapter 2
    Chapter #0:2: start 334.488000, end 584.364000
    Metadata:
    title : Chapter 3
    Chapter #0:3: start 584.364000, end 831.534000
    Metadata:
    title : Chapter 4
    Chapter #0:4: start 831.534000, end 1314.951000
    Metadata:
    title : Chapter 5
    Chapter #0:5: start 1314.951000, end 1392.930000
    Metadata:
    title : Chapter 6
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 480x360, 191 kb/s, 30.30 fps, 30.30 tbr, 90k tbn, 60.61 tbc (default)
    Metadata:
    creation_time : 2017-01-01T15:13:24.000000Z
    handler_name : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 49 kb/s (default)
    Metadata:
    creation_time : 2017-01-01T15:13:24.000000Z
    handler_name : Mono
    Stream #0:2(eng): Data: bin_data (text / 0x74786574)
    Metadata:
    creation_time : 2017-01-01T15:13:24.000000Z
    handler_name : SubtitleHandler
    At least one output file must be specified

    But when I run it using the code mentioned before, I get "". What I am doing wrong?


  • Lifetime Qt Champion

    params << "-i" << "S01E01.mp4"

    In any case, "2>&1" is command prompt specific, so it does not make sense to put it there and might even interfere.


  • Lifetime Qt Champion

    Hi,

    Remove the channel handling at the end of the command.
    Also the proper way to pass parameters is to build a QStringList with each element separately.



  • @SGaist

    params << " -i"<<" S01E01.mp4";
    

    Still nothing


  • Lifetime Qt Champion

    Is that video file located in the same folder as the executable ?
    You should also check whether the command failed and its standard erreur channel.



  • @SGaist

    Is that video file located in the same folder as the executable ?
    

    Yes, it is like this
    bea25094-c0a0-43dc-9ce1-b5c9bb04b6e2-image.png

    You should also check whether the command failed and its standard erreur channel.
    
    

    How?


  • Lifetime Qt Champion



  • @SGaist How to correctly use readStandartError? Print in qDebug?



  • @rktech exitStatus: QProcess::NormalExit, exitCode: 1


  • Lifetime Qt Champion

    @rktech said in Getting ffmpeg output with QProccess:

    @SGaist How to correctly use readStandartError? Print in qDebug?

    That's one way yes.



  • @rktech readStandartError
    ffmpeg version git-2020-04-24-a501947 Copyright (c) 2000-2020 the FFmpeg developers\r\n built with gcc 9.3.1 (GCC) 20200328\r\n configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\r\n libavutil 56. 42.102 / 56. 42.102\r\n libavcodec 58. 81.100 / 58. 81.100\r\n libavformat 58. 42.101 / 58. 42.101\r\n libavdevice 58. 9.103 / 58. 9.103\r\n libavfilter 7. 79.100 / 7. 79.100\r\n libswscale 5. 6.101 / 5. 6.101\r\n libswresample 3. 6.100 / 3. 6.100\r\n libpostproc 55. 6.100 / 55. 6.100\r\n[NULL @ 0000024fd452b800] Unable to find a suitable output format for ' -i'\r\n -i: Invalid argument\r\n

    I would drop error, but same as in my first post.



  • @rktech That was caused by splitting parametrs into list, but the problem with wrong error continues:
    "ffmpeg version git-2020-04-24-a501947 Copyright (c) 2000-2020 the FFmpeg developers\r\n built with gcc 9.3.1 (GCC) 20200328\r\n configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\r\n libavutil 56. 42.102 / 56. 42.102\r\n libavcodec 58. 81.100 / 58. 81.100\r\n libavformat 58. 42.101 / 58. 42.101\r\n libavdevice 58. 9.103 / 58. 9.103\r\n libavfilter 7. 79.100 / 7. 79.100\r\n libswscale 5. 6.101 / 5. 6.101\r\n libswresample 3. 6.100 / 3. 6.100\r\n libpostproc 55. 6.100 / 55. 6.100\r\nOutput #0, mp4, to ' -i S01E01.mp4':\r\nOutput file #0 does not contain any stream\r\n"


  • Lifetime Qt Champion

    Try removing the spaces in the parameter list.



  • Done like this:

    params << "-i S01E01.mp4 2>&1";
    

    Getting this error:
    "ffmpeg version git-2020-04-24-a501947 Copyright (c) 2000-2020 the FFmpeg developers\r\n built with gcc 9.3.1 (GCC) 20200328\r\n configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\r\n libavutil 56. 42.102 / 56. 42.102\r\n libavcodec 58. 81.100 / 58. 81.100\r\n libavformat 58. 42.101 / 58. 42.101\r\n libavdevice 58. 9.103 / 58. 9.103\r\n libavfilter 7. 79.100 / 7. 79.100\r\n libswscale 5. 6.101 / 5. 6.101\r\n libswresample 3. 6.100 / 3. 6.100\r\n libpostproc 55. 6.100 / 55. 6.100\r\nUnrecognized option 'i S01E01.mp4 2>&1'.\r\nError splitting the argument list: Option not found\r\n"



  • The

    2>&1
    

    Is not the problem, it drops same error without it.


  • Lifetime Qt Champion

    params << "-i" << "S01E01.mp4"

    In any case, "2>&1" is command prompt specific, so it does not make sense to put it there and might even interfere.



  • @SGaist Thanks, now it works


Log in to reply