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

How to record and play RTSP stream from ip camera



  • I have an ip camera that allows me to see live stream over some url: rtsp://192.168...
    I want to display that stream and at the same time record it to local file.

    The main question is how to do it?

    I implemented stream display via QVideoWidget and QMediaPlayer.
    As i can see over qt docs QMediaRecorder is used to record and store video as shown in example. QMediaRecorder uses a QMediaContent* as a source and QMediaPlayer inherits QMediaContent.

    So may be it is possible to record video from QMediaPlayer?

    I can't find any example of how it can be done except this one. I tried it. It compiles and runs, but it doesn't work. May be i miss something?

    Or from the other hand may be it is possible to create a QCamera instance that is connected to my rtsp url?

    I'm using Qt 5.12.8. OS Kubuntu 20.04

    Thanks in advance.


  • Lifetime Qt Champion

    @Stuhalsky-Alex said in How to record and play RTSP stream from ip camera:

    but it doesn't work

    Did you try to find out what exactly does not work? Is the recorded file created? Does it contain anything?...



  • What platform?
    AFAIK Qt doesn't support rtsp urls on Windows.
    I don't think it is possible to create a QCamera connected to some live stream url.
    But QMediaRecorder accepts all QMediaObject classes, not only QCamera, so it may be possible to record if Qt can play the url.



  • Hi @jsulm. Yes, i tried.

    In the first case i created file for writing manually and made sure it can be opened. The files were indeed created, but 0 bytes were written. I checked QMediaRecorder state. It have not been changed at all. Corresponding singnal was not emitting. Actual location was invalid and output location was empty string.

    In the second case i tried simply to set output location in QMediaRecorder instance, but file was not created at all. Actual location was invalid, but output location contained correct QUrl path to local file.

    I may miss something, because i tried many solutions during last couple of days. I can reimplement any solution that is supposed to work and check what happens.


  • Lifetime Qt Champion

    @Stuhalsky-Alex Can you play the stream in your Qt app?



  • Hi @Bonnie

    • "What platform?"
      Kubuntu 20.04.
      Forgot to mention it in the topic. I will add it there too.

    • "I don't think it is possible to create a QCamera connected to some live stream url."
      Ok. Minus one option.

    • "But QMediaRecorder accepts all QMediaObject classes, not only QCamera, so it may be possible to record if Qt can play the url."
      Well. I will try again. May be i missed some minor mistake that breaks everything.



  • @jsulm

    • "Can you play the stream in your Qt app?"
      Yes, i can. Simply passing rtsp url as media for QMediaPlayer and setting video output into QVideoWidget.

Log in to reply