mpegtsmux: error: Could not create handler for stream
I have python app which is dynamically linking video (H264) from an udpsrc
(RTP) and audio from a local alsasrc
(converted to AAC) to mpegtsmux
.
Depending on the order/timing of the linking I'm getting this error message:
basetsmux gstbasetsmux.c:811:gst_base_ts_mux_create_pad_stream:<mpegtsmux2> error: Could not create handler for stream
I have tried asking both on the mailing list and IRC does this error means and what causes it, but nobody has been able to answer me so far...
A simpler gst-launch-1.0 representation of the pipeline works fine:
gst-launch-1.0 udpsrc address=224.1.1.1 port=5000 multicast-iface=eth1 ! application/x-rtp,media=video,payload=33,clock-rate=90000,encoding-name=MP2T ! rtpbin ! queue ! decodebin caps="video/x-h264" ! h264parse ! "video/x-h264,stream-format=byte-stream,alignment=au" ! tee name=t ! queue ! "video/x-h264,stream-format=byte-stream,alignment=au" ! multiqueue name=mq ! mpegtsmux name=mux ! rtpmp2tpay ! fakesink audiotestsrc ! "audio/x-raw,format=S32LE,layout=interleaved,rate=44100,channels=2,channel-mask=(bitmask)0x3" ! mq. mq. ! audioconvert ! avenc_aac ! mux. -v --gst-debug=*:3
So it must be a matter of order/timing
Raising the debug level to *tsmux:5
or even *tsmux:7
doesn't give all that much more clarity:
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168211501 75594 0x564857e0f8f0 DEBUG basetsmux gstbasetsmux.c:1676:gst_base_ts_mux_find_best_pad:<mpegtsmux_cam1> Best pad found with 0:00:00.023219954: <mpegtsmux_cam1:sink_1>
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168320898 75594 0x564857e0f8f0 DEBUG basetsmux gstbasetsmux.c:1094:gst_base_ts_mux_aggregate_buffer:<mpegtsmux_cam1> Pads collected
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168373356 75594 0x564857e0f8f0 DEBUG basetsmux gstbasetsmux.c:403:gst_base_ts_mux_create_stream:<mpegtsmux_cam1:sink_0> Creating stream with PID 0x0041 for caps video/x-h264, stream-format=(string)byte-stream, width=(int)1920, height=(int)1080, framerate=(fraction)0/1, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true, alignment=(string)au, profile=(string)high, level=(string)4
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168416277 75594 0x564857e0f8f0 DEBUG basetsmux gstbasetsmux.c:780:gst_base_ts_mux_create_pad_stream:<mpegtsmux_cam1:sink_0> Use stream (pid=65) from pad as PCR for program (prog_id = 0)
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168447309 75594 0x564857e0f8f0 DEBUG basetsmux gstbasetsmux.c:403:gst_base_ts_mux_create_stream:<mpegtsmux_cam1:sink_1> Creating stream with PID 0x0041 for caps audio/mpeg, mpegversion=(int)4, channels=(int)2, rate=(int)44100, stream-format=(string)raw, framed=(boolean)true, level=(string)2, base-profile=(string)lc, profile=(string)lc, codec_data=(buffer)1210
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168469731 75594 0x564857e0f8f0 DEBUG basetsmux gstbasetsmux.c:470:gst_base_ts_mux_create_stream:<mpegtsmux_cam1:sink_1> we have additional codec data (2 bytes)
Oct 27 08:53:24 qt5122-msb qtec-mediamixer[75594]: 0:00:01.168483311 75594 0x564857e0f8f0 WARN basetsmux gstbasetsmux.c:811:gst_base_ts_mux_create_pad_stream:<mpegtsmux_cam1> error: Could not create handler for stream
And looking at the source I seem to be getting here:
if (ts_pad->stream == NULL) {
ret = gst_base_ts_mux_create_stream (mux, ts_pad);
if (ret != GST_FLOW_OK)
goto no_stream;
}
no_stream:
{
GST_ELEMENT_ERROR (mux, STREAM, MUX,
("Could not create handler for stream"), (NULL));
return ret;
}
if (st != TSMUX_ST_RESERVED) {
ts_pad->stream = tsmux_create_stream (mux->tsmux, st, ts_pad->pid,
ts_pad->language);
} else {
GST_DEBUG_OBJECT (pad, "Failed to determine stream type");
}
if (ts_pad->stream != NULL) {
My best guess:
/* Ensure we're not creating a PID collision */
if (tsmux_find_stream (mux, new_pid))
return NULL;
Finally if I compare with the output of the working gst-launch:
0:00:00.306454146 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:403:gst_base_ts_mux_create_stream:<mux:sink_0> Creating stream with PID 0x0041 for caps video/x-h264, stream-format=(string)byte-stream, width=(int)1920, height=(int)1080, framerate=(fraction)0/1, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true, alignment=(string)au, profile=(string)high, level=(string)4
0:00:00.306529032 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:780:gst_base_ts_mux_create_pad_stream:<mux:sink_0> Use stream (pid=65) from pad as PCR for program (prog_id = 0)
0:00:00.306580500 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:403:gst_base_ts_mux_create_stream:<mux:sink_1> Creating stream with PID 0x0042 for caps audio/mpeg, channels=(int)2, rate=(int)44100, mpegversion=(int)4, base-profile=(string)lc, framed=(boolean)true, stream-format=(string)raw, channel-mask=(bitmask)0x0000000000000003, level=(string)2, profile=(string)lc, codec_data=(buffer)121056e500
0:00:00.306609142 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:470:gst_base_ts_mux_create_stream:<mux:sink_1> we have additional codec data (5 bytes)
0:00:00.306659206 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmuxaac.c:106:gst_base_ts_mux_prepare_aac_adts:<mux> Preparing AAC buffer for output
0:00:00.306679775 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmuxaac.c:111:gst_base_ts_mux_prepare_aac_adts:<mux> Rate index 4, channels 2, object type/profile 2
0:00:00.306703159 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:1187:gst_base_ts_mux_aggregate_buffer:<mux:sink_1> Chose stream for output (PID: 0x0042)
0:00:00.306724715 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:1201:gst_base_ts_mux_aggregate_buffer:<mux> Buffer has PTS 0:00:00.000000000 pts 0
0:00:00.306745826 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:1207:gst_base_ts_mux_aggregate_buffer:<mux> Buffer has DTS +0:00:00.000000000 dts 0
0:00:00.306760796 77005 0x5610ab7be370 DEBUG basetsmux gstbasetsmux.c:1229:gst_base_ts_mux_aggregate_buffer:<mux> delta: 1
Here it can be seen that the difference is that the audio and video streams both have their own PIDs (0x41 and 0x42) while when I get the error they both got the same PID (0x41)
And that is what must be triggering this:
/* Ensure we're not creating a PID collision */
if (tsmux_find_stream (mux, new_pid))
return NULL;
Is this expected behavior or a bug / race condition?
If this is expected is it at least possible to add more debug information (pad name, ...) that can give a better indication of what is wrong? Fx, add an WARNING about PID collision?
And in that case what should I do to avoid collisions?