How can I merge subtitle to a movie to play on my android TV?
I searched for a long time but almost program no longer work on ubuntu or I can't find the repository . Here is some answer but I think it's no longer supported on 16.04
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
I use Hand Brake on my ubuntu 16.04 great application and very simple to use . https://launchpad.net/~stebbins/+archive/ubuntu/handbrake-releases
sudo add-apt-repository ppa:stebbins/handbrake-releases sudo apt-get update sudo apt-get install handbrake
How it work:
If your TV can play movies that have subtitles muxed into the same file as the video, there are many advantages to adding the subtitles as a subtitle track, instead of burning them into the video.
mkvmerge -o movie_with_subs.mkv movie.mp4 subs.srt
That will include all tracks from the mp4 (video, audio, chapters), and subs from the srt as a text subtitle track. It takes about as long as copying the file, since it doesn't have to decode/re-encode the video.
Ubuntu packages mkvmerge in
mkvtoolnix. There's an
mkvtoolnix-gui package, with a gui frontend. It has a lot of options to let you control things like the subtitle offset.
The major advantage to this is that you avoid degrading the quality with another decode/encode cycle of generation loss. It's impossible to avoid losing quality when transcoding, and it takes a lot of CPU time to even come close to the quality-per-filesize of a well-encoded source. (e.g. x264 with
-preset slower, or if your player supports it, x265 if you're willing to spend a huge amount of CPU time to make smaller files that still look good). If you don't care about file size because you're just streaming it to your TV, transcoding with x264 with
-preset veryfast -crf15 can run quickly and lose minimal quality.
Another advantage to muxing subs is that you can then toggle the subs on/off, or have your player show them in a different position on screen.
You can also extract them later and search them if you're trying to remember a line from the movie.
You can even extract them, fix typos, and mux them back in.
I think that MKVToolNix is the simplest and easiest-to-use free tool available for you to merge a video file with a subtitles file. Just install it by e.g. running a terminal/shell command such as:
sudo apt-get install mkvtoolnix mkvtoolnix-gui -y
...and then run it, right-click the Source files area in order to add your video file and your subtitles file (step 1, at the picture below), specify the location of the destination MKV video file (step 2) and then click on Start multiplexing (step 3). Done.
MKVToolNix muxes/multiplexes the subtitles track/stream along with the video track/stream. This means that the output MKV file (e.g.
/tmp/output.mkv) will be a video file that contains subtitles embedded in it and you will be able to turn the subtitles on and off, while such MKV video is playing.
In such case, a laborious-yet-rewarding approach consists of (1) converting your subtitles file to the SSA format, (2) editing the SSA's Style line and then (3) using
ffmpeg to merge/hardcode such stylized subtitles into the video track/stream (the subtitles' characters will then be converted to pictograms or graphical symbols, i.e. pixels not only "laid over" the video's pictures/frames but replacing some of such pixels).
Here's how to do it:
sudo apt-get install gnome-subtitles -y) to convert your subtitles file (e.g.
input.srt) to the SSA format (e.g.
input.ssa) and then save the SSA file in
/tmp(you'll thus have
sudo apt-get install gedit -y) to open your SSA file and then replace the entire
Styleline by this one:
After replacing the
Style line, save the SSA file and then close the text editor. The configuration line above will globally preset the subtitles with a 16pt yellow Arial font and will add a semi-transparent black background behind the subtitles (to make reading them easier).
Now it's time to use
3.1. Install the
ffmpeg packages by running this shell command:
sudo apt-get install ffmpeg libav-tools -y
3.2. Move your video file (e.g.
input.avi) to the
/tmp folder, in order to end up having e.g.
3.3. Run the shell command
cd /tmp in order to cause the Linux shell to access the
3.4. Hardcode the SSA subtitles into the video file by running this shell command:
avconv -i input.avi -map 0:0 -map 0:1 -c:v libx264 -aspect 16:9 -q:v 1 -b:v 512k -strict -2 -c:a aac -ac 2 -filter:v subtitles=input.ssa output.mp4
The output of the command above will be
/tmp/output.mp4 and you'll notice that such MP4 video file will have hardcoded bitmap subtitles.
If you want to decrease the quality of the merged/output video in order to make its file smaller and possibly wait less time for the merging process to end, decrease
512k to a smaller value (e.g.
256k). If you decide to increase the quality of the merged/output video at the cost of getting a bigger file size and possibly waiting more for the merging process to end, increase
512k to a bigger value (e.g.
768k). If the original (input) video file has an aspect ratio of e.g. 4:2 and you want to preserve it, change
-aspect 16:9 to
-aspect 4:2. If you don't know the aspect ratio of such video file, open it with a media player and then check it out. For instance, if you open it with VLC, then hit Ctrl + i while it's playing and then select the
Codec tab, you'll see such aspect ratio informed at the field named
It now works without converting to
.ass on Ubuntu 20.10
They's enabled libass support recently it seems on the package, so now you can just do:
ffmpeg -i hello.mp4 -vf "subtitles=hello2.srt" hello-sub.mp4
Before it was enabled, you needed:
ffmpeg -i hello2.srt hello.ass ffmpeg -i hello.mp4 -vf ass=hello.ass hello-sub.mp4
You can check for libsass support with:
which now contains:
The generated output can be seen at: https://www.youtube.com/watch?v=Q0nVA3mYXLU
The test files can be obtained with:
wget -O hello.mp4 https://github.com/cirosantilli/media/blob/master/Top_Down_2D_Continuous_Game_with_Urho3D_C++_SDL_and_Box2D_for_Reinforcement_Learning_first_8_seconds.mp4?raw=true wget -O hello2.srt https://github.com/cirosantilli/media/blob/master/Top_Down_2D_Continuous_Game_with_Urho3D_C++_SDL_and_Box2D_for_Reinforcement_Learning_first_8_seconds.srt?raw=true
Tested on Ubuntu 20.04, ffmpeg 4.2.4.