User Tools

Site Tools


doc:appunti:linux:video:transcode

This is an old revision of the document!


Transcode

Conversione di un DivX danneggiato in XviD

Procedura utilizzata per correggere un file DivX danneggiato. Avidemux non era in grado di aprire il file.

Per cominciare con mplayer (che pare essere più bravo a decodificare file danneggiati) si è convertito in yuv4mpeg (vedere l'opzione -vo yuv4mpeg).

Con transcode si converte un file dal formato yuv4mpeg al formato XviD. Prima bisogna eseguire la prima passata (-R 1) durante la quale viene salvato il file divx4.log:

transcode -i stream.yuv -R 1 -y xvid -o /dev/null

Poi si esegue la seconda passata a bitrate variabile (-R 2), video encoder bitrate 6000 and keyframes every 250 frames (-w), formato audio mp3 (-N 0x55) encoder bitrate kBits/s (-b 96). Contestualmente si effettua il deinterlacing con il filtro smartyuv:

transcode -i stream.yuv \
    -J smartyuv=highq=1:diffmode=2:cubic=1:Blend=1:chromathres=4:threshold=8:doChroma=1 \
    -R 2 -w 6000,250 -y xvid \
    -V \
    -N 0x55 -b 96 \
    -o output.avi

Converting from Flash Video to XviD

Mplayer supports a very large set of video formats, including several closed codecs from the Windows platform. Using the youtube-dl script, we downloaded some clips from YouTube, which are in the Flash Video format.

The first, very simple recipe uses mencoder(1) to convert a Macromedia Flash Video to XviD/MP3 AVI in a single pass, with fixed bitrate (360 kbit/s in this example):

mencoder file.flv -oac copy -ovc xvid -xvidencopts bitrate=360 -of avi -o file.avi

The output audio codec is copy because flv should be already in mp3 format, otherwise specify mp3lame codec.

An insanely complicated recipe will use mplayer to extract the video and audio streams, then use transcode to convert the video to XviD (two pass, 400 kbit):

FILE=youtube_clip
mplayer -ao pcm:file=$FILE.wav -vo yuv4mpeg:file=$FILE.yuv $FILE.flv
transcode -i $FILE.yuv -R 1 -w 400 -y xvid -o /dev/null
transcode -i $FILE.yuv -R 2 -w 400 -y xvid -o $FILE.xvid
rm $FILE.yuv divx4.log

Finally we used avidemux to convert audio to mp3 and to mux audio and video into an avi file. FIXME How to use transcode for this final step?

How to extract subtitles from a DVD-Video into VobSub format

This seems to be the best method to extract subtitles from a DVD-Video.

The same operation can be accomplished with mencoder, but mencoder seems to produce different image data into the .sub file and slightly different timestamps into the index (.idx) file depending on the used video codec (-ovc option): strange enough, I got different outputs using copy and raw options. Transcode instead seems to be more deterministic.

VobSub is a well known subtitle format that saves subtitles nearly in the same format as it appears in DVD subtitle streams. From a technical point of view, VobSub saves subtitles as little images.

We can use mplayer to identify subtitle streams contained into the DVD, they are identified by an ID and a language:

mplayer -dvd-device $RIPDIR dvd://$TITLE -identify
...
ID_SUBTITLE_ID=0
ID_SID_0_LANG=it
ID_SUBTITLE_ID=1
ID_SID_1_LANG=en
ID_SUBTITLE_ID=2
ID_SID_2_LANG=it
...

In the following example you will extract subtitles from a DVD-Video using the transcode tools and the How to rip DVD subtitles with vobsub2srt scripts. The subtitles will be saved into the VobSub format. Two files will be generated: vobsubs-en.idx and vobsubs-en.sub. In the example 0x21 is 0x20 + the subtitle ID:

tccat -i $RIPDIR -T $TITLE -L | tcextract -x ps1 -t vob -a 0x21 > subs-en
subtitle2vobsub -o vobsubs-en -i $RIPDIR/VIDEO_TS/VTS_01_0.IFO < subs-en

The tccat command will concatenate all the files that compose the specified $TITLE to the standard output. Files are taken from the directory where the DVD-Video was ripped ($RIPDIR).

The tcextract command extract the requested stream; ps1 stands for MPEG private stream (subtitles), the source type (-t vob) must be specified when reading from standard input, the required track (-a 0x21) must also be specified.

With How to rip DVD subtitles with vobsub2srt you can convert VobSub subtitles into single .pgm images.

avisync

This is a tool that allow to adjust audio/video syncronization witout re-encode audio and video streams, you must specify time shift in frames. If count is positive, audio starts with audio frame count at the beginning of the AVI-file. If count is negative, audio is prepended count padding frames.

avisync -i input.avi -o output.avi -n -10

Converting AC3 audio to WAV

AC3 audio (aka Dolby Digital) is a lossy compression algorithm, so converting from and to this format always introduces some more loss. Neverthless I had to edit a DVD audio track with Audacity, so I need to convert it from AC3 into something that Audacity can open. The ac3 audio track was extracted with mplayer and the -dumpaudio option.

transcode -i title1.ac3 -y null,wav -o title1.wav
doc/appunti/linux/video/transcode.1253288280.txt.gz · Last modified: 2009/09/18 17:38 by niccolo