如何使用gstreamer覆盖带有字幕的视频 [英] How to use gstreamer to overlay video with subtitles

查看:82
本文介绍了如何使用gstreamer覆盖带有字幕的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与我想用SRT文件中的字幕覆盖MP4视频.

I want to overlay an MP4 video with subtitles from an SRT file.

在我看来,此过程需要两个线程:一个用于读取和解码MP4文件,另一个用于读取和解析字幕.然后,需要以某种方式将它们组合起来,这就是我认为 subtitleoverlay 的目的.最后,我想查看结果.(当此方法有效时,我将用Python重写此代码并将其安装在网络服务器后面,该服务器将使用自定义字幕覆盖视频内容并流式传输结果.)

It seems to me that this process requires two threads: one to read and decode the MP4 file and another to read and parse the subtitles. Then they need to be combined somehow, which is what I think the element subtitleoverlay is for. Last, I want to view the result. (When this works, I will re-write this in Python and install it behind a web-server that will and overlay video content with custom subtitles and stream the result.)

这是我的第一次尝试:

gst-launch-1.0 -v \
  filesrc location=titles.srt \
  ! subparse name=txt \
  ! queue \
  ! filesrc location=sample.mp4 \
  ! decodebin \
  ! subtitleoverlay \
  ! autovideosink

此打印:

WARNING: erroneous pipeline: could not link queue0 to filesrc1

我是一位经验丰富的程序员,但是是视频流处理的完全新手.我花了数小时在 http://docs.gstreamer.com/上浏览文档,并搜索示例,但显然我仍然不了解如何组合流.我没有尝试从上一个问题中复制示例,因为我还不了解所有内容,因此我想从需要添加的基本内容入手.

I'm a veteran programmer but a complete newbie to video-stream processing. I've spent hours going over docs at http://docs.gstreamer.com/ and searching for examples, but I'm am obviously still not understanding something about how to put together streams. I did not try to copy the example from the previous question because I don't yet understand it all and I want to start with something basic that I can add to as needed.

推荐答案

示例管道具有奇数换行符.这是具有更好格式的同一管道(我认为),但是有些人喜欢将所有!"排成一行.字符.

The example pipeline has odd line breaks. Here is the same pipeline with better formatting (in my opinion) but some people like to line up all of the '!' characters.

来自2个文件源的数据过滤到textoverlay元素源板中.所有的行制动器都将被忽略.

The data from the 2 file sources filter into the textoverlay element source pads. All line brakes are ignored.

gst-launch-1.0 -v \
    textoverlay name=ov ! autovideosink \
    filesrc location=sample.mp4 ! decodebin ! ov.videosink \
    filesrc location=titles.srt ! subparse ! ov.text_sink

原始管道中的问题之一是它试图将队列输出连接到第二个filerc的输入.但是filesrc没有输入,因此会发出错误.

One of the issues in your original pipeline is that it is trying to connect the queue output to the input of the second filesrc. But the filesrc does not have an input so an error is issued.

'!'字符表示两个元素已连接,但是如果元素之间存在空格,则仅表示在不将其连接到前一个元素的情况下创建了一个新元素.关于工作管道的另一点要指出的是,有可能并且有必要设置元素的名称,以便以后在管道中使用它.

The '!' character indicates that two elements are connected, but if there is a space between elements, it just means that a new element is created without connecting it to the previous element. Another thing to point out about the working pipeline is that it is possible and necessary to set the name of an element so that it can be used later in the pipeline.

这篇关于如何使用gstreamer覆盖带有字幕的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆