WebRTC to MKV or hlssink2 - problems with audio+video streams together

d3im deim31 at gmail.com
Wed Nov 4 11:46:31 UTC 2020


hlssink is created in function start_pipeline:
hlssink = gst_element_factory_make ("hlssink2", NULL);

/*
 * to hlssink - with pad requests*/
static void
handle_media_stream_d (GstPad * pad, GstElement * pipe, const char *type,
GstElement * hlssink)
{
  GstPad *qpad;
  GstElement *q, *q1, *conv, *resample, *sink, *enc, *parse, *fr_rate;
  GstPadLinkReturn ret;
  GstCaps *fr_caps;

  GstPad *hls_pad, *enc_pad;
  gchar *name;

  gst_print ("Trying to handle stream %s\n", type);

  q = gst_element_factory_make ("queue", NULL);
  g_assert_nonnull (q);
  q1 = gst_element_factory_make ("queue", NULL);
  g_assert_nonnull (q1);

  if (g_strcmp0 (type, "audio") == 0) {
	conv = gst_element_factory_make ("audioconvert", NULL);
	g_assert_nonnull (conv);
    /* Might also need to resample, so add it just in case.
     * Will be a no-op if it's not required. */
    resample = gst_element_factory_make ("audioresample", NULL);
    g_assert_nonnull (resample);
    enc = gst_element_factory_make ("faac", NULL); //avenc_aac
    g_assert_nonnull (enc);
    parse = gst_element_factory_make ("aacparse", NULL);
    g_assert_nonnull (parse);

    gst_bin_add_many (GST_BIN (pipe), q, conv, resample, enc, q1, parse,
NULL);
    gst_element_sync_state_with_parent (q);
    gst_element_sync_state_with_parent (conv);
    gst_element_sync_state_with_parent (resample);
    gst_element_sync_state_with_parent (enc);
    gst_element_sync_state_with_parent (q1);
    gst_element_sync_state_with_parent (parse);
    //gst_element_sync_state_with_parent (hlssink);
    gst_element_link_many (q, conv, resample, enc, q1, parse, NULL);

  } else { // video
	conv = gst_element_factory_make ("videoconvert", NULL);
	g_assert_nonnull (conv);
	enc = gst_element_factory_make ("x264enc", NULL);
	g_object_set(enc,
"tune",0x00000004,"pass",5,"speed-preset",1,"key-int-max",10,NULL);

	fr_rate = gst_element_factory_make("videorate", NULL);
	fr_caps = gst_caps_new_simple("video/x-raw",
		  "framerate", GST_TYPE_FRACTION, 25, 2,
		  NULL);

	g_assert_nonnull (enc);
	parse = gst_element_factory_make ("h264parse", NULL);
	g_assert_nonnull (parse);
    gst_bin_add_many (GST_BIN (pipe), q, conv, fr_rate, enc, q1, parse,
NULL);
    gst_element_sync_state_with_parent (q);
    gst_element_sync_state_with_parent (conv);
    gst_element_sync_state_with_parent (fr_rate);
    gst_element_sync_state_with_parent (enc);
    gst_element_sync_state_with_parent (q1);
    gst_element_sync_state_with_parent (parse);

    gst_element_link_many (q, conv, fr_rate, NULL);
    gst_element_link_filtered(fr_rate,enc,fr_caps);
    gst_element_link_many (enc, q1, parse, NULL);

  }

  // add to hls audio/video sink pads
  enc_pad = gst_element_get_static_pad(parse, "src");
  hls_pad = gst_element_get_request_pad(hlssink, type);
  name = gst_pad_get_name(hls_pad);
  gst_print ("pad name %s\n", name);

// tried to sync hlssink only once but it's not better
  gst_print ("state %d\n", state);
  if (state > 0) {
	  gst_print ("SYNCING\n", NULL);
	  gst_element_sync_state_with_parent (hlssink);
  } else {
	  state++;
  }

  gst_pad_link(enc_pad, hls_pad);

  qpad = gst_element_get_static_pad (q, "sink");

  ret = gst_pad_link (pad, qpad);
  g_assert_cmphex (ret, ==, GST_PAD_LINK_OK);
}

"... ! matroskamux ! filesink" is the same but doesn't exits - it produces
mkv file with only audio playable (only audio stream is visible in mkv file,
don't know if it fills video also, but size seem be bigger than just audio)

I think common bin could help. Never done this before. Should I make bin
only from hlssink or longer pipe?

Thanks,
deim31



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


More information about the gstreamer-devel mailing list