Gstreamer实践

播放ts over udp

gst-launch-1.0 udpsrc uri=udp://233.233.233.223:6666 \
! queue2 use-buffering=1 max-size-buffers=0 \
max-size-time=0 max-size-bytes=0 low-percent=50 \
! decodebin ! videoconvert ! autovideosink

延时

gst-launch-1.0 rtmpsrc location=rtmp://172.17.1.55:1935/test/orig ! flvdemux ! queue min-threshold-time=10000000000 max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! flvmux !  rtmpsink location=rtmp://172.17.1.55:1935/test/delay

生成字幕视频

gst-launch-1.0 videotestsrc pattern=17 foreground-color=0 ! video/x-raw,width=1280,height=720   ! textoverlay text=123456 ! autovideosink

textoverlay插件利用pango进行渲染,所以支持pango标记语言,可以用如下的方式来输出字符串[2]

gst-launch-1.0 videotestsrc ! textoverlay text="<span foreground=\"blue\" background=\"green\" size=\"x-large\">Blue text</span> is <i>cool</i>" ! xvimagesink

具体格式定义参考链接Pango Text Attribute Markup Language

videomix

gst-launch-1.0 \
  videotestsrc pattern=1 ! \
  video/x-raw,format=AYUV,framerate=\(fraction\)10/1,width=100,height=100 ! \
  videobox border-alpha=0 top=-70 bottom=-70 right=-220 ! \
  videomixer name=mix sink_0::alpha=0.7 sink_1::alpha=0.5 ! \
  videoconvert ! xvimagesink \
  videotestsrc ! \
  video/x-raw,format=AYUV,framerate=\(fraction\)5/1,width=320,height=240 ! mix.

输出pipeline graph

在代码中增加如下代码即可

GST_DEBUG_BIN_TO_DOT_FILE(pipeline, GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");

运行程序前,需要设置环境变量

# export GST_DEBUG_DUMP_DOT_DIR=/tmp/

编译Gstreamer

PKG_CONFIG_PATH=/home/meng/bins/gstreamer/lib/pkgconfig
./configure --prefix=/home/meng/bins/gstreamer

编译支持nvenc版本的libav插件

PKG_CONFIG_PATH=/home/meng/bins/gstreamer/lib/pkgconfig ./configure --prefix=/home/meng/bins/gstreamer --with-libav-extra-configure="--enable-nonfree --enable-nvenc --enable-gpl --enable-libx264"

渐变修改gstreamer element的属性值

static GstTimedValueControlSource *
set_interpolation (GstObject * element, GESVideoTransitionPrivate * priv,
    const gchar * propname)
{
  GstControlSource *control_source;

  g_object_set (element, propname, (gfloat) 0.0, NULL);

  control_source = gst_interpolation_control_source_new ();
  gst_object_add_control_binding (GST_OBJECT (element),
      gst_direct_control_binding_new (GST_OBJECT (element), propname,
          control_source));
  g_object_set (control_source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);

  return GST_TIMED_VALUE_CONTROL_SOURCE (control_source);
}

static void
ges_video_transition_update_control_source (GstTimedValueControlSource * ts,
    guint64 duration, gdouble start_value, gdouble end_value)
{
  gst_timed_value_control_source_unset_all (ts);
  gst_timed_value_control_source_set (ts, 0, start_value);
  gst_timed_value_control_source_set (ts, duration, end_value);
}

priv->smpte_control_source =
    set_interpolation (GST_OBJECT (priv->smpte), priv, "position");
ges_video_transition_update_control_source (priv->smpte_control_source,
    duration, 1.0, 0.0);

录制rtmp

GST_DEBUG_NO_COLOR=1 GST_DEBUG=4,GST_HUB:2 LD_LIBRARY_PATH=/root/nmpdirector/lib gst-launch-1.0 rtmpsrc location=rtmp://host/app/stream ! flvdemux ! flvmux ! filesink location=/root/test.flv 2> log.txt

画中画

MAIN_SCREEN=file:///file/path \
SUB_SCREEN=file:///file/path \
gst-launch-1.0 -v \
uridecodebin uri=$MAIN_SCREEN name=decoder1 \
uridecodebin uri=$SUB_SCREEN name=decoder2 \
videomixer name=mix \
        sink_0::xpos=0   sink_0::ypos=0 \
        sink_1::xpos=640 sink_1::ypos=360 \
    ! autovideosink \
decoder1. \
    ! queue ! videoscale \
    ! video/x-raw,width=1280,height=720 \
    ! videoconvert \
    ! mix.sink_0 \
decoder2. \
    ! queue ! videoscale \
    ! video/x-raw,width=640,height=360 \
    ! videoconvert \
    ! mix.sink_1 \

问题

参考文档

  1. https://developer.ridgerun.com/wiki/index.php/How_to_generate_a_Gstreamer_pipeline_diagram_(graph)
  2. change text- and timeoverlay settings
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一种新的协议。它实...
    香橙柚子阅读 24,399评论 8 183
  • Java基础常见英语词汇(共70个)['ɔbdʒekt] ['ɔ:rientid]导向的 ...
    今夜子辰阅读 8,628评论 1 34
  • 文|飘扬的鹅毛 犹如一颗坠落的繁星在夜空的屋顶上生辉犹如风雨中一把大伞为我撑起了一片晴天 母亲你看那山谷里 那田...
    飘扬的鹅毛阅读 3,858评论 2 6
  • 日子走着走着 渐渐面目全非 谁会在意长夜里的悲泣 谁也钻不进谁心里 那一重一重的路 遥远的距离 愁肠团成了团 纠缠...
    辛末阅读 5,034评论 0 0
  • 我现在过得很好。有爱情,有好友,父母也在身边,计划中有圆满的跨境旅行,悠长达到半个月的假期。 我的工作压力不大,环...
    梦蝶Ariel阅读 1,517评论 0 1

友情链接更多精彩内容