VinGarcia
VinGarcia

Reputation: 1205

Encoding video for streaming with multiple subtitle streams in VLC

I am implementing an offline video streaming service, so our users can have the encrypted videos on their computers and open them only by using our streaming app.

So what I need is to stream a freshly decrypted video file directly to a local VLC client so I don't have to save it on disk. A minimum working example would be:

cat my_video.mp4 | vlc -

But this only shows the video and audio tracks, no subtitles.

I want to know if there is a way to encode a video so that this would work with 3 audio tracks and 3 subtitle tracks. I would also settle for an answer explaining that it is not possible and why not.

More details below:


I have 3 audio tracks and 3 subtitle tracks and I am using FFMPEG.
(The original format of the videos is mp4 with an h264 encoding)

Currently, I am able to make streamable .mp4 files, thanks to this answer, and also to make .ts files that will show the video and the 3 audio options but not the subtitles. The command I am using is this:

video_name=demo_0101.mp4
sub_name=demo_0101.srt
output=0101.mp4 # Or `.ts`

ffmpeg\
  -i en_raw/$video_name -i pt_raw/$video_name -i es_raw/$video_name\
  -i en_subs/$sub_name\
  -i pt_subs/$sub_name\
  -i es_subs/$sub_name\
  -map 2:v\
  -map 0:a:0 -map 1:a:0 -map 2:a:0\
  -map 3:s -map 4:s -map 5:s\
  -c:v libx264 -crf 22\
  -movflags faststart\ # (This line is only necessary for .mp4)
  -c:a:0 aac -c:a:1 aac -c:a:2 aac\
  -c:s:0 mov_text -c:s:1 mov_text -c:s:2 mov_text\
  $output

The problem is: The subtitles are not recognized (don't show up at all) using the .ts format and when using .mp4 VLC reports an error:

Unidentified codec: VLC could not identify the audio or video codec

Please note when not streaming the .mp4 version works with all audios and the subtitles, i.e.:

vlc my_video.mp4

In case someone is wondering I plan on selecting the which subtitle and audio to play from command line with the VLC options: --audio-track 1 --sub-track 0

I hope someone can help me. Thanks in advance.

Upvotes: 0

Views: 840

Answers (1)

VinGarcia
VinGarcia

Reputation: 1205

I was unable to find a way to encode the subtitles directly on the video which would be the preferable solution. However, I found a VLC command that will display the subtitle file together with the streaming video:

cat 0101.mp4 | vlc --sub-file en_subs/demo_0101.srt

This is not ideal for 2 reasons:

  1. It does not work with the .ts format only .mp4.
  2. This requires me to save the original subtitle files on the user disk.

I will not mark this solution as the accepted answer because if it is possible to stream the video directly with the subtitles I want to know, and I also believe that such answer would be helpful for others that happen to read this page.

Upvotes: 0

Related Questions