You are not logged in.

#1 2009-10-27 12:43:06

zowki
Member
From: Trapped in The Matrix
Registered: 2008-11-27
Posts: 582
Website

[SOLVED] Hard encode subtitles into MP4 file

I have an .mp4 video and .ass subtitles. How would I hard encode the subtitles on to the mp4 file so I can view it on my iPod with subtitles?

Last edited by zowki (2009-10-28 23:24:30)


How's my programming? Call 1-800-DEV-NULL

Offline

#2 2009-10-27 14:29:19

zowki
Member
From: Trapped in The Matrix
Registered: 2008-11-27
Posts: 582
Website

Re: [SOLVED] Hard encode subtitles into MP4 file

bump


How's my programming? Call 1-800-DEV-NULL

Offline

#3 2009-10-27 15:26:44

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: [SOLVED] Hard encode subtitles into MP4 file

Offline

#4 2009-10-27 20:59:05

madeye
Member
From: Denmark
Registered: 2006-07-19
Posts: 331
Website

Re: [SOLVED] Hard encode subtitles into MP4 file

Don't know if this is what you're looking for, but I found the following in the wiki

http://wiki.archlinux.org/index.php/Con … _subtitles


MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage

Offline

#5 2009-10-27 21:18:39

Themaister
Member
From: Trondheim, Norway
Registered: 2008-07-21
Posts: 652
Website

Re: [SOLVED] Hard encode subtitles into MP4 file

Okay, it's a bit dirty, but hey. Basically, it plays video from mplayer, and pipes the output (which should now include the .ass file) to x264 via fifo. It also encodes audio. This is for my PSP though, so you might need some different settings, etc. smile

#!/bin/bash

##
### PSPMP4: A simple video encoding tool for PSP video
##
#



###
## Main directory for where your PSP encodes will be stored
#
MP4DIR="/home/maister/psp-encodes"
#
##
###

if [ ! -d "$MP4DIR"/tmp ]
then
    mkdir "$MP4DIR"/tmp
fi

function help()
{
    echo "Usage: `basename $0` --threads/-t | --input/-i | --crf/-q (video quality, lower = better. default 22) | --abitrate/-ab (audio bitrate) | --output/-o (basename only) | --size/-s width:height | -x264 \"--options for x264 here\" | -mplayer \"-options for mplayer here\""
    echo ""
    echo "Example: `basename $0` -i 720p.mkv -o Episode5 -b 800 -ab 160"
    echo ""
    echo "This script provides sane defaults for encoding PSP video, and should suit most video clips. It is sufficient to just supply an input. A recent version of x264 is required, as this script uses the baseline profile, which is only supported in newer git-versions."

}

## Default values

TAG=`date +%Y%m%d-%T`
FILENAME=""
#BITRATE=250
CRF=22
AB=128
THREADS=auto
SCALE=480:270


##

if [ -z "$1" ]
then
    help
    exit 1
fi

while [ -n "$1" ]
do
    case "$1" in
        --threads | -t )
        shift
        THREADS="$1"
        shift
        ;;
        
        --input | -i )
        shift
        FILENAME="$1"
        shift
        ;;

        -ab | --abitrate )
        shift
        AB="$1"
        shift
        ;;

        -s | --size )
        shift
        SCALE="$1"
        shift
        ;;

        -x264 )
        shift
        X264OPTS="$1"
        shift
        ;;

        -mplayer )
        shift
        MPLAYEROPTS="$1"
        shift
        ;;
        
        --output | -o )
        shift
        TAG="$1"
        shift
        ;;

        --rate | -r )
        shift
        RATE="$1"
        shift
        ;;

        --crf | -q )
        shift
        CRF="$1"
        shift
        ;;

        * )
        help
        exit 1
        ;;
        
    esac

done

# Creates fifo-pipes for audio and video
mkfifo "$MP4DIR"/tmp/video$TAG.y4m
mkfifo "$MP4DIR"/tmp/audio$TAG.wav

# Encodes audio
faac -b $AB -w "$MP4DIR"/tmp/audio$TAG.wav &
mplayer $MPLAYEROPTS -vo null -vc null -ao pcm:file="$MP4DIR"/tmp/audio$TAG.wav:fast -nocorrect-pts "$FILENAME" &

sleep 2

x264 --profile main --deblock 1:1 --crf $CRF --level 3 --b-adapt 2 --partitions p8x8,b8x8,i4x4 --no-8x8dct --me umh --threads $THREADS --output "$MP4DIR"/tmp/video$TAG.264 "$MP4DIR"/tmp/video$TAG.y4m &        
    mplayer -vo yuv4mpeg:file="$MP4DIR"/tmp/video$TAG.y4m -benchmark -vf scale=$SCALE -vc ffh264, $MPLAYEROPTS -nosound "$FILENAME"

sleep 2

#Muxing into PSP-compatible MP4
ffmpeg -y -vcodec copy -acodec copy -i "$MP4DIR"/tmp/video$TAG.264 -i "$MP4DIR"/tmp/audio$TAG.m4a -f psp "$MP4DIR/$TAG.mp4"


rm "$MP4DIR"/tmp/video$TAG*
rm "$MP4DIR"/tmp/audio$TAG*

Offline

#6 2009-10-28 09:45:46

zowki
Member
From: Trapped in The Matrix
Registered: 2008-11-27
Posts: 582
Website

Re: [SOLVED] Hard encode subtitles into MP4 file

If it's piping Mplayer's output then it would take as long as the video's lengh right? I have a large batch of videos to convert so it might take days.


How's my programming? Call 1-800-DEV-NULL

Offline

#7 2009-10-28 10:05:46

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: [SOLVED] Hard encode subtitles into MP4 file

if you want hardcoded subs, you have to reencode, no way around that.


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#8 2009-10-28 10:16:27

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: [SOLVED] Hard encode subtitles into MP4 file

As an addition to what Rasi said (which is true), I found Avidemux2 to be a great tool for this stuff. I even use it on OSX at work, and at home I use it to convert high quality videos for my PSP. Never needed to add subtitles as I am fairly fluent in english, but I know it has the option to do so, and I've seen it work, it does a good job.
edit:
have a look at this http://www.youtube.com/watch?v=dxtxNGX6tJQ and this for subtitles http://www.youtube.com/watch?v=mNt6mEQ658s

Last edited by Lich (2009-10-28 10:20:14)


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#9 2009-10-28 14:05:59

zowki
Member
From: Trapped in The Matrix
Registered: 2008-11-27
Posts: 582
Website

Re: [SOLVED] Hard encode subtitles into MP4 file

Will try avidemux and report back if it works.

Edit: Avidemux did what I wanted. Thanks!

Last edited by zowki (2009-10-28 23:23:57)


How's my programming? Call 1-800-DEV-NULL

Offline

Board footer

Powered by FluxBB