在管道中使用 autoaudiosink 并在没有声音的情况下播放媒体

use autoaudiosink in pipeline and play media without sound

我想使用下面的管道来播放有声和无声内容。问题是内容没有声音 PREROLLING 管道,但不播放

gst-launch-1.0.exe uridecodebin uri=file:///home/mymediafile.ogv name=d1 ! tee name=t1 ! queue max-size-buffers=2 ! jpegenc ! appsink name=myappsink t1. ! queue ! autovideosink d1. ! queue ! audioconvert ! audioresample ! autoaudiosink

我该如何解决这个问题?

我发现无法让您的管道在命令行上运行。如果我放入管道的音频部分,没有音频的文件会挂起。

但是,在您的应用程序中,您将能够为 pad_added 事件添加信号,并且只在需要时添加管道的音频部分。一些伪代码:

void decodebin_pad_added(GstElement *decodebin, GstPad *new_pad, gpointer user_data) {
 GstElement* pipeline = (GstElement*)user_data;

 GstCaps* audio_caps = gst_caps_from_string("audio/x-raw");
 GstCaps* pad_caps = gst_pad_get_current_caps(new_pad);
 if(! gst_caps_can_intersect(pad_caps, audio_caps)) {
  return;
 }

 GstElement* audio_pipeline = gst_parse_launch("queue ! audioconvert ! audioresample ! autoaudiosink", NULL);

 gst_bin_add(GST_BIN(pipeline), audio_pipeline);

 GstElement* decodebin = gst_bin_get_by_name(GST_BIN(pipeline), "d1");
 gst_element_link(decodebin, audio_pipeline);
 gst_object_unref(decodebin);
}

void decodebin_no_more_pads(GstElement *decodebin, gpointer user_data) {
    GstElement* pipeline = (GstElement*)user_data;

    gst_element_set_state(pipeline, GST_PLAYING);
}

GstElement* pipeline = gst_parse_launch("uridecodebin uri=file:///home/mymediafile.ogv name=d1 ! tee name=t1 ! queue max-size-buffers=2 ! jpegenc ! appsink name=myappsink t1. ! queue ! autovideosink", NULL);

GstElement* decodebin = gst_bin_get_by_name(GST_BIN(pipeline), "d1");
g_signal_connect(decodebin, "pad-added", G_CALLBACK(decodebin_pad_added), pipeline);
g_signal_connect(decodebin, "no-more-pads", G_CALLBACK(decodebin_no_more_pads), pipeline);

gst_element_set_state(pipeline, GST_STATE_PAUSED); //pause to make demuxer and decoders get setup and find out what's in the file

async-handling=true 添加到自动音频接收器。

gst-launch-1.0.exe uridecodebin uri=file:///home/mymediafile.ogv name=d1 ! tee name=t1 ! queue max-size-buffers=2 ! jpegenc ! appsink name=myappsink t1. ! queue ! autovideosink d1. ! queue ! audioconvert ! audioresample ! autoaudiosink async-handling=true