Grab keyframe image data from h264 stream?

We are looking at some h264 coming from an RTSP stream. Membrane is doing a fine job with the HLS demo turning it into HLS. But we want to grab images for processing and such. I didn't find anything conclusive on how to do this. I remember being able to do something with keyframes and images but can't find it.
16 Replies
lawik
lawikOP•10mo ago
Hah! essentially I want the thing you do in the iOS blog post from way back but as an example 😄
mat_hek
mat_hek•10mo ago
Hi @lawik , if you decode an H264 stream you get a series of YUV pictures. I worked with the author of Elixir Image on using the library to manipulate them and the most straightforward way requires converting YUV to RGB. The guy did that, but it's quite slow, see https://github.com/elixir-image/image/discussions/121. Since my use case was specifically about applying an image overlay, I managed to do that without converting to RGB, see https://github.com/membraneframework/membrane_overlay_plugin (merged today)
GitHub
GitHub - membraneframework/membrane_overlay_plugin: Filter for appl...
Filter for applying overlay image or text on top of video - membraneframework/membrane_overlay_plugin
mat_hek
mat_hek•10mo ago
Regarding key frames, instead of decoding the whole stream you can throw away all frames that are not key frames and decode only the key frames, for example if you want thumbnails, that's going to save a lot of CPU compared to decoding the whole stream and then choosing frames for thumbnails.
lawik
lawikOP•10mo ago
YUV is fine, I want to feed it into a model. I can change color spaces and stuff if I need to.. I can't find a scissors plugin example for keyframes only.. cocoa's evision can use opencv to give you yuv to rgb I think Anyway, I have a tee working, I want to filter to only keep keyframes, then decode and turbojpeg them or something
mat_hek
mat_hek•10mo ago
Ah yeah, this plugin doesn't have the best API :/ When I needed to have key frames last time I wrote a simple filter. It's enough to check for buffer.metadata.h264.key_frame? and only send these buffers
lawik
lawikOP•10mo ago
gotcha
mat_hek
mat_hek•10mo ago
cocoa's evision can use opencv to give you yuv to rgb I think
that's possible, I didn't want to include whole evision for that purpose
lawik
lawikOP•10mo ago
Hmm, getting errors due to some bad stuff going into the ffmpeg decoder..
lawik
lawikOP•10mo ago
Elixir Programming Language Forum
Membrane RTSP source
@mat-hek I’ve successfully wired up my first pipeline. It seems like it almost works, but i’ve ran into an issue. My stream only supports interleaving, however the membrane-element-rtp-h264 element does not support interleaving. There is only one channel, so i tried to hack it together but just filtering out the interleaving packets with someth...
mat_hek
mat_hek•10mo ago
The problem there was that SPS and PPS were not in the stream
mat_hek
mat_hek•10mo ago
GitHub
membrane_demo/rtsp_to_hls/lib/pipeline.ex at master · membraneframe...
Examples of using the Membrane Framework. Contribute to membraneframework/membrane_demo development by creating an account on GitHub.
lawik
lawikOP•10mo ago
I wonder if the camera was giving us rtsp 2 or something.. will look at that though Hah, Nope those cameras don't send that
lawik
lawikOP•10mo ago
Stack Overflow
Identify if an RTSP Stream contains PPS and SPS information
I am ingesting different kinds of security camera RTSP streams with gstreamer. In most of the cases I use a pipeline similar to this gst-launch-1.0 rtspsrc location=rtsp://<username:password@$RT...
lawik
lawikOP•10mo ago
I might have a chance to contrib that. We will see I won't have access to the device for a bit. Curious if we could detect that failure and just make it clear what the problem is, or solve it for the dev
mat_hek
mat_hek•10mo ago
We plan to create an RTSP source bin that would be passed an URL and did everything for you, no time for that yet though :/ contributions very welcome as always 😉
lawik
lawikOP•10mo ago
Yeah, that'd be nice
Want results from more Discord servers?
Add your server