Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Burning subtitles to video with mencoder

  1. #1
    Join Date
    Feb 2008
    Beans
    157
    Distro
    Ubuntu Development Release

    Burning subtitles to video with mencoder

    Just to remind myself, this was the first time I tried it

    Code:
    mencoder movie.avi -sub movie.srt -o movie.hardsubs.avi -oac copy -ovc lavc -lavcopts vbitrate=1200
    Mencoder is fast, took about 10 minutes to burn hardcode the subs to a 1:30 hour movie. Excellent!
    My PC
    Ubuntu user from 18.2.2008
    Oh, my studio and my band

  2. #2
    Join Date
    Jan 2009
    Beans
    5

    Re: Burning subtitles to video with mencoder

    I think that the default font size (%5) is way too big, so I add this to the mencoder command to make it %3.3
    Code:
    -subfont-text-scale 3.3
    I also like to move the subtitles up a smidgeon so that they don't get cut-off when I play on my TV.
    Code:
    -subpos 96

    -mlahey
    Last edited by mlahey; August 18th, 2009 at 03:03 AM.

  3. #3
    Join Date
    Jan 2009
    Beans
    5

    Re: Burning subtitles to video with mencoder

    If you want to burn a subtitle track that is part of a matroska file (i.e .mkv file)

    replace
    Code:
    -sub subfile.srt
    with
    Code:
    -slang eng
    of course replace "eng" with the language of your choice. inspect the output of mencoder to find out what subtitle languages are available.

    If you want to adjust the size or other properties of the subtitles it becomes complicated. Matroska files can include at least three different kinds of subtitle tracks: SSA/*** , SRT or Vobsub. each uses a different set of mencoder commands. get the "mkvtoolnix" package to figure out which type of subs you have. also read the mencoder man page

    if you have vobsubs that are printed too high, you can try this to move the subtitles to the bottom of the screen
    Code:
    -spualign 2 -subpos 96
    -mlahey

    ha - the forums won't let me put in the file format for Advanced Sub Station files. apparently it thinks subtitles are obscene. it replaces the A S S with ***
    Last edited by mlahey; August 18th, 2009 at 03:04 AM. Reason: added more info

  4. #4
    Join Date
    Jan 2009
    Beans
    5

    Re: Burning subtitles to video with mencoder

    Also keep if you are encoding to DivX (which we are) you really should do two-pass encoding to get the best quality video.

    see any mencoder gude or check out the mencoder docs here

    for example

    pass 1
    Code:
    mencoder movie.avi -sub movie.srt -subfont-text-scale 3.3 -subpos 96 -o /dev/null -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1
    pass 2
    Code:
    mencoder movie.avi -sub movie.srt -subfont-text-scale 3.3 -subpos 96 -o movie.hardsubs.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vpass=2
    sorry about the serial posts

    -mlahey
    Last edited by mlahey; August 18th, 2009 at 03:05 AM.

  5. #5
    Join Date
    Aug 2009
    Beans
    1
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Burning subtitles to video with mencoder

    Thanks a bunch guys, I'm really new to Ubuntu and was having trouble figuring out what to do with an avi/srt combo that I had downloaded. This worked like a charm

  6. #6
    Join Date
    Jan 2009
    Beans
    5

    Re: Burning subtitles to video with mencoder

    Here is a sample script to hardsub your avi or matroska files. should work with mpegs too


    it takes a single movie file as the argument. if you add "fast" after the movie file it will do a one-pass encode instead of a two-pass

    for example
    Code:
    sh ./hardsub.sh movie.avi
    sh ./hardsub.sh movie.avi fast
    it assumes that your .srt has the same name as the avi
    if you are hardsubbing a matroska file and don't have an .srt it tries to use an english subtitle track embedded in the matroska

    here's the script


    hardsub.sh:
    Code:
    #!/bin/bash
    
    # hardsub.sh
    # a basic script to hardcode subtitles into movie files using mencoder
    #
    # uses a two pass - high quality encode by default
    # fast option invokes a quick one pass encode 
    #
    # it assumes that you are using an .srt subtitle file with the same
    #+ name as the movie file
    #
    # if you are using a matroska movie (.mkv) and it can't find the .srt
    #+ file it uses the embedded english subtitle track
    #
    #
    # NB: this is a preliminary script and doesn't do much error checking
    #
    # Version 0.11
    #
    # Mike Lahey 2009
    #####################
    
    # language used for subtitle track embedded in a matroska file
    # for alternative subtitle (& audio) tracks try "mplayer -v movie.mkv"
    LANG=eng
    
    # these mencoder options scale down the subtitles and move them 
    #+ up just a bit 
    SUBOPTS="-subfont-text-scale 3.3 -subpos 96"
    
    if [ -z "$1" ]; then
    	echo usage: $0 movie.avi [fast]
    	echo 
    	echo fast -  do a fast one pass encode
    	exit 1
    fi
    MOVIE=$1
    EXT=${MOVIE##*.}
    OUTPUT=${MOVIE/%.$EXT/.hardsub.avi}
    
    # first make sure that our movie file is there
    if [ ! -f "$MOVIE" ]; then
    	echo input file \"$MOVIE\" does not exit
    	exit 1
    fi
    
    # next check if we have the SRT file and create subtitle command for 
    # mencoder 
    SRT=${MOVIE/%$EXT/srt}
    
    if [ -f "$SRT" ]; then
    	
    	# good we have an SRT file, so create our subtitle command
    	SUBCMD="-sub \"$SRT\""
    else	
    	#no SRT file? well check if we are dealing with a matroska file
    	if [ "$EXT" == "mkv" ]; then
    		echo "################################################"
    		echo couldnt find \"$SRT\" 
    		echo so trying embedded subtitle track \"$LANG\"
    		echo "################################################"
    		SUBCMD="-slang $LANG -spualign 2"
                    # "-spualign 2" ensures proper placement of vobsub tracks
    	else
    		echo could not find subtitle file \"$SRT\"
    		echo
    		echo maybe its called something else? try renameing it.
    		exit 1
    	fi
    fi
    
    # if the input movie is not an avi then transcode the audio to mp3 
    # this may result in an unnecessary transcode but it will make 
    #+ incompatable audio streams (such as ogg/vorbis) work with an avi
    
    if [ "$EXT" == "avi" ]; then
    	ACODEC=copy
    else
    	ACODEC=mp3lame
    fi
    
    # most formats other than avi allow non-square pixels.  
    # by invoking the scale filter we ensure that the video is 
    # displayed with the proper aspect ratio in our avi
    # since were scaling anyway - scale to a multiple of 16 to make the encoding more effiecient
    if [ "$EXT" != "avi" ]; then
    	SUBOPTS="$SUBOPTS -vf-pre scale=-8:-8"
    fi
    
    #### if fast option was invoked, do a fast one pass encode
    if [ "$2" == "fast" ]; then
    
    	CMD="mencoder \"$MOVIE\" $SUBCMD $SUBOPTS -o \"$OUTPUT\" \
    	-oac $ACODEC -ovc lavc"
    	echo $CMD
    	eval $CMD
    
    	if [ $? != 0 ]; then
    	   echo "################# mencoder failed ################"
    	   exit 1
    	fi
    	exit
    fi
    
    
    
    
    #### normal two pass encode
    
    CMD="mencoder \"$MOVIE\" $SUBCMD $SUBOPTS -o /dev/null -oac $ACODEC \
    -ovc lavc -lavcopts vcodec=mpeg4:vhq:turbo:vpass=1"
    echo $CMD
    eval $CMD
    
    if [ $? != 0 ]; then
    	echo "################# mencoder failed ################"
    	rm divx2pass.log
    	exit 1
    fi
    
    CMD="mencoder \"$MOVIE\" $SUBCMD $SUBOPTS -o \"$OUTPUT\" -oac $ACODEC \
    -ovc lavc -lavcopts vcodec=mpeg4:vhq:vpass=2"
    echo $CMD
    eval $CMD
    
    if [ $? != 0 ]; then
    	echo "################# mencoder failed ################"
    	rm divx2pass.log
    	exit 1
    fi
    
    rm divx2pass.log
    remember to set the executable bit of the script
    Code:
    chmod +x hardsub.sh

    -mlahey
    Last edited by mlahey; August 21st, 2009 at 09:00 AM. Reason: updated script

  7. #7
    Join Date
    Aug 2006
    Location
    Crakatinny, nea
    Beans
    Hidden!

    Re: Burning subtitles to video with mencoder

    Thanks for that, but I get "./hardsub.sh: 17: Bad substitution" when I run the script.

    Any ideas?

    Thanks
    Last edited by GuiGuy; August 28th, 2009 at 09:17 AM.
    The GuiGuy
    Free is only good when it works.

  8. #8
    Join Date
    Oct 2007
    Location
    Mexico City
    Beans
    57
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Burning subtitles to video with mencoder

    I made a very simple script (subtitles.sh) for making an .avi file with the .srt subtitles already embedded. Save my script to your scripts folder in Nautilus:
    ~/.gnome2/nautilus-scripts/
    Make it executable:
    sudo chown +x subtitles.sh
    To use it:
    You should have 2 files, same name, different extension. For example:
    MyMovie.avi (The video without subtitles)
    MyMovie.srt (The subtitles file)
    Then, using Nautilus, point to the MyMovie.avi file, right click, Scripts, subtitles.sh. A message "working..." appears. When it finishes, it says "Finished". Now you will have a third file, MyMovie_subt.avi with the subtitles embedded.
    Hope you find my script useful.
    Here is the script subtitles.sh:

    #!/bin/bash
    for file
    do
    base=${file%.*}
    ext=${file##*.}
    newname=${base}"_subt".${ext}
    mencoder "$file" -sub ${base}.srt -oac copy -ovc lavc -o "$newname" -subcp latin1 -font /usr/share/fonts/msttcorefonts/arial.ttf -subfont-text-scale 3.8 | zenity --progress --text="Working: $file" --pulsate --auto-close
    done
    zenity --info \
    --text="Finished"
    Last edited by asphixmx; September 18th, 2009 at 08:47 AM.

  9. #9
    Join Date
    Nov 2006
    Location
    India
    Beans
    24
    Distro
    Ubuntu Development Release

    Re: Burning subtitles to video with mencoder

    Using mencoder 2:1.0~rc2-0ubuntu19+medibuntu1, there seems to be a problem when applying a filter and embedding subtitles into the video. I use a command like (removed all unnecessary options in this example):

    Code:
    mencoder -sub test.srt  -vf pp=lb -ovc lavc -oac lavc INPUT.MPG -o out.avi
    The de-interlace filter is applied, but the subtitles don't show up. If I remove the "-vf pp=lb", the subtitles show up fine. Is this combination of options not allowed, or is my usage incorrect?

    Thanks...

  10. #10
    Join Date
    Feb 2010
    Beans
    1

    Re: Burning subtitles to video with mencoder

    hi
    does anybody know how to add visual effects to the subtitle text being played, such as text flys in from the left or right, comes in sideways or becomes 3d ect.. any effect of these does the job for me.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •