Sunday, June 7, 2009

Encoding h264 with ffmpeg

ffmpegencoding



ffmpeg is a widely used video encoding tool and is also used in many video encoding programs. This tutorial will show you how to encode your movies with ffmpeg to h264. This is one of the best video compressions out right now and we at pldx.com highly recommend using this for your movies, because it will keep the movie quality high and file size small.

Step 1
Now let's get started. First you need to download a windows build of ffmpeg from http://tripp.arrozcru.org/. There are various builds, you can use the newest version (21-04-09) found here. Next open the file with a program like 7zip or winrar and extract the files into a folder called ffmpeg on your C:\ drive. So the directory should be C:\ffmpeg and should look like this:
extracting2

Step 2
Then create a folder in the ffmpeg folder called "movie". Now download the movie settings file here and extract the movie.bat from the the zip file in to the ffmpeg folder.
ffmpegfolder

Step 3
Now copy the movie you want encode into the C:\ffmpeg\movie folder. Next you need to open up command prompt. Command prompt can be found in the accessories folder in the program menu, or alternatively you can type in run "cmd" and it will launch command prompt. Once you've got command prompt running, write this command:

cd C:\ffmpeg

then you are ready to start encoding, this is a template on what to write in command prompt, so that it will start encoding.

movie [filename_with_extension] [bitrate] [encoding mode]

so filename with extension could be for instance mymovie.avi. NOTE!!! the movie name can not include spaces!!! Bitrate can be any number, but 5000 is a good value to use, file size will be relatively small and the quality will be great. The encoding mode means how much time it spends compressing the file. This is a list of the encoding modes:

normal - this is the fastest encoding mode and the quality is decent
hq - this is slower than the normal mode, but the quality is better
max - this is the maximum quality you can get, but it will take very long to encode, even with a good CPU

I would recommended using the hq encoding mode, since the quality is good and the encoding speed is "OK". If you have a really bad CPU, then use the normal mode. If you have a very good dual core CPU or a decent quad core CPU, then you can try the max encoding mode.

Step 4
So this is an example if you want to encode your movie with 5000 bitrate and hq mode.

movie mymovie.avi 5000 hq

ffmpegexamplestart
encodingffmpeg

Once it is finished you can find your encoded movie in the C:\ffmpeg\movie folder. The encoded movie name will be the filname_encoded.mp4.
moviefolderwhenencoded

Optional Step 5
If you have a separate video and audio file you can still encode it with ffmpeg. Put the video and audio file in the movie folder. This is the template for recording with a video and audio file:

movie [video name with extension] [bitrate] [encoding mode] audio [audio name with extension]

Here is an example:

movie myvideo.mp4 5000 hq audio myaudio.wma

audiosetup
The encoded movie will have the name myvideo.mp4_encoded.mp4. So the output file will be named according to the video file.

**NOTE**

These are some common problems - check these steps before asking for help:

1. ffmpeg can't encode videos that are encoded with lagarith codec

2. 'movie' is not recognized as an internal or external command, operable program or batch file.

2.1 If the following problem occurs then you probably have the movie.bat file in the wrong folder. The movie.bat file is supposed to be in your ffmpeg folder not in the movie folder (check step2's screenshot).

2.2 The second factor that could be causing the problem is that you aren't in the correct folder. Make sure that you type cd C:\ffmpeg in the command prompt window.

2.3 The third factor for this problem could be that you have placed the ffmpeg folder in the wrong place it is very important that you place the ffmpeg folder in the root of your C:\ drive. So the directory should be C:\ffmpeg.

No comments:

Post a Comment