% ------------------------------------------- % latex generated by: booktolatex.cgi % from source file : ../htdocs/books/linux-video/linux-video-book.txt % on: 20 April 2024, 12:49am % querystring: books/linux-video/linux-video-book.txt % document-root: /var/www/html % script-name: /cgi-bin/booktolatex.cgi % Server-name: bumble.sourceforge.net % Sed-script: booktolatex.sed % ------------------------------------------- \documentclass[a4paper,12pt]{article} \usepackage[margin=0.4cm,noheadfoot]{geometry} \usepackage{color} %% to use colours, use "xcolor" for more \usepackage{multicol} %% for multiple columns \usepackage{keystroke} %% for keyboard key images \usepackage[toc]{multitoc} %% for multi column table of contents \usepackage{tocloft} %% to customize the table of contents \setcounter{tocdepth}{2} %% only display 2 levels in the contents \setlength{\cftbeforesecskip}{0cm} %% make the toc more compact \usepackage{listings} %% for nice code listings %\lstset{language={}, \lstset{language=, %% define special comment delimiters '##(' and ')' moredelim=[s][\color{grey}\itshape\footnotesize\ttfamily]{~(}{)}, basicstyle=\ttfamily, %% fixed pitch font xleftmargin=1cm, %% margin on the left outside the frames breaklines=true, %% break long code lines breakatwhitespace=false, %% break long code lines anywhere breakindent=10pt, %% reduce the indent from 20pt to 10 postbreak=\mbox{{\color{blue}\small$\Rightarrow$\space}}, %% mark with arrow showstringspaces=false, %% dont show spaces within strings framerule=5pt, %% thickness of the frames rulecolor=\color{lightgrey}, frame=l} %% source code settings \usepackage{graphicx} %% to include images \usepackage{fancybox} %% boxes with rounded corners \usepackage{wrapfig} %% flow text around tables, images \usepackage{tabularx} %% change width of tables \usepackage[table]{xcolor} %% alternate row colour tables \usepackage{booktabs} %% for heavier rules in tables \usepackage[small,compact]{titlesec} %% sections more compact, less space \usepackage{enumitem} %% more compact and better lists \setlist{noitemsep} %% reduce list item spacing \usepackage{hyperref} %% make urls into hyperlinks \hypersetup{ %% add "pdftex," if only pdf output is required colorlinks=true, %% set up the colours for the hyperlinks linkcolor=black, %% internal document links black urlcolor=black, %% url links black filecolor=red, citecolor=red, bookmarks=true, pdfpagemode=UseOutlines} % define some colours to use \definecolor{lightgrey}{gray}{0.70} \definecolor{grey}{gray}{0.30} \titleformat{\section}[frame] %% titlesec: create framed section headings {\normalfont} {\filleft \footnotesize \enspace Section \thesection\enspace\enspace} {3pt} {\bfseries\itshape\filright} \title{The Linux Video Booklet} \author{} \date{08 August 2015, 4:00pm} \setlength{\parindent}{0pt} % \setlength{\parskip}{1ex} % label lists with stars \renewcommand{\labelitemi}{$\star$} \begin{document} \centerline{\Large \bf The Linux Video Booklet} \medskip \begin{center} {\huge ``}\textit{}{\huge ''} \textsc{} \end{center} % ----------------------------------- % the toc should be 2 columns because of the \multitoc package \tableofcontents 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 \section{Playing Videos} \emph{ Play a dvd } \begin{lstlisting} mplayer dvd://1 \end{lstlisting} \begin{lstlisting} mplayer dvd:// \end{lstlisting} \emph{ Play the 3rd track, this could be trailer for example } \begin{lstlisting} mplayer dvd://3 -dvd-device /dev/sr0 \end{lstlisting} 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. \section{Joining Videos} The following runs into trouble if the mp4 files have different encoding parameters. \emph{ Mpg files can be joined with a simple 'cat' } \begin{lstlisting} cat file1.mpg file2.mpg file3.mpg >> newfile.mpg \end{lstlisting} \emph{ Join 'one.mp4' and 'two.mp4' and save as 'test.mp4' } \begin{lstlisting} mencoder -oac pcm -ovc copy first.mp4 second.mp4 -o test.mp4 \end{lstlisting} \emph{ Join 2 avi videos } mencoder -oac copy -ovc copy video1.avi video2.avi -o final.avi \emph{ Join vob files with all (language) audio streams, encode h264, flac } \begin{lstlisting} ffmpeg -i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB -map 0:v -map 0:a \end{lstlisting} flac is lossless audio, and h264 is a nearly free video encoding (see 'theora', vp8, dirac for alternatives) \section{Sound} \begin{description}[labelindent=1cm, leftmargin=2cm, style=nextline] \item[\url{http://bumble.sf.net/books/linux-sound/linux-sound-book.txt}] More comprehensive information about using sound with the Linux operating system. \end{description} \subsection{Sound Conversion} \emph{ Create a file 'f.flac', a lossless compression of s.wav } \begin{lstlisting} flac s.wav \end{lstlisting} \emph{ Convert from wav to ogg } \begin{lstlisting} oggenc trac9.wav \end{lstlisting} \emph{ Convert from wav to ogg with highest quality } \begin{lstlisting} oggenc -q10 trac9.wav \end{lstlisting} \emph{ Convert from flac to ogg } \begin{lstlisting} oggenc trac9.flac \end{lstlisting} \emph{ Convert a wav file 'track9.wav' to mp3 format with variable bitrate } \begin{lstlisting} lame -h -V 6 track9.wav track9.mp3 \end{lstlisting} \emph{ Encode from wav to mono channel mp3 sampled 22050 herz, bitrate 64k } \begin{lstlisting} ffmpeg -i test.wav -acodec libmp3lame -ac 1 -ar 22050 -ab 64k test.mp3 \end{lstlisting} It is probably better and simpler to use lame to encode to mp3 \emph{ Show what audio file formats are supported by ffmpeg } \begin{lstlisting} ffmpeg -formats \end{lstlisting} \section{Downloading} \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ youtube video download tools }} \\ \hline \texttt{ clive } & A perl script \\ \texttt{ cclive } & The same written in C \\ \texttt{ youtube-dl } & Works for me \\ \hline \end{tabular} \end{center} \emph{ Download the amelie song 'comptine dautre ete' } \begin{lstlisting} youtube-dl \end{lstlisting} \emph{ Download a chopin song in flv format at 480p } \begin{lstlisting} youtube-dl -f 35 http://www.youtube.com/watch?v=GZbuA7r17uk \end{lstlisting} 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 \emph{ Create an audio only file from a youtube video } \begin{lstlisting} youtube-dl -extract-audio -f 35 http://www.youtube.com/watch?v=GZbuA7r17uk \end{lstlisting} \emph{ Create an audio only file in mp4 at 480p using the video title } \begin{lstlisting} youtube-dl -extract-audio -t -f 35 http://www.youtube.com/watch?v=GZbuA7r17uk \end{lstlisting} \emph{ Clean up youtube file names given by 'youtube-dl' -t option } \begin{lstlisting} rename 'y/A-Z_/a-z./' *.flv *.mp3 *.mp4 \end{lstlisting} \begin{lstlisting} rename 's/-[^\.]*//' *.flv *.mp3 *.mp4 \end{lstlisting} \section{Analysing Video} \emph{ Show information about the avi video file 'green.avi' (duration, encoding etc) } \begin{lstlisting} ffmpeg -i green.avi \end{lstlisting} \emph{ Show information with mplayer, dont actually play anything } \begin{lstlisting} mplayer -endpos 0 -vo null -ao null video.mp4 | less \end{lstlisting} \emph{ Show how long an mpg file is } \begin{lstlisting} ffprobe -show_format -show_streams aa.mpg | grep duration \end{lstlisting} \subsection{Duration} \emph{ Find out how long an mpg runs for } \begin{lstlisting} mediainfo aa.mpg | grep -i duration \end{lstlisting} \section{Video Sound} \emph{ Just listen to the sound in 'green.avi', dont watch the video } \begin{lstlisting} mplayer -vo null green.avi \end{lstlisting} \emph{ Find out what audio format is contained in a video file 'vid.flv' } \begin{lstlisting} ffmpeg -i vid.flv | grep stream \end{lstlisting} \emph{ Extract audio from 'eg.flv' video and encode it in the same format (mp3) } \begin{lstlisting} ffmpeg -i eg.flv -vn -acodec copy eg.mp3 \end{lstlisting} \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ ffmpeg important options }} \\ \hline \texttt{ -i } & Show information \\ \texttt{ -vn } & Dont use the video \\ \texttt{ -an } & Dont use the audio \\ \texttt{ -acodec copy } & Use the same audio encoding as decoding \\ \texttt{ -vcodec copy } & Use the same video encoding as decoding \\ \texttt{ -s 320x240 } & Encode video for screen size 320x240 \\ \texttt{ -r 25 } & Encode video at 25 frames per second \\ \texttt{ -formats } & Show available formats \\ \hline \end{tabular} \end{center} \emph{ Extract audio from video 'eg.avi' and stereo encode for burning to cd } \begin{lstlisting} ffmpeg -i eg.avi -vn -acodec pcm_s16le -ar 44100 -ac 2 eg.wav \end{lstlisting} \emph{ Extract only the video from 'eg.flv' (without the audio) } \begin{lstlisting} ffmpeg -i eg.flv -an -vcodec copy silent.flv \end{lstlisting} \emph{ Encode an mpeg video to the youtube flv format } \begin{lstlisting} ffmpeg -i mov0001.mpg -ar 22050 -acodec libmp3lame -ab 32k -r 25 -s 320x240 -vcodec flv eg.flv \end{lstlisting} \section{Extracting Video} \emph{ Extract audio from vob in folder } \begin{lstlisting} for i in *.VOB; do mplayer "$i" -ao pcm:file="${i%.*}.wav"; done \end{lstlisting} \section{Dvd} \subsection{Playing Dvds} \emph{ Play a particular chapter (``scene'') from a dvd track } \begin{lstlisting} mplayer dvd://6 -dvd-device /dev/sr0 -chapter 3 \end{lstlisting} \subsection{Chapters} \emph{ Show the chapters and lengths from a track 6 of a dvd } \begin{lstlisting} lsdvd -t 6 -c /dev/sr0 \end{lstlisting} \subsection{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. \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ tools }} \\ \hline \texttt{ lsdvd } & Just whats needed \\ \texttt{ mediainfo } & Really good, does everything \\ \texttt{ mplayer } & Use the '-identify' switch \\ \hline \end{tabular} \end{center} \emph{ Install the lsdvd utility } \begin{lstlisting} sudo apt-get install lsdvd \end{lstlisting} \emph{ Show lots of info about a dvd } \begin{lstlisting} lsdvd /dev/sr0 \end{lstlisting} \emph{ Show detailed info about audio tracks on a dvd } \begin{lstlisting} lsdvd -a /dev/sr0 \end{lstlisting} \emph{ Show the chapters and lengths from a track 6 of a dvd } \begin{lstlisting} lsdvd -t 6 -c /dev/sr0 \end{lstlisting} \emph{ Print number of tracks, audio information etc. } \begin{lstlisting} mplayer -dvd-device /dev/sr0 -nocache -identify dvd:// -vo null -ao null -frames 0 | less \end{lstlisting} \subsection{Ripping Or Copying Dvds} https://xinn.org/linuxdvdrippingguide.html a guide \emph{ Try handbrake for a gui tool } http://lifehacker.com/5773000/how-to-rip-dvds-with-handbrake \emph{ Install ffmpeg, mplayer, lsdvd etc } \emph{ Try to locate the 'main' track on the dvd. } \begin{lstlisting} lsdvd /dev/sr0 \end{lstlisting} 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 \emph{ Dump chapter 12 of track 6 and save as '12.mpg' (and time it) } \begin{lstlisting} time mplayer dvd://6 -dvd-device /dev/sr0 -chapter 12 -dumpstream -dumpfile 12.mpg \end{lstlisting} \emph{ Extract an entire dvd track and save to 'out.mpg' } \begin{lstlisting} mplayer dvd://6 -dvd-device /dev/sr0 -dumpstream -dumpfile out.mpg \end{lstlisting} The process below is really quite slow, will take hours, but the resulting mp4 file should be much, much smaller than the mpg file \emph{ Recode 'out.mpg' into mp4 format and save as 'out.mp4' } \begin{lstlisting} ffmpeg -i video.mpg -acodec libmp3lame -vcodec libx264 -crf 26 -threads 0 out.mp4 \end{lstlisting} \emph{ Dvd ripping with audio language ``spanish'' } \begin{lstlisting} 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 \end{lstlisting} \emph{ Extract video with a particular audio track } \begin{lstlisting} mplayer dvd://1 -aid 128 -dvd-device DVD.iso -dumpstream -dumpfile Title_1.vob \end{lstlisting} \emph{ Dump chapter by chapter } \begin{lstlisting} 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 \end{lstlisting} \emph{ Maybe better way } \begin{lstlisting} mplayer dvd://6 -dvd-device /dev/sr0 -dumpstream -dumpfile -chapter 1-13 untouchables.mpg \end{lstlisting} \subsection{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 \emph{ Copy all vobs from dvd with } \begin{lstlisting} vobcopy \end{lstlisting} \emph{ Then concatenate } \begin{lstlisting} cat VTS_01_1.VOB VTS_01_2.VOB ...> ~/temp/mymovie.VOB \end{lstlisting} \emph{ Then ffmpeg to create a mkv format movie } \begin{lstlisting} ./ffmpeg -i mymovie.vob -c:v copy -c:a copy -c:s copy -map 0 mymovie.mkv \end{lstlisting} http://stackoverflow.com/questions/19200790/converting-dvd-image-with-subtitles-to-mkv-using-avconv more info about ffmpeg with vobs \subsection{Two Pass With Mencoder} \emph{ First pass } \begin{lstlisting} 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 \end{lstlisting} \emph{ Second pass } \begin{lstlisting} 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 \end{lstlisting} \subsection{Audio In Dvds} \emph{ Show detailed info about audio tracks on a dvd } \begin{lstlisting} lsdvd -a /dev/sr0 \end{lstlisting} \emph{ Extract the audio from a dvd quickly, save to audiodump.wav } \begin{lstlisting} mplayer dvd://3 -dvd-device /dev/sr0 -vc null -vo null -ao pcm:fast \end{lstlisting} \section{Audio In Video} \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ audio keystrokes }} \\ \hline \texttt{ \# } & (DVD, Blu-ray, MPEG, Matroska, AVI and libavformat only) \\ Cycle through the available audio tracks. \hline \end{tabular} \end{center} \emph{ Recode 'eg.flv' with the same audio/video encoding but a different screen size } \begin{lstlisting} ffmpeg -i eg.flv -acodec copy -s 320x240 -vcodec flv silent.flv \end{lstlisting} \emph{ Convert an mpeg video to 'flv', using only 128 seconds after 10 minutes } \begin{lstlisting} ffmpeg -i eg.mpg -acodec copy -r 25 -s 320x240 -vcodec flv -ss 00:10:00 -t 128 eg.flv \end{lstlisting} \emph{ Encode from mpeg to flv format breaking when file size 10M is reached } \begin{lstlisting} ffmpeg -i eg.mpg -acodec copy -vcodec flv -fs 10485760 eg.flv \end{lstlisting} \emph{ Encode 'eg.avi' movie to television mpeg suitable for pal format tv. } \begin{lstlisting} ffmpeg -i eg.avi -target pal-vcd eg.mpg \end{lstlisting} \emph{ Extract audio and video of an flv video into separate files } \begin{lstlisting} ffmpeg -i eg.flv -vcodec mpeg2video eg.m2v -acodec copy eg.mp3 \end{lstlisting} \emph{ Create a video 'new.flv' combining audio and video, offseting audio 1/2 a second } \begin{lstlisting} ffmpeg -i eg.mp3 -itsoffset 00:00:00.5 -i eg.m2v new.flv \end{lstlisting} In this recipe the audio is delayed by 1/2 second \emph{ Create a video 'new.flv' combining audio and video, offseting audio 1/2 a second } \begin{lstlisting} ffmpeg -i eg.m2v -itsoffset 00:00:00.5 -i eg.mp3 new.flv \end{lstlisting} In the command above the video is delayed by half a second \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ some preset targets with ffmpeg }} \\ \hline \texttt{ ntsc dvd } \\ \texttt{ vcd } \\ \texttt{ dvd } \\ \texttt{ dv } \\ \hline \end{tabular} \end{center} \emph{ Split an avi video into chunks } \begin{lstlisting} avisplit \end{lstlisting} \emph{ Split mpg video into chunks } \begin{lstlisting} mpgtx \end{lstlisting} \begin{description}[labelindent=1cm, leftmargin=2cm, style=nextline] \item[\url{handbrake}] a graphical tool for converting video formats \end{description} \subsection{Analysing Audio In Video} \emph{ Show some audio info for a dvd } \begin{lstlisting} mplayer dvd://3 -dvd-device /dev/sr0 -vo null -ao null -endpos 0 | grep audio \end{lstlisting} \subsection{Extracting Audio From Video} \emph{ 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. ... ,,, \emph{ Extract audio from track 3 of dvd, save as audiodump.wav } \begin{lstlisting} mplayer dvd://3 -dvd-device /dev/sr0 -vc null -vo null -ao pcm \end{lstlisting} \emph{ Extract audio from track 3 of dvd, save as s.wav } \begin{lstlisting} mplayer dvd://3 -dvd-device /dev/sr0 -vc null -vo null -ao pcm:file=s.wav \end{lstlisting} \emph{ Extract all audio from vobs in a folder } \begin{lstlisting} for i in *.VOB; do mplayer "$i" -ao pcm:file="${i%.*}.wav"; done \end{lstlisting} \emph{ Play video with particular audio track } \begin{lstlisting} mplayer dvd://1 -aid 128 -dvd-device DVD.iso \end{lstlisting} \section{Formats} \begin{description}[labelindent=1cm, leftmargin=2cm, style=nextline] \item[\url{wav}] uncompressed \item[\url{flac}] (free lossless audio codec) good lossless format for storage, more compressed than wav \item[\url{ogg}] good for streaming, lossy compression, no patent \end{description} \section{Video} \emph{ Play high-res video files on a slow processor } \begin{lstlisting} mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all \end{lstlisting} \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ some video formats }} \\ \hline \texttt{ h.264 } & An open standard used by apple \\ \texttt{ ogv } \\ \texttt{ mp4 } \\ \texttt{ flash } & A proprietary thing, not good \\ \hline \end{tabular} \end{center} \begin{description}[labelindent=1cm, leftmargin=2cm, style=nextline] \item[\url{deb:}] flashblock an add on for firefox (et al) which replaces flash content with a button to play the content. \end{description} \emph{ Dump dvd from a different machine onto this one. } \begin{lstlisting} ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso \end{lstlisting} \emph{ Use mplayer to save video streams to a file } \begin{lstlisting} mplayer -dumpstream -dumpfile "yourfile" -playlist "URL" \end{lstlisting} \emph{ External projector for presentations } \begin{lstlisting} xrandr --auto \end{lstlisting} \emph{ Download Apple movie trailers } \begin{lstlisting} 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/'` \end{lstlisting} \emph{ Remux an avi video if it won't play easily on your media device } \begin{lstlisting} mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi \end{lstlisting} \emph{ Create multiple mp4 files using avidemux } \begin{lstlisting} for i in *;do avidemux --video-codec Xvid4 --audio-codec mp3 --load "${i}" --save "`echo "$i" | sed -e 's/\....$//'`.done.mp4" --quit; done \end{lstlisting} \emph{ FLV to AVI with subtitles and forcing audio sync using mencoder } \begin{lstlisting} 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 \end{lstlisting} \begin{lstlisting} mplayer dvd:// -softvol -softvol-max 500 \end{lstlisting} \emph{ Play audio stream and video stream in two different mplayer instances } \begin{lstlisting} mplayer test.mp3 < /dev/null & mplayer test.avi -nosound -speed 1.0884 \end{lstlisting} \emph{ Uncompress a movie 'eg.rar' (in .rar archive) and play it } \begin{lstlisting} unrar p -inul eg.rar | mplayer - \end{lstlisting} \emph{ Stream a youtube video directly from the web to mplayer } \begin{lstlisting} 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') \end{lstlisting} \emph{ View the video file 'eg.avi' using only ascii characters } \begin{lstlisting} mplayer -vo aa eg.avi \end{lstlisting} \subsection{Video And Audio} \emph{ Removing syncronization problems between audio and video } \begin{lstlisting} ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv \end{lstlisting} \section{Converting Video Formats} \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ tools }} \\ \hline \texttt{ ffmpeg } & Good command line tool \\ \texttt{ mencoder } & Part of the mplayer suite \\ \texttt{ avidemux } & Graphical tool \\ \hline \end{tabular} \end{center} 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 \emph{ Recode 'out.mpg' into mp4 format and save as 'out.mp4' } \begin{lstlisting} ffmpeg -i video.mpg -acodec libmp3lame -vcodec libx264 -crf 26 -threads 0 out.mp4 \end{lstlisting} \subsection{Youtube Format} \emph{ Rip dvd to youtube ready mpeg-4 avi file using mencoder } \begin{lstlisting} 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 \end{lstlisting} \subsection{Image To Video} \emph{ Convert (almost) any image into a video } \begin{lstlisting} ffmpeg -loop_input -f image2 -r 30000/1001 -t $seconds -i frame/$num.ppm -y frame/%02d.mpeg 2>/dev/null \end{lstlisting} \emph{ Convert multiple files using avidemux } \begin{lstlisting} for i in `ls`;do avidemux --video-codec Xvid4 --load $i --save $i.mp4 --quit; done \end{lstlisting} \emph{ Convert wmv into avi } \begin{lstlisting} mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi \end{lstlisting} \emph{ Create a thumbnail from a video file } \begin{lstlisting} thumbnail() { ffmpeg -itsoffset -20 -i $i -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x272 ${i%.*}.jpg } \end{lstlisting} \emph{ Convert .flv flash video to the '.3gp' format } \begin{lstlisting} ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp \end{lstlisting} \emph{ Convert a flv video file to avi using mencoder } \begin{lstlisting} mencoder your_video.flv -oac mp3lame -ovc xvid -lameopts preset=standard:fast -xvidencopts pass=1 -o your_video.avi \end{lstlisting} \emph{ Convert video files to XviD } \begin{lstlisting} mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o "$1".avi \end{lstlisting} \emph{ Rip a DVD to AVI format } \begin{lstlisting} mencoder dvd://1 -aid 128 -o track-1.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4 \end{lstlisting} \emph{ Convert a DVD to YouTube-ready ``watermarked'' MPEG-4 AVI file } \begin{lstlisting} 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 \end{lstlisting} \emph{ Convert a VMWare screencast into a flv file } \begin{lstlisting} mencoder -of avi -ovc lavc movie.avi -o movie2.avi; ffmpeg -i movie2.avi -r 12 -b 100 movie.flv \end{lstlisting} \subsection{Video Editing Programs} Kino, Cinelerra, Avidemux, Kdelive, Lives, Lumiera, Pitivi, Open Movie Editor \arrayrulecolor{gray} \begin{center} \begin{tabular}{ |rl| } \multicolumn{2}{c}{\textbf{ video tools }} \\ \hline \texttt{ vcdimager } & A VideoCD (VCD) image mastering and ripping too \\ \hline \end{tabular} \end{center} \emph{ Extract audio track from a video file using mencoder } \begin{lstlisting} mencoder -of rawaudio -ovc copy -oac mp3lame -o output.mp3 input.avi \end{lstlisting} \subsection{Webcam Video} \begin{description}[labelindent=1cm, leftmargin=2cm, style=nextline] \item[\url{qmotion}] motion detection for webcams \end{description} \emph{ Webcam player in ascii art } \begin{lstlisting} gst-launch v4l2src ! aasink \end{lstlisting} \emph{ View webcam output using GStreamer pipeline } \begin{lstlisting} gst-launch-0.10 autovideosrc ! video/x-raw-yuv,framerate=\(fraction\)30/1,width=640,height=480 ! ffmpegcolorspace ! autovideosink \end{lstlisting} \emph{ Webcam view with vlc } \begin{lstlisting} cvlc v4l2:// & \end{lstlisting} \emph{ Mirror from your laptop + webcam (fullscreen+grab) } \begin{lstlisting} mplayer -fs -vf screenshot,mirror tv:// \end{lstlisting} \emph{ View the webcam output using mplayer } \begin{lstlisting} mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2 \end{lstlisting} \section{Desktop Video} This section refers to recording video of what is happening on the computer screen. It is equivalent to the 'screenshot'. \emph{ Capture a video of a linux desktop } \begin{lstlisting} ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg \end{lstlisting} \subsection{Compressing Video} \emph{ Convert an avi video into a gif animation } \begin{lstlisting} convert -quiet -delay 1 plane.avi plane.gif \end{lstlisting} \emph{ Convert an avi to gif with a colour map and no dithering for more compression } \begin{lstlisting} convert -quiet -delay 1 plane.avi +dither -map colormap_332.png plane_ugc_nd.gif \end{lstlisting} \emph{ Use ordered dithering for good compression and quality } \begin{lstlisting} convert -quiet -delay 1 plane.avi -ordered-dither o8x8,8,8,4 +map plane_od.gif \end{lstlisting} \end{document}