[MPlayer-users] Make a clip with subtitles?

Miriam English mim at miriam-english.org
Sat Apr 14 12:31:48 EEST 2018


Sorry about the delay in responding. Been busy.

Bill Crockett wrote:
>> I can post a brief example of the ffmpeg code to do this
>> (perhaps offlist if it potentially derails the thread).
> I would be interested to see that.  It won't derail.  I have seen many 
> references to FFmpeg on the MPlayer and MEncoder mailing list.  They 
> seem to prod you to use FFmpeg than MEncoder.

The following presumes Linux. Other operating systems probably work 
exactly the same, but I haven't tried them.

Using ffmpeg to hard-code subtitles into a video requires libass 
dependency to be compiled in with --enable-libass or if you don't want 
to compile it you can download a static binary precompiled from:
https://johnvansickle.com/ffmpeg/
If you want to compile it yourself he handily provides all the sources 
including required libs at:
https://johnvansickle.com/ffmpeg/release-source/

To hardcode subtitles.srt into inputvideo.mp4
ffmpeg  -i input.mp4  -vf subtitles=subtitles.srt  out.mp4

To split frames into jpeg images is probably possible using ffmpeg, but 
I prefer mplayer.
mplayer  -vo jpeg  out.mp4

To add srt subtitles to the container is a little longer.
Instead of putting it all on one line I'll backslash-escape the linefeed 
characters to make it easier to read.
ffmpeg -i input.mp4 \
     -i subtitles.srt \
     -map 0:0 -map 0:1 -map 1
     -vcodec copy \
     -acodec copy \
     -scodec mov_text \
     -metadata:s:s:0 language=eng \
     out.mp4

The line with the -map options is not really necessary in simple cases, 
but it lets you select which streams you want to include in the output 
video. In the case above it includes the video (usually 0:0) and the 
audio (usually 0:1) from the first input (0), and the only stream from 
the second input (1). This maps the streams into 0:0 (video), 0:1 
(audio), and 0:2 (subtitle) of the output video.

The -map options are kinda useless here and could be omitted, but if the 
input video had two audio streams, one English and one French plus a 
French subtitle stream, then specifying only the particular streams you 
want becomes very useful, so that you end up with just the video, 
English audio, and English subtitles substituted for the French subs. 
Alternatively, creative use of the -map options lets you add multiple 
soundtracks and multiple subtitles all inside the single mp4 container. 
Probably works for avi output container too, though I haven't tried that.

The metadata line isn't terribly important and can be safely omitted. It 
just displays the label "eng" briefly when you select the subtitle 
stream with the "j" key, so makes it easier to see. You can set up 
mplayer to automatically play subtitles -- I'm half deaf, so require 
subtitles. I use a wrapper script with the line:
mplayer -fs -sid 0 -utf8 -msglevel all=-1 "$@"
where "-fs" runs it fullscreen,  -sid 0 displays the first subtitle 
stream,  -utf8 expects subtitles to be encoded as utf-8 characters,  and 
-msglevel all=-1 turns off error messages (if I want error messages I 
run it from a terminal without that option). "$@" simply gets replaced 
by the input video's name when the script is called. I've set the script 
to be the default action run by clicking on a video.

I use ffprobe to check what streams are in the input video. (I use 
probesize and analyzeduration with large numbers because some videos 
don't begin some streams right at the beginning.)
ffmpeg  -probesize 50M  -analyzeduration 100M  -i input.mp4

And I like to check that with mplayer.
mplayer input.mp4  -v  -ao null  -vo null  -frames 0

Note that if you want to add vobsub subtitles you need only specify the 
.idx file on the subtitle input line and the .sub file will be used 
automatically (if it is in the same folder). No subtitle codec is needed 
-- it just gets copied in ( -scodec copy ).

Hope this helps,

     - Miriam

-- 
What is the most important thing in the world you could be working on right now, and if you are not working on that, why aren't you?
  -- Aaron Swartz (internet genius, philanthropist)



More information about the MPlayer-users mailing list