Revision as of 03:03, 28 October 2013
This guide does not advocate the illegal duplication of copyrighted content. However, fewer and fewer devices use DVDs any longer, and a large amount of video content is distributed on DVDs. It becomes necessary to convert video content into formats that can be viewed on devices that no longer used DVDs. Furthermore, online content is often in a format that is not universally playable and this also requires conversion. Trying to select and encode a video into a format which your device accepts is not always a straightforward task.
There are lots of video and audio codecs and lots of methods and preferences for converting between formats. These are only some basic examples. A good deal of trial and error is often required for successful video conversion.
- Mencoder and FFMPEG are the two packages that are the workhorses of video conversion. Of these, mencoder is faster and generally gives better results.
- Handbrake uses a streaming algorithm and FFMPEG to "rip" DVDs and can work with many different encryption methods. It uses the (superior, open source) .MKV container only, however (which is not supported by many devices). It also does not support XVID (and uses either X264/H.264 or MP4 video codecs) and therefore its video output is also not universally accepted by a wide range of devices. As these standards become more widely accepted, however, this will be an invaluable encoding tool. On rare occasions I rip a video with Handbrake (to .MKV and H.264/MP3) and then convert it to .AVI (XVID/MP3) in a second step (using mencoder).
- When I originally wrote these articles, .MKV was accommodated by only a handful of DVD players. A recent survey of new DVD players shows that most (including widely available inexpensive DVD players) will now play files in .MKV format. In fact, it is now difficult to find DVD players that will still play .AVI with XVID / DivX video. However, over the years I have accumulated a very large collection of .AVI / XVID / MP3 videos. In 2013, the only DVD player I could find that would play them all was the Philips BDP2105/F7 DVD Player with BluRay/HD Upconversion/WiFi/Netflix streaming (which I found at Best Buy for $70). I highly recommend this player if you find yourself with a large collection of .AVI / XVID video files.
sudo apt-get install mencoder
Usage instructions can be found from the command-line (man mencoder) or here.
MP4 with AAC audio to AVI with Xvid / MP3
- The AAC audio codec is not compatible with many DVD players and devices due to licensing restrictions, whereas the MP3 audio codec is nearly universally accepted. Xvid is the open source version of the DivX video codec and is accepted by a very large number of DVD players and other devices (even older ones, especially those displaying the DivX logo).
- The .AVI container only allows a constant bitrate, so the MP3 audio must be encoded at CBR. If the AAC is 5.1, it will be downcoded to stereo for MP3.
- This example is a two-pass technique that allows the file size to be specified and quality optimized for that filesize (using the information generated in the first pass). In this example, a 700 MB file is desired (and is specified by the negative value of 620000, which by a quirk of mencoder gives an approximately 700 MB file).
mencoder <input.mp4> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=1 -o /dev/null mencoder <input.mp4> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-620000 -o <output.avi>
Remove MKV subtitles and convert to AVI (XVID/MP3)
Mastroska container (.MKV) video files can have multiple subtitles included. In the default conversion from an .MKV container format to an .AVI container format, the default subtitle file of the .MKV container is automatically hardcoded into the converted .AVI file, which may be undesirable. To overcome this behaviour (so that the converted .AVI has no subtitles), use the -sid 999 option:
mencoder <input.mkv> -sid 999 -ovc xvid -oac mp3lame -lameopts cbr:br=192 -xvidencopts pass=1 -o /dev/null mencoder <input.mkv> -sid 999 -ovc xvid -oac mp3lame -lameopts cbr:br=192 -xvidencopts pass=2:bitrate=-1200000 -o <output.avi>
- To hardcode one of the subtitle tracks onto the .AVI video from the .MKV video, choose the subtrack ID, such as -sid 0 or -sid 1.
- If using NTFS and the error
> Too many audio packets in the buffer: (4096 in 837540 bytes). > Maybe you are playing a non-interleaved stream/file or the codec > failed? For AVI files, try to force non-interleaved mode with the > -ni option.
appears, then add these options:
-mc 0 -ofps 24000/1001 -noskip
DVD to AVI with Xvid / MP3
- See the mencoder documentation.
- Extract a video (in the .vob format) from a DVD to a file with an .AVI container and XVID/DivX video and .MP3 audio using this (2-pass conversion) command:
mencoder dvd://1 -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=1 -o /dev/null mencoder dvd://1 -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-620000 -o <output.avi>
where dvd://1 indicates the first track of the DVD.
- If you are not sure which track contains the content you wish to extract to a file, one way to check this is to play the DVD with a media player like VLC, examining the tracks on it:
- VLC -> Media -> Open Disc... -> Play -> Playback -> Navigation
or from the command line install lsdvd (sudo apt-get install lsdvd) and use it:
lsdvd -v -t 1 /dev/dvd
This will show a list of the title numbers (for the content tracks) on the DVD (and information about them). Use the title number for the content to be extracted.
- Conversion is much faster when done from from a hard drive than from a physical DVD. It is possible to copy the VIDEO_TS and AUDIO_TS folders from the physical DVD to a folder on the hard drive. Once you have copied the contents of the DVD to a folder, add the -dvd-device /path/to/dvd_folder option to specify it (with the same options as above in addition to the new one):
mencoder dvd://1 -dvd-device /path/to/dvd_folder
- Note the -vobsub 999 option to prevent subtitles from being automatically added. (If you wish to hardcode subtitles, use the number of the subtitle track, such as -sid 0 or -vobsubid 0 for the default subtitle track or -sid 1 or -vobsubid 1 for the next subtitle track.)
- Other options for video cropping and scaling can be used. See these hints and these tips, as well as this section.
- When better audio quality is desired, an audio bitrate more than 128 kb/sec can be used (e.g. br=160 or br=192), but this will give a larger file (or will decrease video quality if the filesize remains constant). cbr (constant bitrate) is used for mp3lame encoding in .AVI; I generally increase the volume of the video by 30% using the vol=3 option, as well. My final audio command therefore usually ends up: -oac mp3lame -lameopts cbr:br=128:vol=3.
- If there are multiple audio tracks, the audio track can be selected with the -aid 1 (or similar) option, specifying the number of the desired audio track. (Note: check audio track numbering carefully.) The English default audio track is usually -aid 128. To show information about the audio tracks, use
lsdvd -a -t 1 /dev/dvd
- Although the bitrate=-700000 option specifies a target file size of 700000 (approx. 700 MB), this actually results in a file size of nearly 800 MB. Specify a target filesize about 15% less than actually desired, therefore. For a target 700 Mb file, for example, I use bitrate=-620000.
- For XVID there is an option to allow video seeking (for fast forwarding or rewinding) in 1 second increments (instead of the default 10 second increments): -xvidencopts max_key_interval=25 (seek every 25 frames instead of the default 250 frames). This would be included as part of a more complex option string, such as -xvidencopts pass=2:max_key_interval=25:bitrate=-620000.
- In order to play the converted .AVI file on my older DVD players and televisions (and avoid significant motion artifacts and pixelation), I find that I must use deinterlacing. Only two interlacing methods have worked well for me: -vf pp=lb or -vf yadif=0. There are many methods of deinterlacing for mencoder, however (see here and here, for example). Deinterlacing may not be necessary for your needs (when used for archival purposes only, for example, or if viewing files with media players (such as VLC) that already have built-in deinterlacing capabilities). Often recommended when ripping NTSC-format movies (progressive or telecined) is to include the option -vf pullup,softskip,harddup, which must be used with a deinterlacing filter, such as -vf pullup,softskip,pp=lb,harddup (or -vf pullup,softskip,yadif=0,harddup). The order of the telecine/progressive option, the deinterlacing option, and any cropping or scaling options is very specific -- read the mencoder documentation carefully when mixing these options. Specifically, cropping and scaling (when used) should be done after the telecine/progressive/deinterlacing options but before the frame duplication option, e.g. -vf pullup,softskip,pp=lb,crop=720:416:0:80,scale=704:304,harddup.
- Note: You will need libdvdcss2 installed on your system to access DVD data. If your DVD has encryption that is not able to be decrypted by libdvdcss, then consider using Handbrake, which uses a streaming algorithm to "rip" DVDs.
- This is the 2-pass command I end up using most often (with 4:3 NTSC videos):
mencoder dvd://1 -dvd-device /path/to/dvd_folder -vf pullup,softskip,pp=lb,harddup -vobsub 999 -aid 128 -ovc xvid -oac mp3lame -lameopts cbr:br=128:vol=3 -xvidencopts pass=1 -o /dev/null mencoder dvd://1 -dvd-device /path/to/dvd_folder -vf pullup,softskip,pp=lb,harddup -vobsub 999 -aid 128 -ovc xvid -oac mp3lame -lameopts cbr:br=128:vol=3 -xvidencopts pass=2:max_key_interval=25:bitrate=-620000 -o <output.avi>
- This is the 2-pass command I end up using most often (with 16:9 NTSC videos):
mencoder dvd://1 -dvd-device /path/to/dvd_folder -vf pullup,softskip,pp=lb,scale=648:364,harddup -vobsub 999 -aid 128 -ovc xvid -oac mp3lame -lameopts cbr:br=128:vol=3 -xvidencopts pass=1 -o /dev/null mencoder dvd://1 -dvd-device /path/to/dvd_folder -vf pullup,softskip,pp=lb,scale=648:364,harddup -vobsub 999 -aid 128 -ovc xvid -oac mp3lame -lameopts cbr:br=128:vol=3 -xvidencopts pass=2:max_key_interval=25:bitrate=-620000 -o <output.avi>
- The scale option is set so that I can play the video on analogue televisions with overscan (I still have a few of those). However, an alternative is to use scale=720:406 for use on most widescreen TVs.
Using k9copy as a conversion front-end
- k9copy is a good front-end for mencoder (as well as ffmpeg).
- To add an option to encode to XVID from an NTSC DVD (when using mencoder within k9copy), I add the necessary options to the Video codecs section:
- k9copy -> Configure k9copy -> Encoders -> mencoder -> Add -> label: XVID from NTSC -> first pass ->
-ovc xvid -xvidencopts bitrate=$VIDBR:turbo:pass=$PASS:aspect=$ASPECT -vf pullup,softskip,pp=lb,crop=$CROPWIDTH:$CROPHEIGHT:$CROPLEFT:$CROPTOP,scale=$WIDTH:$HEIGHT,dsize=$ASPECT,harddup
The same command is entered for the "second pass" option as well. For the "one pass" option enter:
-ovc xvid -xvidencopts bitrate=$VIDBR:aspect=$ASPECT -vf pullup,softskip,pp=lb,crop=$CROPWIDTH:$CROPHEIGHT:$CROPLEFT:$CROPTOP,scale=$WIDTH:$HEIGHT,dsize=$ASPECT,harddup
- To then use this new Video codec option, make sure it is selected:
- k9copy -> Configure k9copy -> MPEG-4 -> Video -> Codec -> XVID from NTSC -> 2 pass (ticked) -> Apply
At the same time, the MP3 (lame) Audio codec option can be selected:
- k9copy -> Configure k9copy -> MPEG-4 -> Audio -> Codec -> mp3 (lame) -> OK
- Now when the Output: MPEG-4 encoding is selected from the main screen, this "XVID from NTSC" Video encoding option will be used.
- Note that the -vf pullup,softskip,pp=lb,crop=$CROPWIDTH:$CROPHEIGHT:$CROPLEFT:$CROPTOP,scale=$WIDTH:$HEIGHT,dsize=$ASPECT,harddup option can be used with any Video codec, not just XVID.
AVI to MPG
- The MPG format is sometimes useful for creating DVDs (using the MPEG-1 or MPEG-2 video codec, which can be then used for vob files using QDVDAuthor or ToVid). If the audio codec of the AVI file is already AC3 or MP3, it usually can be copied. This example is take from the MPlayer/Mencoder documentation. Example:
mencoder <input.avi> -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video -oac copy -o <output.mpg>
- Use the -af volume=3:0 option, where the first number (3 in the example) is the number of decibels to increment the volume (a 3 db increment doubles the volume), and the second number is 0 for hard-clipping and 1 to allow software-based clipping (to prevent oversaturation when the sound becomes too loud).
For example, if I want to double the sound volume of my .AVI video:
mencoder <input.avi> -ovc copy -oac mp3lame -lameopts cbr:br=128 -af volume=3:0 -o <output.avi>
- This can also be done when encoding to the mp3lame audio codec by adding an option to the mp3lame options:
mencoder <input.avi> -ovc copy -oac mp3lame -lameopts cbr:br=128:vol=3 -o <output.avi>
- where vol=3 can be set to any value between -10 and 10. I use vol=3 to increase the volume 30%. (This method works best for me.)
Re-synchronize audio with video
If the audio track is out of synch with the video, it can be adjusted using the -audio-delay [sec] option. For example, if it is found (using VLC -> Tools -> Track Synchronization, for example) that the required delay is 0.700 sec, then re-encode using -audio-delay 0.700:
mencoder <input.avi> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -audio-delay 0.700 -xvidencopts pass=1 -o /dev/null mencoder <input.avi> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -audio-delay 0.700 -xvidencopts pass=2:bitrate=-620000 -o <output.avi>
Add subtitles to video
- .srt subtitle files are essentially text files with time stamps. They are meant to be used with digital video files (such as .AVI files) and are different from the image-based .idx / .sub subtitle files (vobsub) used with the .vob format found on commercial DVDs.
- Using mencoder:
mencoder -ovc [codec] [codec opts] -oac copy -sub [sub file.srt] -subfont-text-scale [3 normally]
In the example above, this would be:
mencoder <input.mp4> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-620000 -sub <subtitles.srt> -subfont-text-scale 3 -o <output.avi>
- If the subtitles are too low or too high on the screen, they can be positioned so that the top edge of the subtitles are at a different position using the -subpos 95 option, where the number specifies the percentage from the top of the screen where the subtitles will be placed. For example, if using the value 95, the top of the subtitles will be placed 95% down the screen. The full command would then be, for example:
mencoder <input.mp4> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-620000 -sub <subtitles.srt> -subfont-text-scale 3 -subpos 95 -o <output.avi>
- Full subtitle options can be found in the manual (available from the command-line terminal): man mencoder
- Note: When adding subtitles to an .AVI video, you must transcode it completely. It is not sufficient to merely add the subtitle track as listed above -- the entire video must be re-transcoded. So, for example:
mencoder <input.avi> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=1 -o /dev/null mencoder <input.avi> -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-1200000 -sub <subtitles.srt> -subfont-text-scale 3 -o <output.avi>
Trim a video
- Using mencoder:
mencoder <input.avi> -ovc copy -oac mp3lame -ss 01:57:12 -endpos 00:04:08 -o <output.avi>
where -ss indicates the start position of the clip (hh:mm:ss) and -endpos indicates how long the clip should be. (I use mp3lame for the audio codec because YouTube accepts that.)
Resize a video
- Using mencoder:
mencoder <input.avi> -ovc xvid -vf scale=320:240 -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-1200000 -o <output.avi>
where -vf scale=320x240 indicates that the resulting video should be of that size. The position of the suboption in the command string is important.
- HDTV resolution is usually 1920 x 1080 ("1080p") or 1280 x 720 ("720p"). A standard definition widescreen TV has a maximum height of "480p" (usually 853 x 480 but sometimes 720 x 406). The standard width:height aspect ratio for cinema is 1.85:1, whereas the average aspect ratio for widescreen movies distributed for display on television is 16:9 (1.78:1). When resizing a video, it is good to know the original dimensions of the video and maintain the width to height aspect ratio in the chosen scale.
- Example: A video is distributed as 1280 x 692 (which has an aspect ratio of 1.85:1). The device (a low resolution television) on which it is to be displayed has a maximum width of 720. The desired resolution would then be 720 x 390 to keep the aspect ratio at approximately 1.85:1. The option would then be -vf scale=720:390. An analog television would require 10% overscan, making the maximum width 648. To keep an aspect ratio of 1.85:1 would require a resolution of 648 x 350, or a scale option of -vf scale=648:350.
- Example: An HQ video is distributed as 1920 x 1080 (which has an aspect ratio of 16:9). It is desired to view the video on a television with a maximum width of 720p, which would require a final resolution of 720 x 406 to maintain an aspect ratio of 16:9. The scale option would be -vf scale=720:406.
- Example: An HQ video is distributed as 1920 x 1080 (which has an aspect ratio of 16:9). It is desired to view the video on an analogue television with 10% overscan, which would require a final resolution of 648 x 364 to maintain an aspect ratio of 16:9. The scale option would be -vf scale=648:364.
- "Standard" definition analog television has a 4:3 ratio, for which a scale of 640:480 (-vf scale=640:480) is generally preferable.
Cropping and Scaling
- The -vf filters operate on the video in the order they are loaded. The crop filter uses width:height:x-offset:y-offset. (The default x-offset and y-offset is centered, so these are optional.) For example, to first crop the 688x464 region of the picture with upper-left corner at (x=12,y=4) and then scale the result down to 640x464, the following chain is used:
If I want to remove subtitles (-sid 999), crop out black bars and extraneous noise at the top/bottom of an .mkv video, scale it, and convert to an .avi format, an example command might be:
mencoder <input.mkv> -sid 999 -ovc xvid -oac mp3lame -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=1:bitrate=-620000 -vf crop=1280:688,scale=720:406 -o <output.avi>
Convert to .MP3 audio file
- To use Mplayer to extract audio from an .avi file to an ,mp3 .wav file:
mencoder <input.avi> -of rawaudio -oac mp3lame -ovc copy -o <output.mp3>
- This can be combined with start markers (-ss hh:mm:ss) and a length marker (-endpos hh:mm:ss) to extract only a segment of audio from an .avi file. In the following example, only audio from starting position at 3 minutes 45 seconds with a length of 2 minutes 4 seconds will be extracted:
mencoder <input.avi> -ss 00:03:45 -endpos 00:02:04 -of rawaudio -oac mp3lame -ovc copy -o <output.mp3>
- (Under construction) To use Mplayer to extract audio to a pcm .wav file:
mplayer <input.avi> -vc null -oa pcm -aofile -ss 1441.4 -endpos 260.1 <output.wav>
- Then convert the .wav file to .mp3 with your favourite converter (such as Audacity or SoundConverter).
- I often use FFMPEG and find it to be easier for this task.
Change audio track of video
- In general, Avidemux is a good video editor for most needs, including muxing and demuxing video and audio.
- For a quick method to change the audio for a video, I like to merely remove the audio from the original video file using the -nosound option, for example:
mencoder <input.avi> -ovc copy -nosound -o <outputnosound.avi>
- Then, I add a new audio file as the audio track to the video using the -audiofile option. For example, if I now want to add an .mp3 audio track named <newaudio.mp3>, I would use the command:
mencoder <outputnosound.avi> -ovc copy -oac mp3lame -audiofile <newaudio.mp3> -o <output.avi>
FFMPEG is the swiss-army knife of video and audio format conversion. It succeeds when no other program can. It is free and open source. If it not yet installed on your system as part of another package (it is used by many video/audio editors), then install it:
sudo apt-get install ffmpeg
Flash video (.flv) to MPG-2 using FFMPEG
- To convert a saved Flash video (.flv) to an MPEG-2 format playable on a DVD, convert:
ffmpeg -i samplevideo.flv -target ntsc-dvd samplevideo.mpg
- For PAL use -target pal-dvd. For widescreen, use -target film-dvd. For other conversion tips, see this forum. (Note: Most Flash video has very low resolution, with a screen size of 360x270, for example. You may see a slight diminishment in resolution if you wish to convert it to 720x480 (which is the NTSC standard size) or other screen size. You can keep the original screen size and resolution by omitting the -target parameter.) If your original file is 16:9 widescreen and you desire a 4:3 letterbox output for playing on an overscanned TV, you may need to pad the file so that the widescreen is not compressed (see this forum):
ffmpeg -i samplevideo.flv -target ntsc-dvd -s 648x364 -padleft 36 -padright 36 -padtop 58 -padbottom 58 samplevideo.mpg
- You can also use the WinFF GUI and add the command (as above) as a "Preset," for subsequent use. For example:
- Video converter (WinFF) -> Edit -> Presets ->
- Preset Name: Letterbox -> Preset Label: 16:9 Widescreen to 4:3 Letterbox
- Preset command: -target ntsc-dvd -s 648x364 -padleft 36 -padright 36 -padtop 58 -padbottom 58
- Ouput file extension: mpg -> Category: DVD
- -> Add/Update -> Save
- To convert to MPEG-4 (mp4) files, use
ffmpeg -i samplevideo.flv outputvideo.mp4
- FFMPEG requires that multiple restricted extra codecs be installed. This can be done in a single easy step from the command-line Terminal:
sudo apt-get install kubuntu-restricted-extras
sudo apt-get install ubuntu-restricted-extras
Convert to .MP3 audio file using FFMPEG
Convert Flash video audio to mp3
- Once you have downloaded flash video content (.flv) from the Internet (using the Video Download Helper plug-in for Firefox, for example), the audio component can be converted to an mp3 using this command (from the command line Terminal). (This will work for any type of video file, not just Flash.)
ffmpeg -i nameofvideoclip.flv -ab 160k -ac 2 -ar 44100 -vn nameoffile.mp3
- where -i indicates the input, -ab indicates the bit rate (in this example 160kb/sec), -vn means no video ouput, -ac 2 means 2 channels, -ar 44100 indicates the sampling frequency. See FFMPEG docs for more info.
If I only want a segment of the video to be converted, I can use the time markers:
ffmpeg -i nameofvideoclip.flv -ss 00:00:09 -t 00:03:00 -ab 160k -ac 2 -ar 44100 -vn nameoffile.mp3
- where -ss 00:00:09 indicates the point in the video (hh:mm:ss) at which to start conversion and -t 00:03:00 indicates the amount of time (from the start point) to convert.
- As long as FFMPEG is already installed, the Video DownloadHelper plug-in for Firefox already has an option to automatically convert an online video (such as those found at YouTube) into an .MP3 file. (Settings are adjustable.) From the DownloadHelper icon in Firefox, highlight the video to convert, then
- DownloadHelper icon -> Download and Convert -> Converter options: MP3
Edit/convert screencapture with FFMPEG
Note: This section under construction.
- Note: I now recommend using mencoder for all video conversion techniques. It uses some of the ffmpeg libraries but is faster and gives more reliable and high-quality results.
- This is only one example of a wide variety of techniques. Once I have a captured video, I want to convert it to XVID video (which is the format my older DVD player accepts) and MP3 audio (mp3lame), which I will place in an AVI container (which my DVD player also accepts).
ffmpeg -i Punchcast1.avi -vcodec mpeg4 -vtag xvid -acodec libmp3lame -ss 00:00:09 -t 00:03:00 Punchcast2.avi
I will start conversion (-ss) at second 9 (to eliminate unimportant things at the beginning) and convert 3 minutes (-t) of video (00:03:00).
- I happen to watch my screencasts on my old-fashioned 4:3 television. To do that, I make a letterboxed video:
ffmpeg -i Punchcast1.avi -vcodec mpeg4 -vtag xvid -ss 00:00:09 -t 00:03:00 -s 648x364 -padleft 36 -padright 36 -padtop 58 -padbottom 58 -acodec libmp3lame Punchcast3.avi
My laptop screen is 1366x768, which I reduce to a size of 648x364. My TV wants 720x480, so I pad the sides and top/bottom. Why not a width of 720 initially? My older television has 10% overscan, which cuts off 10% of the video. I therefore use (at least) 10% padding on the edges.
In newer versions of FFMPEG, the padding (and many other) options have changed. The proper command is now:
ffmpeg -i Punchcast1.avi -vcodec mpeg4 -vtag xvid -ss 00:00:09 -t 00:03:00 -s 648x364 -vf pad 720:480:36:58 -acodec libmp3lame Punchcast3.avi
ffmpeg movie=Punchcast1.avi:seek_point=9 -vcodec copy -acodec libmp3lame Punchcast1f.avi
WinFF (FFMPEG GUI)
WinFF is a free, GPL-licensed open source GUI frontend for FFMPEG. Install:
sudo apt-get install winff xterm
- Menu -> Applications -> Sound & Video -> WinFF
Avidemux (Video editor/convertor GUI)
I happen to like the command line for video conversion (because the commands are more transparent), but many users prefer a GUI interface, for which Avidemux has long been a favourite.
VobSub2SRT (Convert subtitles from .sub/.idx to .srt)
- VobSub2SRT is a simple (GPLv3-licensed) command-line program to convert the image-based .idx / .sub subtitle files (used with the .vob format found on commercial DVDs) into text-based .srt text subtitle files by using OCR. It is based on code from the MPlayer project, Tesseract as OCR software, and libavutil (part of the FFmpeg project). Install the (K)Ubuntu/Debian (.deb) package from a PPA repository:
sudo add-apt-repository ppa:ruediger-c-plusplus/vobsub2srt sudo apt-get update sudo apt-get install vobsub2srt
- Alternatively, you can download and build a version from source code.
- Install dependencies:
sudo apt-get install pkg-config build-essential cmake libavutil-dev libtesseract-dev
- For (K)Ubuntu 12.10 (Quantal) also install:
sudo apt-get install libtiff5-dev tesseract-ocr-eng
- For (K)Ubuntu 12.04LTS (Precise) also install:
sudo apt-get install libtiff4-dev tesseract-ocr tesseract-ocr-eng
- If you will be converting subtitles in languages other than English, you must install tesseract for any or all of those languages as well:
sudo apt-get install tesseract-ocr-vie tesseract-ocr-deu tesseract-ocr-fra tesseract-ocr-ita sudo apt-get install tesseract-ocr-nld tesseract-ocr-spa tesseract-ocr-por tesseract-ocr-deu-f
- where vie is for Vietnamese, deu is for German, fra is for French, ita is for Italian, nld is for Dutch, spa is for Spanish, por is for Portugeuse, and deu-f is for German Fraktur script. If you don't you will get an error of the type: Unable to load unicharset file /usr/share/tesseract-ocr/tessdata/xxx.unicharset.
- Download and unzip the VobSub2SRT .zip file into its own directory:
mkdir vobsub2srt cd vobsub2srt wget -O vobsub2srt-current.zip https://github.com/ruediger/VobSub2SRT/zipball/ca53a18108eb08d6e2b853643d8c6838e2489823 unzip vobsub2srt-current.zip rm vobsub2srt-current.zip
- This will create a subdirectory with the current version. For example, my version is vobsub2srt/ruediger-VobSub2SRT-ca53a18. Change into that directory then compile and install the program.
cd ruediger-VobSub2SRT-ca53a18 ./configure make sudo make install
- This should install the program vobsub2srt to /usr/local/bin. You can uninstall vobsub2srt with sudo make uninstall. You can build a *.deb package (Debian/Ubuntu) with make package. The package is created in the build directory.
- Convert the .sub / .idx pair of subtitle files (named Filename.sub and Filename.idx) into a .srt subtitle file (named Filename.srt):
- where Filename is the file name of the subtitle files WITHOUT the extension (.sub / .idx).
- If there are multiple languages in the .sub / .idx pair of subtitle files, you can select which language to convert (using the 2-letter ISO 639-1 language code, e.g. en, fr, de, it, es, pt, etc.):
vobsub2srt --lang en Filename
- Edit the .srt subtitle file for OCR mistakes (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):
Join .MPG video segments
Individual video segments (MPEG-2, for example) can easily be joined:
cat samplevideo1.mpg samplevideo2.mpg samplevideo3.mpg > samplevideo123.mpg
- You can then write the resulting MPEG-2 file to a DVD and play it in most DVD players.
Split a file into segments
Any file can be split into segments using the Linux command:
split -b 1440k my_big_file
which will split my_big_file into equal segments of size 1440 kb.
Create a commercial (.vob) format DVD
- The audiovideo container of commercial DVDs uses the .vob format. This container requires either MPEG-1 or MPEG-2 video (.mpg) and either AC3 or MPEG-2 (.mp2) audio. Therefore, the first step in creating a DVD-video in this format is to convert all audiovisual files (to be included on it) to .mpg files (with one of those video and audio formats), usually with the MPEG-PS (A+V) container. This can be done from the command-line terminal (using mencoder or ffmpeg) or from a GUI utility (such as Avidemux).
- Open the file and allow the time map and Index to be rebuilt.
- It is best to convert a file (to be included on the DVD) to a format with MPEG-2 (avcodec) video, AC3 (lav) audio, and the MPEG-PS (A+V) container as an intermediate first. The MP2 audio format (the default for Avidemux in "Auto" mode) can also be used, and will result in a much smaller .mpg file than when using AC3 audio, but several of my very old DVD players only recognise AC3 audio (so this has therefore become my personal preference).
- The easiest method for doing this is to use the Avidemux Auto DVD wizard. (Avidemux -> Auto -> Optical Disc -> DVD). Select the appropriate souce and destination ratios. (My source videos are usually already in 16:9 widescreen formats, and I want to make DVDs for my widescreen 16:9 TV. I therefore choose 16:9 for both the "Source Aspect Ratio" and the "Destination Aspect Ratio.") The Auto DVD Wizard uses MP2 audio by default, but I personally like AC3 audio instead (the format usually used on "commercial" DVDs). I therefore change this using the Audio -> AC3 (lav) option.
- It is possible to customise (or initially set) the format options manually as well (see the Avidemux documentation). Select the Video (and make sure the aspect ratio is the one you desire in Video -> Configure -> Configuration: DVD -> Aspect Ratio: 16:9 ), Audio, and (container) Format options.
- To be DVD compliant, the resolution must be
- 352*480 or 720*480 or 704*480 for NTSC
- 352*576 or 720*576 or 704*576 for PAL/SECAM
- This is set automatically if using the Auto DVD wizard. If your original video does not already have the correct aspect ratio, you will have to use cropping, scaling, and/or black bar "Filter" options until one of the standard resolutions is achieved.
- Save the file ( Avidemux -> File -> Save -> Save Video... -> myconvertedvideo.mpg ) to activate the conversion process. (If prompted whether to "Reuse the existing log file?" answer "No.")
- Alternatively, mencoder can be used from the command-line to convert a file to the .mpg format.
- Alternatively, FFMPEG can be used from the command-line to convert a file to the .mpg format. A simplified preset option for for conversion to both PAL and NTSC options is available.
- Once all files to be included on the DVD-video have been converted to .mpg files, the utility dvdauthor can be used for conversion to .vob format (appropriate for writing to the DVD). While this utility can be used from the command-line, "authoring" (conversion) is more easily accomplished using one of several available GUI front-ends, which allow creation of menus for the DVD as well.
- With Kubuntu I use KMediaFactory for simple projects. (QDVDAuthor, which is difficult to install in recent Kubuntu versions, is superior and more powerful. KMediaFactory, in contrast, is in the repositories and is adequate (and quick) for most purposes.
- Rename the .mpg files (created with Avidemux or other method) carefully. The filename(s) becomes the Title(s) used by KMediaFactory for the video(s) on the DVD menu.
- Set up the DVD menu in KMediaFactory.
- KMediaFactory -> Project -> Title -> MyDVDTitle (this will appear on the DVD Menu at the top)
- -> Type: DVD-NTSC -> Aspect: 16:9 -> Destination Folder /home/user/DVDs
- Add the .mpg files to the DVD.
- KMediaFactory -> Media -> Add Video -> MyFirstVideofile.mpg -> VideoProperties: Aspect ratio: 16:9
- -> Add Video -> MySecondVideofile.mpg -> VideoProperties: Aspect ratio: 16:9
- Choose the DVD Menu appearance.
- KMediaFactory -> Template -> Preview 3
- Choose the output format. For this, I generally create a "DVD folder":
- KMediaFactory -> Output -> DVD Folder
- Start the conversion ("DVD authoring") process. If an error appears, the problem usually lies in a non-existent (or write-protected) folder having been specified when setting the "Title" options. Make sure the folder has been specified properly. KMediaFactory will then create the standard AUDIO_TS and VIDEO_TS folders in the folder specified.
- -> Start
- Prior to burning I check to make sure that my DVD looks the way I had intended using VLC (VLC -> Media -> Open Disc... -> Browse... -> specified_folder -> Play)
- In Kubuntu I then use K3b to burn the AUDIO_TS and VIDEO_TS folders to a blank DVD. This can be done in K3b using the "New Video DVD Project" (K3b -> More actions... -> New Video DVD Project) using the AUDIO_TS and VIDEO_TS folders as the data. Edit the name of the DVD to reflect the desired DVD name. "Burn" the DVD. The result will be identical to commercial DVDs. (Note: In recent versions of K3b I have had to "Burn" using the "growisofs" Writing app at 8x Speed and DAO (Disc-At-Once) Writing Mode in order to achieve reliable burns. See here for more details.)
- To manipulate .MKV files directly, install the mkvtoolnix utilities:
sudo apt-get install mkvtoolnix mkvtoolnix-gui
- This toolset includes the mkvextract and mkvmerge tools. Instructions for mkvextract can be found from the command-line terminal (man mkvextract) or here.
Extract .MKV audio track
- Use mkvmerge to identify the tracks:
mkvmerge --identify <input.mkv>
This command will also list the format of the audio track (AC3, MP3, AAC, etc.)
- If the audio track to be extracted is track 2, use
mkvextract tracks <input.mkv> 2:<output.ac3>
- Use an audio editor such as Audacity to edit or modify the audio track as desired (and export it to the desired audio format).
- It is then possible to use the new audio file to change the audio track of the original video.
Extract .MKV subtitle file to .SRT subtitle file
- Use mkvmerge to identify the tracks:
mkvmerge --identify <input.mkv>
- If the subtitle file to be extracted is track 3, use
mkvextract tracks <input.mkv> 3:<output.srt>
- For this to work, of course, the MKV subtitle track must already be in text (.srt) format, not image (.sub/.idx) format.
- If instead of the text-based .srt format the subtitle track of the input.mkv video is in the image-based vobsub format used with .vob commercial DVDs, the mkvextract tool will output the subtitles as a pair of output.sub and output.idx files instead. The .sub/.idx subtitle files can then be converted into a .srt subtitle file using VobSub2SRT.
- There is only one format that works on all my devices (computer (both Linux and Windows), (Android) tablet, (Android) eBook reader, MP3 player, (older) DVD player):
- .AVI container with XVID/DivX video codec and MP3lame (MP3) audio codec
- I use this for all my devices, and encode files to about 700 MB. This is a good size that gives good quality and allows me to fit many videos on a single SDcard (which I use in my mobile devices). For most of my devices, a 128 kb MP3 encoding bitrate is sufficient; I previously encoded at 192 kb for MP3lame (which is the default bitrate for AC3 sound), but I find this bitrate to be unnecessary. (The higher the encoding bitrate, the larger the encoded file, and I try to keep all my files around 700 MB.) The .AVI container has several limitations: it does not allow more than stereo audio (i.e. no 5.1 surround sound), does not allow multiple subtitle files, and requires a constant bitrate (CBR) audio channel. For advanced archival purposes it may not be suitable in the long-term, but currently it is desirable for the wide range of devices that accept it. It is also one of the only containers guaranteed to be accepted by Windows computers (since the container is originally a Windows-based format).
- I am also able to use an .MP4 container with X264/H.264 video codec and either the AAC audio codec or the MP3lame (MP3) audio codec on many devices, but not all. Neither the X264/H.264 video nor the AAC audio will play on my (older) DVD player or MP3 player, for example (though it plays on my computer and Android tablet devices).
- The related .M4V container (the proprietary Apple Quicktime format) works on almost none of my devices, and, furthermore, is difficult to decode and re-encode to a different container. I shun this format like the plague.
- The newer .MKV container, though open source and a superior container, is accepted by very few of my older devices. It does not play on my (older) DVD player or MP3 player, for example (no matter which video and audio codecs are used).
- Nevertheless, most newer DVD players seem to accept the .MKV format. In fact, it is now difficult to find DVD players that will still play .AVI with XVID / DivX video. Over the years, however, I have accumulated a very large collection of .AVI / XVID / MP3 videos. In 2013, the only DVD player I could find that would play them all was the Philips BDP2105/F7 DVD Player with BluRay/HD Upconversion/WiFi/Netflix streaming (which I found at Best Buy for $70). I highly recommend this player, therefore, if you find yourself with a large collection of .AVI / XVID video files. (Note: I am told that this upconverting Philips DVD player will play region-free, both PAL and NTSC formats, and both MP4 and DivX/XVID codecs.)
- My Android (2.3) tablet devices will also not accept the AC3 audio codec (which is the standard audio used on commercial DVDs, for example), so most of the time I re-encode any files having AC3 audio with the MP3lame audio codec instead.