bash 使用 Gstreamer textoverlay 插件在视频文件上叠加文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22247029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:49:37  来源:igfitidea点击:

Overlaying text on video file using Gstreamer textoverlay plugin

bashgstreamer

提问by user3391196

I am using the following command to do it:

我正在使用以下命令来做到这一点:

/usr/local/bin/gst-launch-1.0 filesrc location=/home/ubuntu/DELTA.mpg ! textoverlay text="Hello" ! filesink location=/home/ubuntu/delta2.mpg

But I am getting this output:

但我得到这个输出:

ubuntu@ip-10-185-10-118:~$ /usr/local/bin/gst-launch-1.0 filesrc location=/home/ubuntu/DELTA.mpg  ! textoverlay text="Hello" ! filesink location=file4.mpg
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstTextOverlay:textoverlay0: Could
not multiplex stream.
Additional debug info:
gstbasetextoverlay.c(1892): gst_base_text_overlay_video_event(): /GstPipeline:pipeline0/GstTextOverlay:textoverlay0:
received non-TIME newsegment event on video input
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:00.024475840
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
ubuntu@ip-10-185-10-118:~$

What am I doing wrong here ?

我在这里做错了什么?

回答by max taldykin

The problem here is that you are trying to overlay text on undecoded stream. filesrcelement just reads data from the file and outputs raw bytes. You need to decode it first, then overlay the text, then encode it back and write to file.

这里的问题是您试图在未解码的流上覆盖文本。filesrcelement 只是从文件中读取数据并输出原始字节。您需要先解码它,然后覆盖文本,然后将其编码回并写入文件。

Here is simple preview pipeline:

这是简单的预览管道:

$ gst-launch  filesrc location=test.mpg \
    ! decodebin2 ! textoverlay text=Hello ! xvimagesink

And here is the pipeline that overlays text and encodes video back to the file:

这是覆盖文本并将视频编码回文件的管道:

$ gst-launch \
    filesrc location=test.mpg \
      ! decodebin2 name=demuxer \
    demuxer. \
      ! textoverlay text=Hello \
      ! x264enc ! muxer. \
    demuxer. ! audioconvert ! vorbisenc ! muxer. \
    matroskamux name=muxer \
      ! filesink location=output.mkv

I used different output format just to not depend on additional gstreamer plugins. You can switch vorbisencto faacand matroskamuxto mpegtsmuxto get output.mpgfile.

我使用不同的输出格式只是为了不依赖于额外的 gstreamer 插件。您可以切换vorbisencfaacmatroskamuxmpegtsmux获得output.mpg文件。