Recording and Displaying Streams Simultaneously

This forum is about all development around libVLC.
Moriquendi
Blank Cone
Blank Cone
Posts: 74
Joined: 31 May 2011 16:22

Recording and Displaying Streams Simultaneously

Postby Moriquendi » 23 Oct 2018 15:43

Hello everyone,

I have Qt application which allows users to watch a stream, and record this stream if needed.The interface looks as follows;

https://imgur.com/a/CGB8vP7

So "Open Stream Button" allows user to watch a specific stream and "Record Stream Button" displays and record the stream simultaneously. So far everything is fine. My problem is that when the user watches the stream and wants to record it, I have to stop the Vlc instance and open the media with new parameters. What I want to do is record the stream without stopping VLC media. Here's a part of my code;

TO DISPLAY STREAM:

Code: Select all

QString url = "udp://@239.255.255.10:1234"; VlcMedia media = new VlcMedia(url, instance); VlcMediaPlayer *player = new VlcMediaPlayer(instance); player->open(media);
TO DISPLAY AND RECORD STREAM:

Code: Select all

player->stop(); QString recordOption = ":sout=#duplicate{dst=display, dst=std{access=file,mux=ts,dst=save.ts}}"; libvlc_media_add_option(media->core(), recordOption.toUtf8().data()); player->open(media);
As I said, this code works just fine but everytime I start/stop recording, I have to stop and open the media as well. VLC Media Player "Record" button does this exactly how I want. If I open a media using VLC Media Player (i.e. VLC 2.2.8 ), and then press the record button. And you will see that the media is not restarted. Is there any way I can achieve this?

NOTE: I tried this creating two different VLC instances and two different player instances. But in that case, if I open a stream with one player, the other player doesnt record the stream at all. I think the reason behind it is that both players are trying to listen to the same udp port, and only one of them can access.

wrybread
Blank Cone
Blank Cone
Posts: 17
Joined: 24 Mar 2007 05:44

Re: Recording and Displaying Streams Simultaneously

Postby wrybread » 23 Oct 2018 23:14

Oops, I just posted almost exactly the same question. You posted after I read all the threads on this last night. Ha, I hope we can figure this out!

My thread:

https://forum.videolan.org/viewtopic.php?f=32&t=146794

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: Recording and Displaying Streams Simultaneously

Postby mfkl » 29 Oct 2018 03:56

Hey guys,

I tried doing this as well recently and it turns out this is not currently supported by vanilla libvlc 3. You will need to patch.

An alternative way I've been suggested is to use an additional mediaplayer in the background which only does sout (no display).
https://mfkl.github.io

Moriquendi
Blank Cone
Blank Cone
Posts: 74
Joined: 31 May 2011 16:22

Re: Recording and Displaying Streams Simultaneously

Postby Moriquendi » 30 Oct 2018 07:43

Hey guys,

I tried doing this as well recently and it turns out this is not currently supported by vanilla libvlc 3. You will need to patch.

An alternative way I've been suggested is to use an additional mediaplayer in the background which only does sout (no display).
Hey mfkl,

I already tried this with no success. I created two media player instances. 1 of them was dedicated for display and the second one was for recording the media. The problem is that since my input source is a network stream (udp://@239.255.255.10:1234), I can not listen to the same udp port with two different Vlc media players.

But, recently I tried solving this using pcap library in addition to a single VLC media player. Basically I use VLC media player to display the stream and I listen to the same port using pcap library. Let me explain it with a part of my code;

Code: Select all

void Interfaces::pcapEthernetRead() { int res=0; struct pcap_pkthdr *header; const u_char *pkt_data; U16 dataSize = 0; if(ethernetCaptureRecord != NULL) { res = pcap_next_ex( (pcap_t*)ethernetCaptureRecord, &header, &pkt_data); if(res > 0) { memcpy(&dataSize, &pkt_data[38], sizeof(dataSize)); dataSize = htons(dataSize); dataSize = dataSize - 8; qDebug() << "RECORD DATA SIZE:"<<dataSize; if(dataSize > 0) { U8 recordPayload[dataSize]; memcpy(recordPayload, &pkt_data[42], dataSize); QByteArray byteArray((const char *)recordPayload,dataSize); QTextStream recordFileDosyasi(&recordFile); recordFileStream << byteArray << endl; } } } }
This way, I can save the payload of the incoming udp packets to a file. Now my problem is the transport stream format of the recorded file. For some reason VLC doesnt like the content, but thats another issue beyond this topic.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 24 guests