Editing raw frames before output
Posted: 19 Jan 2018 16:31
Hi everyone!
I'm working on a project in which I need to capture a live video stream, apply colourful filters to the frames and then re-stream it forward all in real time. I started implementing this with OpenCV, with which i managed to capture and edit the frames easily, but I couldn't find a way to stream it further. In my research I found out about libVLC and managed to get a simple capture and re-stream working by looking at the Streaming HowTo on VideoLAN Wiki. My code looked something like this:
The problem is I can't find a way to access the frames before they are re-streamed. I tried custom callbacks for mediaPlayer to get the frames rendered to custom memory but when I changed it, it didn't seem to have any effect on the re-streamed video. From this I figured out that mediaPlayer probably ignores what I do with the rendered data and uses the original input instead, because the sout option is set for media, not mediaPlayer (am I correct?). So I created another media and mediaPlayer, and defined custom callbacks for the media, so that I can supply it with the edited frames, and it should then stream it. When I tried this, I got an error on the recieving side stating core stream error: cannot pre fill buffer. I wrote just the read callback according to documentation, because I didn't need to allocate, deallocate, or seek the stream (it will be a live stream).
With similar results, I tried doing this with imem. (I couldn't find any documentation so I used the example here.
I don't usually post on forums, because most of the times, after enough digging I can figure things out. I've been struggling with this problem for weeks, though, and I would really appreciate any help on how to solve this. Thanks!
I'm working on a project in which I need to capture a live video stream, apply colourful filters to the frames and then re-stream it forward all in real time. I started implementing this with OpenCV, with which i managed to capture and edit the frames easily, but I couldn't find a way to stream it further. In my research I found out about libVLC and managed to get a simple capture and re-stream working by looking at the Streaming HowTo on VideoLAN Wiki. My code looked something like this:
Code: Select all
libvlc_instance_t *vlc;
libvlc_media_player_t *mediaPlayer;
libvlc_media_t *media;
media = libvlc_media_new_location(vlc, "https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8");
libvlc_media_add_option(media, ":sout=#standard{mux=ts,dst=:8090,access=http}");
mediaPlayer = libvlc_media_player_new_from_media(media);
libvlc_media_player_play(mediaPlayer);
sleep(60);
libvlc_media_player_stop(mediaPlayer);
libvlc_media_release(media);
libvlc_media_player_release(mediaPlayer);
libvlc_release(libvlc);
The problem is I can't find a way to access the frames before they are re-streamed. I tried custom callbacks for mediaPlayer to get the frames rendered to custom memory but when I changed it, it didn't seem to have any effect on the re-streamed video. From this I figured out that mediaPlayer probably ignores what I do with the rendered data and uses the original input instead, because the sout option is set for media, not mediaPlayer (am I correct?). So I created another media and mediaPlayer, and defined custom callbacks for the media, so that I can supply it with the edited frames, and it should then stream it. When I tried this, I got an error on the recieving side stating core stream error: cannot pre fill buffer. I wrote just the read callback according to documentation, because I didn't need to allocate, deallocate, or seek the stream (it will be a live stream).
With similar results, I tried doing this with imem. (I couldn't find any documentation so I used the example here.
I don't usually post on forums, because most of the times, after enough digging I can figure things out. I've been struggling with this problem for weeks, though, and I would really appreciate any help on how to solve this. Thanks!