synchronize streams from 2 appsrc to hlssink

toksey tokunboq at ips-yes.com
Fri Jul 24 12:15:17 UTC 2020


I am trying to synchronize 2 live streams using the appsrc elements with this
pipeline : 

gst_parse_launch(
        "appsrc name=mkv_appsrc ! matroskademux name=demux mpegtsmux
name=hlsmux ! "
        "hlssink name=sink demux.video_0 ! queue ! decodebin ! videoconvert
! video/x-raw, format=I420 "
        " ! x264enc tune=zerolatency ! queue ! hlsmux. demux.audio_0 ! queue
! decodebin ! audioconvert "
        " ! voaacenc ! queue ! hlsmux. appsrc name=raw_appsrc ! queue !
audioconvert ! voaacenc ! queue ! "
        "hlsmux. ", &error);

I have 2 separate threads injecting live media streams into the 2 appsrc .
The first stream has MKV audio and video stream and the 2nd stream has
audio/x-raw,format=S16LE,rate=48000,channels=2,layout=interleaved. 
The streams contain metadata that allow me to align the injection to the
pipeline so that the buffers carrying the same event in time are assigned
the same timestamps before being injected into the pipeline.  The goal is
that the pipeline will mux together and create hls files with the streams
synchronized.

Each thread has this code :        
        /* Inject stream */
        buffer = gst_buffer_new_and_alloc(capture_buffer_size);
        GST_BUFFER_TIMESTAMP(buffer) = gstreamer_push_clock;
//gstreamer_push_clock is aligned on both threads
        gst_buffer_map(buffer, &map, GST_MAP_WRITE);
        memcpy(map.data, capture_buffer, capture_buffer_size);
        gst_buffer_unmap(buffer, &map);

        ret = gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer);

The problem I'm having is that the hls files produced are not always in
sync.  Sometimes the stream on the mkv_appsrc are about 1-2 secs ahead of
the stream from the raw_appsrc.
I also noticed that when I probed the buffer timestamp after the
matroskademux, the buffers don't have the same timestamps that was assigned
to the buffers from the mkv_appsrc, however the timestamps on the buffers
injected from the raw_appsrc were retained.  Since timestamp information is
lost with matroskademux, how can I obtain synchronization once the streams
go through mpegtsmux and hlssink.

Any feedback on my approach to this issue will be much appreciated.



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list