Cookbook
From ActiveArchives
Audio
Subtitles
"Burning" subtitles into a video file (mencoder)
mencoder should accept most of the subtitle options available to mplayer. The tool is useful to 'burn' subtitles onto a video directly, as using mplayer becomes a more complicated, two-step process. The following line will burn subtitles into an output video file using the Liberation Serif font:
mencoder original_video.avi -sub original_video.srt -o burned_video.avi -subfont 'Liberation Serif' -oac copy -ovc lavc -lavcopts vbitrate=1200
Adding additional command-line switches relating to the subtitle files should work flawlessly, except for SSA/ASS-specific features, which apparently are only available in very recent versions of mencoder (meaning the latest source must be compiled). Even then there are no guarantees that it will look perfect.
For SSA/ASS, then, you can use the multi-stage mplayer/mencoder hybrid process:
mplayer original_video.avi -dumpaudio mplayer -vo yuv4mpeg -ass original_video.avi -sub original_video.srt -subfont 'Liberation Serif' | mencoder - -ovc lavc -lavcopts vbitrate=1200 -o burned_video.avi mencoder -oac copy -ovc copy -o 'final_burn.avi' -audiofile 'stream.dump' 'burned_video.avi'
to try: mencoder moviesource.avi -sub moviesubtitles.ssa -ass -ass-color FFFF0000 −ass−font−scale 3 -o movie output.mp4 -oac lavc -lavcopts acodec=libfaac:abitrate=128 -ovc lavc -lavcopts vcodec=libx264:vbitrate=1200
Convert .srt subtitles into .ssa allowing styling
SSA/ASS stands for SubStation Alpha: http://en.wikipedia.org/wiki/SubStation_Alpha More tags available here: http://aegisub.cellosoft.com/docs/ASS_Tags It allows better control on the styling of subtitles: position, fonts, italics, bold You can modify the styles per sentence or inside the sentences as well. Layers are also available. And stylesheets too!
The srt2ssa.sh script makes several search and replace for the subtitles fit the SSA format. Make it executable by `chmod +x srt2ssa.sh`.
The header is an example header to which we will append the subtitles. Be free to change the options there.
#!/bin/bash cat << HEADER Collisions: Normal PlayResX: 200 PlayResY: 200 PlayDepth: 0 Timer: 100,0000 Video Aspect Ratio: 0 Video Zoom: 6 Video Position: 0 [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding Style: MyStyle, DejaVu Sans Bold,28,&H00B4FCFC,&H00FF0000,&H000000FF,&H8000FF00,-1,0,0,0,100,100,0.00,0.00,1,1.00,2.00,1,30,30,30,0 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text HEADER # cat "$1" | \ sed "s/^[0-9]*$//g" | \ sed s/\ --\>\ /,/g | \ sed "s/\([0-9][0-9]\),\([0-9][0-9][0-9]\)/\1.\2/g" | \ sed "s/\([0-9].*[0-9]\)/Dialogue: 1,\0,MyStyle,NTP,0000,0000,0000,,/g" | \ tr -d "\n" | \ sed "s/Dialogue/\n\0/g" | \ sed "s/\(,\)[0-9]\([0-9]:\)/\1\2/g"
Usage
./srt2ssa.sh < your_subtitle_file.srt > output.ssa
To use in mplayer:
mplayer your_video.avi -ssa -sub output.ssa
Making a stylesheet for each person in an interview
The script is detecting every sentence beginning like this: `Name:` and apply to these sentences and the following until the next name a specific stylesheet.
#! /usr/bin/python import fileinput import re speaker="MyStyle" for l in fileinput.input(): r = re.search(r".+,,(.+):.+", l) if r is None: l = re.sub(r"MyStyle", speaker, l) print l else: speaker = r.groups()[0] l = re.sub(r"MyStyle", speaker, l) print l
After we get a styled ssa file, we can just change the styles of each character (see the "Format" to understand how to change the options):
[V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding Style: Myriam, DejaVu Sans Bold,14,&H00B4FCFC,&H00FF0000,&H00000008,&H80000008,-1,0,0,0,100,100,0.00,0.00,1,1.00,2.00,1,30,30,100,0 Style: Hahn, DejaVu Serif Bold,14,&H00B4FCFC,&H00B4FCFC,&H00000008,&H80000008,-1,0,1,0,100,100,0.00,45.00,1,1.00,2.00,2,30,30,100,0 Style: David, DejaVu Sans Bold,28,&H00B4FCFC,&H00FF0000,&H00000008,&H80000008,-1,0,0,0,100,100,0.00,0.00,1,1.00,2.00,1,30,30,100,0
Usage
With an .ssa file (see previous section to convert an srt file to an ssa one): ./ssa2voices.py your_subtitles_file.ssa >| multiple_voices.ssa
To use with mplayer: mplayer your_video.avi -ssa -sub multiple_voices.ssa
How to I convert to OGG?
Converting a Video to OGG/Theora
An example of a simple BASH script to transcode a file, using ffmpeg2theora.
The resulting movie uses OGG as the file (or container) format, and the Theora codec for the video data.
#!/bin/bash -x # # makeogv # i=$1 base=`basename $i` o=${base%.*}.ogv # ffmpeg -y -i "$i" -ac 2 -ab 80 -ar 48000 -acodec libvorbis -qscale 9 -r 15 -s 320x240 "$o" ffmpeg2theora -o "$o" --channels=2 --samplerate=48000 -x 320 -y 240 "$i"
Converting Audio to OGG/Vorbis
Here is an example of using ffmpeg to convert a WAV audio file into OGG/Voribs. Note that OGG is the file or "container" format, and "vorbis" is the actual compression technique (codec) for the audio.
This command uses the -ss and -t options to start at 3 minutes into the file (3*60 seconds), with a duration of 60 seconds.
ffmpeg -i xabier.wav -ss 180 -t 60 -acodec libvorbis -ab 192000 xabier_sample.ogg
How can I convert my movie into the flash (FLV) format?
An example of a simple BASH script to transcode a file, using ffmpeg.
#!/bin/bash -x # # makeflv # i=$1 base=`basename $i` o=${base%.*}.flv ffmpeg -y -i "$i" -ab 48 -ar 22050 -qscale 9 -r 15 -s 320x240 "$o"
Editing with mplayer / mencoder
Extracting a clip (cutting)
playing a particular portion in this case endpos determines the total duration of the shot (end position relative to adjusted start position)
mplayer -ss 2:05 -endpos 3 dvgrab-001.avi
Make an edit (extract to new file)
note -oac copy, -ovc copy, KEEP THE ORIGINAL FORMAT (fastest & no recompression/change of data, video quality unchanged) Here, we first make a subdirectory (clips) to hold (& later make selecting) the edits.
mkdir clips mencoder -ss 2:05 -endpos 3 dvgrab-001.avi -oac copy -ovc copy -o clips/01.avi
Make some more clips...
mencoder -ss 4:00 -endpos 3 dvgrab-001.avi -oac copy -ovc copy -o clips/02.avi mencoder -ss 2:00 -endpos 3 dvgrab-001.avi -oac copy -ovc copy -o clips/03.avi
View your "rough cut"...
mplayer clips/*
Try a random edit?
mplayer -shuffle clips/*
(or even ;)
mplayer -flip -shuffle clips/*
PERFORMING the edit
mencoder -oac copy -ovc copy -o edit.avi clips/*
Controlled loop, 2 times:
mencoder -oac copy -ovc copy -o edit2.avi edit.avi edit.avi
Example of "Appending multiple AVI" from net:
As a side-effect, the broken AVI fixer function enables MEncoder to append 2 (or more) AVI files:
cat 1.avi 2.avi | mencoder -noidx -ovc copy -oac copy -o output.avi -
Note: This expects 1.avi and 2.avi to use the same codecs, resolution, stream rate etc, and at least 1.avi must not be broken. You may need to fix your input AVI files first, as described above.
http://web.njit.edu/all_topics/Prog_Lang_Docs/html/mplayer/encoding.html
Compressing to a Flash Video(flv)
ffmpeg -y -i IN.OGG -ab 48 -ar 22050 -qscale 9 -r 15 -s 320x240 OUT.FLV
Capturing DV format video with dvgrab
dvgrab -format rawTranscoding to DV
using ffmpeg to go DV (avi)
ffmpeg -y -i dvgrab-001.avi -t 1 -s 640x480 -sameq -vcodec mjpeg -acodec copy dvmjff.avi then the whole movie mencoder -oac pcm -ovc lavc -lavcopts vcodec=mjpeg -o dvgrab0001mjpeg.avi dvgrab-001.avi mencoder -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=600 -o output.avi input.flv
How do I convert a Movie to Images
with ffmpeg
ffmpeg -i rearwindow.avi -f image2 -y -r .01 -an rearwindow%06d.jpg
with mplayer
mplayer -vo png rearwindow.avi
Use sstep to do a time lapse / select one frame per second
mplayer -sstep 25 -vo png rearwindow.avi
(see: mplayer -vo help for other opts)
How do I convert images to a movie?
Slideshow.py is an example using Python, ImageMagick, and mencoder to convert images into a "slideshow" movie.
Screen Grabbing
ffmpeg X11 grabbing!
ffmpeg -f x11grab -s cif -i :0.0 /tmp/out.mpg 0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. ffmpeg -f x11grab -s cif -i :0.0+10,20 /tmp/out.mpg 0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x−offset and 20 the y−offset for the grabbing.
How can I make audio files from a DVD?
Recently I wanted to make some individual audio files (MP3's) of audio on an "supplementary" audio track of a DVD.
I used mplayer's -dumpaudio option to select the particular audio track I had in mind:
mplayer -aid 130 -dumpaudio -vo null VTS_01_2.VOB
Then I used ffmpeg to convert the whole thing to mp3 format (this step is necessary only because I didn't figure out how to play the dump file with mplayer -- kind of weird that it doesn't recognize it's own dump format -- probably you can manually instruct it as to the format, but in any case ffmpeg recognizes and converting to mp3 allows mplayer to play it again).
ffmpeg -i stream.dump -ar 192000 stream.mp3
Then I figured out a start and end time using mplayer, subtract start from end to get duration, and plug this into ffmpeg. Apparently ffmpeg (version specific?) doesn't deal with time codes (like 3:18), and so values for start (-ss) and duration (-t) need to be given as seconds (so 3:19 becomes 199).
ffmpeg -i stream.mp3 -ss 44 -t 199 -y -ab 192000 03_NameMe.mp3
What are other good resources on the web?
- http://commons.wikimedia.org/wiki/Help:Converting_video
- http://internetarchive.wordpress.com/2008/11/25/fast-and-reliable-way-to-encode-theora-ogg-videos-using-ffmpeg-libtheora-and-liboggz/
Questions that are not on this page, but should be
- How to use the HTML5 <video> tag
- How to create an RSS feed
Quick and dirty way of installing ffmpeg with all kinds of necessary libs for mp4
For the current version of AA, we need a particular type of mp4 (made with a compiled version of ffmpeg to run this ffmpg on the big video computer: constant@constant-desktop:~/Downloads/ffmpeg-0.6$ /opt/ffmpeg_x264
This is how you compile it
128 sudo aptitude search x264
129 sudo apt-get install libx264-dev
130 sudo aptitude search faad
131 sudo apt-get install libfaad-dev
132 sudo apt-get install libfaac-dev
133 ls
134 cd Downloads/
135 ls
136 tar xvzf ffmpeg-0.6.tar.gz
137 cd ffmpeg-0.6/
138 ./configure --help
139 ffmpeg
142 ./configure --enable-libx264 --enable-libfaad --enable-libfaac --enable-gpl --enable-nonfree
143 make
144 ./ffmpeg
145 sudo cp ffmpeg /opt/ffmpeg_x264
146 /opt/ffmpeg_x264
---
Making MP4 videos with ffmpeg
Make sure you've compiled ffmpeg with lib-faad/faac and libx264
For a 4:3 ratio movie:
ffmpeg -y -i "MYMOVIE.FLV" -acodec libfaac -ab 64k -ac 1 -vcodec libx264 -b 500k -bt 500k -threads 0 -vpre libx264-hq -s 384x288 -aspect 4:3 -r 25 -g 25 -keyint_min 25 "MYMOVIE.mp4"
For a 16:9 ratio movie:
ffmpeg -y -i "MYMOVIE.FLV" -acodec libfaac -ab 64k -ac 1 -vcodec libx264 -b 500k -bt 500k -threads 0 -vpre libx264-hq -s 480x272 -aspect 16:9 -r 25 -g 25 -keyint_min 25 "MYMOVIE.mp4"