The Linux Video Booklet

Table of Contents

last revision
08 August 2015, 4:00pm
book quality
just begun

:

This booklet is about using, creating and editing video on a computer running the Linux operating system, all many of its techniques may be applicable to computers using other operating systems. This booklet will attempt to cover both command-line techniques for manipulating video as well as graphical tools (such as Blender) which are available for creating and editing video. However this is quite a large topic and may have to be split into sub-books

Playing Videos ‹↑›

play a dvd

 mplayer dvd://1
 mplayer dvd://

play the 3rd track, this could be trailer for example

 mplayer dvd://3 -dvd-device /dev/sr0

MPLAYER AND MPLAYER2

mplayer is a very very capable command line video player supporting many formats. 'mplayer2' is a fork of the mplayer project with some undefined differences. The mplayers have many keystrokes for controlling video playback as well as an enormous number of command line options.

Joining Videos ‹↑›

The following runs into trouble if the mp4 files have different encoding parameters.

mpg files can be joined with a simple 'cat'

 cat file1.mpg file2.mpg file3.mpg >> newfile.mpg

join 'one.mp4' and 'two.mp4' and save as 'test.mp4'

 mencoder -oac pcm -ovc copy first.mp4 second.mp4 -o test.mp4

join 2 avi videos mencoder -oac copy -ovc copy video1.avi video2.avi -o final.avi

join vob files with all (language) audio streams, encode h264, flac

 ffmpeg -i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB -map 0:v -map 0:a

flac is lossless audio, and h264 is a nearly free video encoding (see 'theora', vp8, dirac for alternatives)

Sound ‹↑›

www: http://bumble.sf.net/books/linux-sound/linux-sound-book.txt
More comprehensive information about using sound with the Linux operating system.

Sound Conversion ‹↑›

create a file 'f.flac', a lossless compression of s.wav

 flac s.wav

convert from wav to ogg

 oggenc trac9.wav

convert from wav to ogg with highest quality

 oggenc -q10 trac9.wav

convert from flac to ogg

 oggenc trac9.flac

convert a wav file 'track9.wav' to mp3 format with variable bitrate

 lame -h -V 6 track9.wav track9.mp3

encode from wav to mono channel mp3 sampled 22050 herz, bitrate 64k

 ffmpeg -i test.wav -acodec libmp3lame -ac 1 -ar 22050 -ab 64k test.mp3

It is probably better and simpler to use lame to encode to mp3

show what audio file formats are supported by ffmpeg

 ffmpeg -formats

Downloading ‹↑›

download the amelie song 'comptine dautre ete'

 youtube-dl

download a chopin song in flv format at 480p

 youtube-dl -f 35 http://www.youtube.com/watch?v=GZbuA7r17uk

WebM is a new patent free format sponsored by google and may be difficult to play unless you have a very up-to-date media player

The format codes for the -f switch are WebM video at 480p: 43 WebM video at 720p: 45 H264 video in MP4 container at 480p: 18 H264 video in MP4 container at 720p: 22 H264 video in MP4 container at 1080p: 37 H264 video in FLV container at 360p: 34 H264 video in FLV container at 480p: 35 H263 video at 240p: 5 3GP video: 17

create an audio only file from a youtube video

 youtube-dl -extract-audio -f 35 http://www.youtube.com/watch?v=GZbuA7r17uk

create an audio only file in mp4 at 480p using the video title

 youtube-dl -extract-audio -t -f 35 http://www.youtube.com/watch?v=GZbuA7r17uk

clean up youtube file names given by 'youtube-dl' -t option

 rename 'y/A-Z_/a-z./' *.flv *.mp3 *.mp4
 rename 's/-[^\.]*//' *.flv *.mp3 *.mp4

Analysing Video ‹↑›

show information about the avi video file 'green.avi' (duration, encoding etc)

 ffmpeg -i green.avi

show information with mplayer, dont actually play anything

 mplayer -endpos 0 -vo null -ao null video.mp4 | less

show how long an mpg file is

 ffprobe -show_format -show_streams aa.mpg | grep duration

Duration ‹↑›

find out how long an mpg runs for

 mediainfo aa.mpg | grep -i duration

Video Sound ‹↑›

just listen to the sound in 'green.avi', dont watch the video

 mplayer -vo null green.avi

find out what audio format is contained in a video file 'vid.flv'

 ffmpeg -i vid.flv | grep stream

extract audio from 'eg.flv' video and encode it in the same format (mp3)

 ffmpeg -i eg.flv -vn -acodec copy eg.mp3

youtube video download tools
clive - a perl script
cclive - the same written in C
youtube-dl - works for me

extract audio from video 'eg.avi' and stereo encode for burning to cd

 ffmpeg -i eg.avi -vn -acodec pcm_s16le -ar 44100 -ac 2 eg.wav

extract only the video from 'eg.flv' (without the audio)

 ffmpeg -i eg.flv -an -vcodec copy silent.flv

encode an mpeg video to the youtube flv format

 ffmpeg -i mov0001.mpg -ar 22050 -acodec libmp3lame -ab 32k -r 25 -s 320x240 -vcodec flv eg.flv

Extracting Video ‹↑›

extract audio from vob in folder

 for i in *.VOB; do mplayer "$i" -ao pcm:file="${i%.*}.wav"; done

Dvd ‹↑›

Playing Dvds ‹↑›

play a particular chapter ("scene") from a dvd track

 mplayer dvd://6 -dvd-device /dev/sr0 -chapter 3

Chapters ‹↑›

show the chapters and lengths from a track 6 of a dvd

 lsdvd -t 6 -c /dev/sr0

Analysing Dvds ‹↑›

The 'tracks' on a dvd are normally trailers, advertisements copywrite info, etc. There is usually one main track which is the actual video. That main track will usually have 'chapters' which are just sections of the video.

ffmpeg important options
-i - show information
-vn - dont use the video
-an - dont use the audio
-acodec copy - use the same audio encoding as decoding
-vcodec copy - use the same video encoding as decoding
-s 320x240 - encode video for screen size 320x240
-r 25 - encode video at 25 frames per second
-formats - show available formats

install the lsdvd utility

 sudo apt-get install lsdvd

show lots of info about a dvd

 lsdvd /dev/sr0

show detailed info about audio tracks on a dvd

 lsdvd -a /dev/sr0

show the chapters and lengths from a track 6 of a dvd

 lsdvd -t 6 -c /dev/sr0

print number of tracks, audio information etc.

 mplayer -dvd-device /dev/sr0 -nocache -identify dvd:// -vo null -ao null -frames 0 | less

Ripping Or Copying Dvds ‹↑›

https://xinn.org/linuxdvdrippingguide.html a guide

try handbrake for a gui tool http://lifehacker.com/5773000/how-to-rip-dvds-with-handbrake

install ffmpeg, mplayer, lsdvd etc

Try to locate the 'main' track on the dvd.

 lsdvd /dev/sr0

And look for the longest track, or the track with numerous chapters

Find a small chapter on the main dvd track with 'lsdvd' (see above) then time how long it takes to dump it, to get an idea of how long it will take to dump the whole track.

For example, on an old thinkpad an 8m 35s dvd chapter dumps in 1m 19 secs. For a 1hour50m video, the mpg file size is 411 megabytes

dump chapter 12 of track 6 and save as '12.mpg' (and time it)

 time mplayer dvd://6 -dvd-device /dev/sr0 -chapter 12 -dumpstream -dumpfile 12.mpg

extract an entire dvd track and save to 'out.mpg'

 mplayer dvd://6 -dvd-device /dev/sr0 -dumpstream -dumpfile out.mpg

The process below is really quite slow, will take hours, but the resulting mp4 file should be much, much smaller than the mpg file

recode 'out.mpg' into mp4 format and save as 'out.mp4'

 ffmpeg -i video.mpg -acodec libmp3lame -vcodec libx264 -crf 26 -threads 0 out.mp4

dvd ripping with audio language "spanish"

 mplayer dvd://1 -dumpstream -alang es -dumpfile video.mpg && ffmpeg -i video.mpg -acodec libmp3lame -alang spa -vcodec libx264 -crf 26 -vpre hq -threads 0 video.mp4

extract video with a particular audio track

 mplayer dvd://1 -aid 128 -dvd-device DVD.iso -dumpstream -dumpfile Title_1.vob

dump chapter by chapter

 for i in {1..13}; do echo "getting chapter $i"; mplayer dvd://6 -dvd-device /dev/sr0 -dumpstream -dumpfile -chapter $i untouchables.chap.$i.mpg ; done

maybe better way

 mplayer dvd://6 -dvd-device /dev/sr0 -dumpstream -dumpfile -chapter 1-13 untouchables.mpg

Vobcopy ‹↑›

The mplayer dump technique may have problems with subtitles, not sure. So it may be better to copy all the vobs and use ffmpeg

copy all vobs from dvd with

 vobcopy

then concatenate

cat VTS_01_1.VOB VTS_01_2.VOB ...> ~/temp/mymovie.VOB

then ffmpeg to create a mkv format movie

 ./ffmpeg -i mymovie.vob -c:v copy -c:a copy -c:s copy -map 0 mymovie.mkv

http://stackoverflow.com/questions/19200790/converting-dvd-image-with-subtitles-to-mkv-using-avconv more info about ffmpeg with vobs

Two Pass With Mencoder ‹↑›

first pass

 mencoder dvd://6 -dvd-device /dev/sr0 -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:v4mv:mbd=2:trell:vbitrate=900:vpass=1:turbo=1 -oac copy -o /dev/null

second pass

 mencoder -dvd-device /dev/sr0 dvd://1 -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:v4mv:mbd=2:trell:vbitrate=900:vpass=2 -oac mp3lame -lameopts vbr=3 -o Something-About-Mary.avi

Audio In Dvds ‹↑›

show detailed info about audio tracks on a dvd

 lsdvd -a /dev/sr0

extract the audio from a dvd quickly, save to audiodump.wav

 mplayer dvd://3 -dvd-device /dev/sr0 -vc null -vo null -ao pcm:fast

Audio In Video ‹↑›

tools
lsdvd - just whats needed
mediainfo - really good does everything
mplayer - use the '-identify' switch
Cycle through the available audio tracks.

recode 'eg.flv' with the same audio/video encoding but a different screen size

 ffmpeg -i eg.flv -acodec copy -s 320x240 -vcodec flv silent.flv

convert an mpeg video to 'flv', using only 128 seconds after 10 minutes

 ffmpeg -i eg.mpg -acodec copy -r 25 -s 320x240 -vcodec flv -ss 00:10:00 -t 128 eg.flv

encode from mpeg to flv format breaking when file size 10M is reached

 ffmpeg -i eg.mpg -acodec copy -vcodec flv -fs 10485760 eg.flv

encode 'eg.avi' movie to television mpeg suitable for pal format tv.

 ffmpeg -i eg.avi -target pal-vcd eg.mpg

extract audio and video of an flv video into separate files

 ffmpeg -i eg.flv -vcodec mpeg2video eg.m2v -acodec copy eg.mp3

create a video 'new.flv' combining audio and video, offseting audio 1/2 a second

 ffmpeg -i eg.mp3 -itsoffset 00:00:00.5 -i eg.m2v new.flv

In this recipe the audio is delayed by 1/2 second

create a video 'new.flv' combining audio and video, offseting audio 1/2 a second

 ffmpeg -i eg.m2v -itsoffset 00:00:00.5 -i eg.mp3 new.flv

In the command above the video is delayed by half a second

audio keystrokes
# - (DVD Blu-ray, MPEG, Matroska, AVI and libavformat only)

split an avi video into chunks

 avisplit

split mpg video into chunks

 mpgtx

www: handbrake
a graphical tool for converting video formats

Analysing Audio In Video ‹↑›

show some audio info for a dvd

 mplayer dvd://3 -dvd-device /dev/sr0 -vo null -ao null -endpos 0 | grep audio

Extracting Audio From Video ‹↑›

look for audio tracks on dvd ---- audio stream: 0 format: ac3 (5.1) language: en aid: 128. audio stream: 1 format: ac3 (5.1) language: en aid: 129.

,,,

extract audio from track 3 of dvd, save as audiodump.wav

 mplayer dvd://3 -dvd-device /dev/sr0 -vc null -vo null -ao pcm

extract audio from track 3 of dvd, save as s.wav

 mplayer dvd://3 -dvd-device /dev/sr0 -vc null -vo null -ao pcm:file=s.wav

extract all audio from vobs in a folder

 for i in *.VOB; do mplayer "$i" -ao pcm:file="${i%.*}.wav"; done

play video with particular audio track

 mplayer dvd://1 -aid 128 -dvd-device DVD.iso

Formats ‹↑›

www: wav
uncompressed
www: flac
(free lossless audio codec) good lossless format for storage, more compressed than wav
www: ogg
good for streaming, lossy compression, no patent

Video ‹↑›

play high-res video files on a slow processor

 mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all

some preset targets with ffmpeg
ntsc dvd
vcd
dvd
dv

www: deb:
flashblock an add on for firefox (et al) which replaces flash content with a button to play the content.
Dump dvd from a different machine onto this one.
 ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso

Use mplayer to save video streams to a file

 mplayer -dumpstream -dumpfile "yourfile" -playlist "URL"

external projector for presentations

 xrandr --auto

Download Apple movie trailers

 wget -U "QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)" `echo http://movies.apple.com/movies/someHDmovie_720p.mov | sed 's/\([0-9][0-9]\)0p/h\10p/'`

Remux an avi video if it won't play easily on your media device

 mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi

Create multiple mp4 files using avidemux

 for i in *;do avidemux --video-codec Xvid4 --audio-codec mp3 --load "${i}" --save "`echo "$i" | sed -e 's/\....$//'`.done.mp4" --quit; done

FLV to AVI with subtitles and forcing audio sync using mencoder

 mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv

 mplayer dvd:// -softvol -softvol-max 500

play audio stream and video stream in two different mplayer instances

 mplayer test.mp3 < /dev/null & mplayer test.avi -nosound -speed 1.0884

uncompress a movie 'eg.rar' (in .rar archive) and play it

 unrar p -inul eg.rar | mplayer -

stream a youtube video directly from the web to mplayer

 id="dMH0bHeiRNg";mplayer -fs http://youtube.com/get_video.php?video_id=$id\&t=$(curl -s http://www.youtube.com/watch?v=$id | sed -n 's/.*, "t": "\([^"]*\)", .*/\1/p')

view the video file 'eg.avi' using only ascii characters

 mplayer -vo aa eg.avi

Video And Audio ‹↑›

removing syncronization problems between audio and video

 ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv

Converting Video Formats ‹↑›

some video formats
h.264 - an open standard used by apple
ogv
mp4
flash - a proprietary thing not good

MP4 CONVERSION ....

The process below is really quite slow, will take hours, but the resulting mp4 file should be much, much smaller than the mpg file, and mp4 is youtube compatible

recode 'out.mpg' into mp4 format and save as 'out.mp4'

 ffmpeg -i video.mpg -acodec libmp3lame -vcodec libx264 -crf 26 -threads 0 out.mp4

Youtube Format ‹↑›

rip dvd to youtube ready mpeg-4 avi file using mencoder

 mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0

Image To Video ‹↑›

convert (almost) any image into a video

 ffmpeg -loop_input -f image2 -r 30000/1001 -t $seconds -i frame/$num.ppm -y frame/%02d.mpeg 2>/dev/null

Convert multiple files using avidemux

 for i in `ls`;do avidemux --video-codec Xvid4 --load $i --save $i.mp4 --quit; done

Convert wmv into avi

 mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi

create a thumbnail from a video file

 thumbnail() { ffmpeg -itsoffset -20 -i $i -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x272 ${i%.*}.jpg }

convert .flv flash video to the '.3gp' format

 ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp

convert a flv video file to avi using mencoder

 mencoder your_video.flv -oac mp3lame -ovc xvid -lameopts preset=standard:fast -xvidencopts pass=1 -o your_video.avi

Convert video files to XviD

 mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o "$1".avi

Rip a DVD to AVI format

 mencoder dvd://1 -aid 128 -o track-1.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4

convert a DVD to YouTube-ready "watermarked" MPEG-4 AVI file

 mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc lavc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o output.avi dvd.avi

Convert a VMWare screencast into a flv file

 mencoder -of avi -ovc lavc movie.avi -o movie2.avi; ffmpeg -i movie2.avi -r 12 -b 100 movie.flv

Video Editing Programs ‹↑›

Kino, Cinelerra, Avidemux, Kdelive, Lives, Lumiera, Pitivi, Open Movie Editor

tools
ffmpeg - good command line tool
mencoder - part of the mplayer suite
avidemux - graphical tool

Extract audio track from a video file using mencoder

 mencoder -of rawaudio -ovc copy -oac mp3lame -o output.mp3 input.avi

Webcam Video ‹↑›

www: qmotion
motion detection for webcams
webcam player in ascii art
 gst-launch v4l2src ! aasink

View webcam output using GStreamer pipeline

 gst-launch-0.10 autovideosrc ! video/x-raw-yuv,framerate=\(fraction\)30/1,width=640,height=480 ! ffmpegcolorspace ! autovideosink

webcam view with vlc

 cvlc v4l2:// &

mirror from your laptop + webcam (fullscreen+grab)

 mplayer -fs -vf screenshot,mirror tv://

view the webcam output using mplayer

 mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2

Desktop Video ‹↑›

This section refers to recording video of what is happening on the computer screen. It is equivalent to the 'screenshot'.

capture a video of a linux desktop

 ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg

Compressing Video ‹↑›

convert an avi video into a gif animation

 convert -quiet -delay 1 plane.avi plane.gif

convert an avi to gif with a colour map and no dithering for more compression

 convert -quiet -delay 1 plane.avi +dither -map colormap_332.png plane_ugc_nd.gif

use ordered dithering for good compression and quality

 convert -quiet -delay 1 plane.avi -ordered-dither o8x8,8,8,4 +map plane_od.gif

DOCUMENT-NOTES:

video tools
vcdimager - A VideoCD (VCD) image mastering and ripping too