首页 > 解决方案 > Gstreamer:如何将 decodebin 链接到 encodebin?(错误:未能延迟链接某些垫......)

问题描述

天真地,我试图将 decodebin 链接到 encodebin:

$ gst-launch-1.0 filesrc location="/tmp/sound.wav" ! decodebin ! encodebin profile="application/ogg:video/x-theora:audio/x-vorbis" ! filesink location="/tmp/sound.ogg"
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstDecodeBin:decodebin0: Delayed linking failed.
Additional debug info:
./grammar.y(510): gst_parse_no_more_pads (): /GstPipeline:pipeline0/GstDecodeBin:decodebin0:
failed delayed linking some pad of GstDecodeBin named decodebin0 to some pad of GstEncodeBin named encodebin0
ERROR: from element /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstWavParse:wavparse0: Internal data stream error.
Additional debug info:
gstwavparse.c(2293): gst_wavparse_loop (): /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstWavParse:wavparse0:
streaming stopped, reason not-linked (-1)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

当然,缺少一些东西。它是什么?

请注意,这有效: gst-launch-1.0 filesrc location="/tmp/sound.wav" ! decodebin ! audioconvert ! vorbisenc ! oggmux ! filesink location="/tmp/sound.ogg"

标签: gstreamer

解决方案


gst-launch-1.0 filesrc location="/tmp/sound.wav" ! decodebin ! encodebin profile="application/ogg:video/x-theora:audio/x-vorbis" ! filesink location="/tmp/sound.ogg"

encodebin 的 pad 中没有模板,因此 gst-launch 不知道要请求哪个 pad(视频或音频)。您可以使用以下命令明确要求其中之一:

gst-launch-1.0 filesrc location="/tmp/sound.wav" ! decodebin ! enc.audio_%u encodebin name=enc profile="application/ogg:video/x-theora:audio/x-vorbis" ! filesink location="/tmp/sound.ogg"

请注意我们如何给 encodebin 命名为“enc”,然后我们将 decodebin 链接到音频垫,因为我们知道这是一个纯音频文件。

如果我们同时拥有视频和音频,您需要将视频板从 decodebin 显式链接到 encodebin 的视频板,依此类推。您也可以为 decodebin 命名并链接它们。就像是:decodebin name=dec dec.audio_%u ! queue ! enc.audio_%u dec.video_%u ! queue ! enc.video_%u

作为最后的建议,建议在每个可以分支到多个路径的元素之后都有一个队列,例如 decodebin。当你有多个输出时,它是强制性的,但即使你只有一个,拥有它也没有什么坏处。


推荐阅读