user656347
user656347

Reputation:

Adding subtitle while doing H.264 encoding into a Matroska container

I have a requirement where I need to encode a v4l2src source in H.264 while using a Matroska container. If I have .mkv file with embedded subtitles it is easy to extract subtitles with

gst-launch-1.0 filesrc location=test.mkv ! matroskademux ! "text/x-raw" ! filesink location=subtitles

From what I understand and assuming I understand correctly, during the encoding process the "subtitle_%u" pad needs to be linked to text/x-raw source using textoverlay.

gst-launch-1.0 textoverlay text="Video 1" valignment=top halignment=left font-desc="Sans, 60" ! mux.  imxv4l2src device=/dev/video0 ! timeoverlay ! videoconvert ! queue ! vpuenc_h264 ! capsfilter 
caps="video/x-h264" ! matroskamux name=mux !  filesink location=sub.mkv

I use the above pipeline but I do not get the overlay in the .mkv video. What is the correct way to encode a subtitle/text overlay while encoding a source in H.264 in a matroska container and then also later be able to extract it using the first pipeline?

Upvotes: 0

Views: 1182

Answers (1)

Laurent Trabattoni
Laurent Trabattoni

Reputation: 1

You may try this:

gst-launch-1.0 \
  filesrc location=subtitles.srt ! subparse ! kateenc category=SUB ! mux.subtitle_0 \
  imxv4l2src device=/dev/video0 ! timeoverlay ! videoconvert ! queue ! vpuenc_h264 ! \
  capsfilter caps="video/x-h264" ! matroskamux name=mux ! filesink location=sub.mkv

And the subtitles.srt file may be like this:

1
00:00:00,500 --> 00:00:05,000
CAM 1

2
00:00:05,500 --> 00:00:10,000
That's all folks !

Upvotes: 0

Related Questions