Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5 QMediaRecorder: does not support any codec or container
Forum Updated to NodeBB v4.3 + New Features

Qt5 QMediaRecorder: does not support any codec or container

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 483 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Davide87
    wrote on last edited by Davide87
    #1

    Hello everybody.
    I'm trying to acquire a rtsp video stream from a remote IP camera and record it on a file.
    I can successfully display the video stream using the QMediaPlayer and QVideoWidget classes. No problem in that.
    Now, I need to record the video stream on a file. Doesn't really matter which video format (I will need a compressed format, though).
    To do this I'm tryiing the QMediaRecorder class, but it seems I can't make it work.
    The code I'm using is as follows:

    mainwindow.h

    ...
    #include <QMediaRecorder>
    ...
    QMediaRecorder *recorder;
    ...
    

    mainwindow.cpp

    recorder = new QMediaRecorder(player,this);
    
    connect(recorder, QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
        [=](QMediaRecorder::Error error){qDebug() << "Recorder error: " << error;});
    
    qDebug() << "recorder->supportedVideoCodecs()" << recorder->supportedVideoCodecs();
    qDebug() << "recorder->supportedAudioCodecs()" << recorder->supportedAudioCodecs();
    qDebug() << "recorder->supportedContainers() " << recorder->supportedContainers();
    qDebug() << "recorder->supportedFrameRates() " << recorder->supportedFrameRates();
    qDebug() << "recorder->supportedResolutions()" << recorder->supportedResolutions();
    
    QVideoEncoderSettings settings = recorder->videoSettings();
    
    settings.setBitRate(4096);
    settings.setCodec("video/mpeg4");
    settings.setResolution(640, 480);
    settings.setEncodingMode(QMultimedia::ConstantQualityEncoding);
    settings.setQuality(QMultimedia::HighQuality);
    
    recorder->setVideoSettings(settings);
    
    qDebug() << " ";
    qDebug() << "recorder->setVideoSettings(settings);";
    
    qDebug() << "   encodingMode" << settings.encodingMode() << recorder->videoSettings().encodingMode();
    qDebug() << "   codec       " << settings.codec() << recorder->videoSettings().codec();
    qDebug() << "   bitRate     " << settings.bitRate() << recorder->videoSettings().bitRate();
    qDebug() << "   frameRate   " << settings.frameRate() << recorder->videoSettings().frameRate();
    qDebug() << "   resolution  " << settings.resolution() << recorder->videoSettings().resolution();
    qDebug() << "   quality     " << settings.quality() << recorder->videoSettings().quality();
    

    Then the result I have on the QtCreator's console as the software is run is as follows:

    recorder->supportedVideoCodecs() ()
    recorder->supportedAudioCodecs() ()
    recorder->supportedContainers()  ()
    recorder->supportedFrameRates()  ()
    recorder->supportedResolutions() ()
     
    recorder->setVideoSettings(settings);
       encodingMode 0 0
       codec        "video/mpeg4" ""
       bitRate      4096 -1
       frameRate    0 0
       resolution   QSize(640, 480) QSize(-1, -1)
       quality      3 2
    

    Same happens if I use settings.setCodec("video/avi"); or settings.setCodec("H.264"); (even though I know that the problem is probably not on the video codec choice at this point).
    It seems that the QMediaRecorder object does not support anything at all as it is created. No video/audio codec, no container (I don't even know what a "container" is), no resolution and no frame rate.
    The same happens on both Windows 10, Windows 11 and Ubuntu 22.04.1 LTS.
    I'm using Qt 5.15.2.

    Has anyone had this kind of problem before. Does anyone have any idea on how I can try to solve it?

    JoeCFDJ 1 Reply Last reply
    0
    • D Davide87

      Hello everybody.
      I'm trying to acquire a rtsp video stream from a remote IP camera and record it on a file.
      I can successfully display the video stream using the QMediaPlayer and QVideoWidget classes. No problem in that.
      Now, I need to record the video stream on a file. Doesn't really matter which video format (I will need a compressed format, though).
      To do this I'm tryiing the QMediaRecorder class, but it seems I can't make it work.
      The code I'm using is as follows:

      mainwindow.h

      ...
      #include <QMediaRecorder>
      ...
      QMediaRecorder *recorder;
      ...
      

      mainwindow.cpp

      recorder = new QMediaRecorder(player,this);
      
      connect(recorder, QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
          [=](QMediaRecorder::Error error){qDebug() << "Recorder error: " << error;});
      
      qDebug() << "recorder->supportedVideoCodecs()" << recorder->supportedVideoCodecs();
      qDebug() << "recorder->supportedAudioCodecs()" << recorder->supportedAudioCodecs();
      qDebug() << "recorder->supportedContainers() " << recorder->supportedContainers();
      qDebug() << "recorder->supportedFrameRates() " << recorder->supportedFrameRates();
      qDebug() << "recorder->supportedResolutions()" << recorder->supportedResolutions();
      
      QVideoEncoderSettings settings = recorder->videoSettings();
      
      settings.setBitRate(4096);
      settings.setCodec("video/mpeg4");
      settings.setResolution(640, 480);
      settings.setEncodingMode(QMultimedia::ConstantQualityEncoding);
      settings.setQuality(QMultimedia::HighQuality);
      
      recorder->setVideoSettings(settings);
      
      qDebug() << " ";
      qDebug() << "recorder->setVideoSettings(settings);";
      
      qDebug() << "   encodingMode" << settings.encodingMode() << recorder->videoSettings().encodingMode();
      qDebug() << "   codec       " << settings.codec() << recorder->videoSettings().codec();
      qDebug() << "   bitRate     " << settings.bitRate() << recorder->videoSettings().bitRate();
      qDebug() << "   frameRate   " << settings.frameRate() << recorder->videoSettings().frameRate();
      qDebug() << "   resolution  " << settings.resolution() << recorder->videoSettings().resolution();
      qDebug() << "   quality     " << settings.quality() << recorder->videoSettings().quality();
      

      Then the result I have on the QtCreator's console as the software is run is as follows:

      recorder->supportedVideoCodecs() ()
      recorder->supportedAudioCodecs() ()
      recorder->supportedContainers()  ()
      recorder->supportedFrameRates()  ()
      recorder->supportedResolutions() ()
       
      recorder->setVideoSettings(settings);
         encodingMode 0 0
         codec        "video/mpeg4" ""
         bitRate      4096 -1
         frameRate    0 0
         resolution   QSize(640, 480) QSize(-1, -1)
         quality      3 2
      

      Same happens if I use settings.setCodec("video/avi"); or settings.setCodec("H.264"); (even though I know that the problem is probably not on the video codec choice at this point).
      It seems that the QMediaRecorder object does not support anything at all as it is created. No video/audio codec, no container (I don't even know what a "container" is), no resolution and no frame rate.
      The same happens on both Windows 10, Windows 11 and Ubuntu 22.04.1 LTS.
      I'm using Qt 5.15.2.

      Has anyone had this kind of problem before. Does anyone have any idea on how I can try to solve it?

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @Davide87 I think Qt 5 uses gstreamer on Ubuntu. Codec is in the plugins of gstreamer. Did you install gstreamer?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Davide87
        wrote on last edited by Davide87
        #3

        Hello Joe.
        Yes, I did. I installed it by writing

        sudo apt-get install gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly
        sudo apt-get install libgstreamer1.0-dev
        

        in the Linux console.
        I'm using a virtual machine throuhg Oracle VM Virtualbox in a Windows system.

        Right now I'm trying to use Qt6 (never used it before), but with this one I'm having a lot of trouble with the rtsp video stream.

        edit:

        With Qt 6.7 I obtained that:

        • recorder->mediaFormat().supportedFileFormats(QMediaFormat::Encode) returns QList(QMediaFormat::MPEG4, QMediaFormat::Matroska, QMediaFormat::WMV, QMediaFormat::AVI, QMediaFormat::QuickTime)
        • recorder->mediaFormat().supportedFileFormats(QMediaFormat::Decode) returns QList(QMediaFormat::MPEG4, QMediaFormat::Matroska, QMediaFormat::WMV, QMediaFormat::AVI, QMediaFormat::QuickTime)
        • recorder->mediaFormat().supportedVideoCodecs(QMediaFormat::Encode) returns QList(QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::MPEG2)
        • recorder->mediaFormat().supportedVideoCodecs(QMediaFormat::Decode) returns QList(QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::MPEG2)

        However, with Qt6 I got other problems

        1. Cannot stream from a IP Camera with the rtsp protocol
        2. How do I record from a QMediaPlayer with QMediaRecorder (it seems I can only record from a QCamera object)?
        JoeCFDJ 1 Reply Last reply
        0
        • D Davide87

          Hello Joe.
          Yes, I did. I installed it by writing

          sudo apt-get install gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly
          sudo apt-get install libgstreamer1.0-dev
          

          in the Linux console.
          I'm using a virtual machine throuhg Oracle VM Virtualbox in a Windows system.

          Right now I'm trying to use Qt6 (never used it before), but with this one I'm having a lot of trouble with the rtsp video stream.

          edit:

          With Qt 6.7 I obtained that:

          • recorder->mediaFormat().supportedFileFormats(QMediaFormat::Encode) returns QList(QMediaFormat::MPEG4, QMediaFormat::Matroska, QMediaFormat::WMV, QMediaFormat::AVI, QMediaFormat::QuickTime)
          • recorder->mediaFormat().supportedFileFormats(QMediaFormat::Decode) returns QList(QMediaFormat::MPEG4, QMediaFormat::Matroska, QMediaFormat::WMV, QMediaFormat::AVI, QMediaFormat::QuickTime)
          • recorder->mediaFormat().supportedVideoCodecs(QMediaFormat::Encode) returns QList(QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::MPEG2)
          • recorder->mediaFormat().supportedVideoCodecs(QMediaFormat::Decode) returns QList(QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::MPEG2)

          However, with Qt6 I got other problems

          1. Cannot stream from a IP Camera with the rtsp protocol
          2. How do I record from a QMediaPlayer with QMediaRecorder (it seems I can only record from a QCamera object)?
          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @Davide87 qt6 uses FFmpeg as default backend.

          D 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @Davide87 qt6 uses FFmpeg as default backend.

            D Offline
            D Offline
            Davide87
            wrote on last edited by Davide87
            #5

            @JoeCFD Yes, I figured that out.
            I tried to set the environment variable QT_MEDIA_BACKEND to gstreamer and managed to have a glimpse of video stream in Qt 6.
            However I had a lot of lost packets, lantency issues and network errors (that I don't have in Qt 5).
            Another problem of Qt 6 is that I need a QCamera object to be able to record thorugh QMediaCaptureSession and QMediaRecorder and I don't know how to set a QCamera with a remote IP camera.
            So I decided to go back to Qt 5 (where I can at least successfully see the video stream).
            For now I'm trying to record the video stream via a QProcess that executes the Linux command

            ffmpeg -rtsp_transport tcp -i rtsp://<user>:<password>@<IP>:<port> -acodec copy -vcodec mpeg4 videotest.mp4
            

            It seems that it works this way, but it's only going to work on Linux machines.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved