Nominate our 2022 Qt Champions!

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.


  • @Stuhalsky-Alex

    Hello, I've stumbled upon your topic after running into the same issue. I'd like to dispaly and record a stream from a camera on the network. But, while I can display effortlessly the stream with a MediaPlayer widget, QMediaRecorder does not appear to support the recording of the stream from QMediaPlayer even though it implements QMediaContent.

    Did you ever find a way to make it work? Or have you used a workaround?

    Thanks,
    Alex.



  • @AlexRNL Hi.
    I haven't found a solution and skipped this task. I will turn back to it later, but not soon i guess :)


  • Lifetime Qt Champion

    Hi,

    Did you check with Qt 6.2 ?



  • @SGaist Hi.
    No i haven't. I can't switch to Qt6 for now so i didn't try that option.


  • Lifetime Qt Champion

    You can try to cheat by using a custom GStreamer pipeline that does both.



  • @Stuhalsky-Alex I can't switch to Qt 6 yet, I'm stuck with 5.12

    I have alternatives ways to record the stream, but using a QMediaRecorder seemed easy enough to set-up and as it is well-integrated into Qt it made everything easier.

    I'll try to have a look at GStreamer to see if it can workaround this issue.

    Thanks for your answer anyway :)


Log in to reply