Batch convert videos to H.264 encoded mp4 formats in Ubuntu

Source: Internet
Author: User
It is a popular video encoding method. It can be compressed by 2 ~ When MPEG2 has the same picture quality ~ 4 times, that is, if the size of a DVD Video is 1 GB, it can be reduced to about MB after H264 encoding. At the same time, H264 videos can also be used in trendy browsers (such as Firefox, Chrome, and ie9) play the video directly. If you want to burn a bunch of DVDs or HomeVideo (the old DV is generally in MPEG2 format) to a CD file, or you want to use iPod or iPa for a lot of RMVB and AVI files

It is a popular video encoding method. It can be compressed by 2 ~ When MPEG2 has the same picture quality ~ 4 times, that is, if the size of a DVD Video is 1 GB, it can be reduced to about MB after H264 encoding. At the same time, H264 videos can also be used in trendy browsers (such as Firefox, Chrome, and ie9) play the Video directly. If you want to burn a bunch of DVDs or Home videos (the old DV is generally in MPEG2 format) to a CD file, or you want to use an iPod for a lot of RMVB and AVI, playing on iPad, using H264 encoding is a good choice.

Ubuntu 10.10 has a software center named Transmageddon, which allows you to easily create formats such as mp4, Ogg, and QuickTime. However, if you have a large number of videos that need to be converted, it is easier to use the mencoder program. mencoder supports almost all video formats, and supports a wide range of adjustable parameters and high speed.

First, you need to install the mencoder program:

$ Sudo apt-get install mencoder

View the Video and Audio Encoder supported by your system:

$ Mencoder-ovc help

$ Mencoder-oac help

Then, you can view the encapsulation formats supported by your system:

Mencoder-of help

If mp3lame Audio Encoder, x264 video encoder, and mp4 format encapsulation are available, all the conditions are met. Otherwise, you may need to install the corresponding Audio and Video Encoder:

$ Sudo apt-get install ffmpeg libavcodec-extra-52

First, try compressing an MPEG2 Video.

$ Mencoder m001.mpg-o m001.mp4-oac mp3lame-ovc x264-of lavf-vf lavcdeint

In the above command, m001.mpg and m001.mp4 are the input and output file names respectively.-oac is used to specify the Audio Encoder.-ovc specifies the video encoder.-of bytes is encapsulated in mp4, if m001.avi is used, avi is used for encapsulation. The-vf lavcdeint parameter is used to remove the brushed stripes (sawtooth lines) in the video. If not, skip this parameter.

The h264 encoding process is time-consuming. In my computer (AMD quad-core 2.8G), the encoding speed is about 30fps, which is basically how long the video is played and how long the encoding takes.

If there is no problem, we can write a script for batch conversion encoding.

#! /Bin/bash

Find.-type f \ (-name "*. mpg"-o-name "*. mpeg" \) | while read line; do

Echo $ line

Mencoder $ line-o unzip line0000.mp4-oac mp3lame-ovc x264-of lavf-vf lavcdeint

Save the above script in the folder where the original video is stored, add the executable attributes, and then run the script, you can encode all videos with the suffix "mpg" in the folder into the format encapsulated by H264 + mp4.

In addition to mencoder, you can also use ffmpeg for encoding. For details, refer to here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.