Reputation: 9369
This question is related to How to add subtitles from a SRT file on a video and play it with Gstreamer in a c program
I want to overlay an MP4 video with subtitles from an SRT file.
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.)
Here is my first attempt:
gst-launch-1.0 -v \
filesrc location=titles.srt \
! subparse name=txt \
! queue \
! filesrc location=sample.mp4 \
! decodebin \
! subtitleoverlay \
! autovideosink
This prints:
WARNING: erroneous pipeline: could not link queue0 to filesrc1
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.
Upvotes: 0
Views: 4446
Reputation: 600
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.
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.video_sink \
filesrc location=titles.srt ! subparse ! ov.text_sink
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.
Upvotes: 2
Reputation: 1
A better way to format the pipeline would be:
gst-launch-1.0 -v \
textoverlay name=ov ! autovideosink \
filesrc location=sample.mp4 ! decodebin ! ov.video_sink \
filesrc location=titles.srt ! subparse ! ov.text_sink
This shows that filesource is a separate element, and not part of the ov.videosink and ov_text_sink.
Upvotes: 0
Reputation: 9369
I found a solution by studying the textoverlay example on http://docs.gstreamer.com/display/GstSDK/gst-launch:
gst-launch-1.0 -v \
textoverlay name=ov \
! autovideosink filesrc location=sample.mp4 \
! decodebin \
! ov.video_sink filesrc location=titles.srt \
! subparse \
! ov.text_sink
I still don't understand what "filesrc" is doing for autovideosink and textoverlay. filesrc is a distinct element, but here it's being used as if it's the name of a pad. Neither autovideosink nor textoverlay have pads by that name. I guess I don't completely understand the pipeline syntax.
Upvotes: 0