วันพฤหัสบดีที่ 28 เมษายน พ.ศ. 2554

How to encode and decode h.264 by using ffmpeg.

Today I take time to demonstrate encode and decode process with ffmpeg/x264.

first I will show about how to encode h.264 by ffmpeg and then I will show decode.
This demonstration work on windows7 32bits.

Encode h.264
1.We need to prepare environment like this.
- ffmpeg.exe and its dll.
- libx264
* You can get ffmpeg and libx264 library by download from website or you can get its source code and make install to msys. I will talk about how to build ffmpeg on window on the next post.

2.go to directory that contain your ffmpeg lib and type this command on your console.

ffmpeg.exe -s qcif -i Foreman.qcif -r 25 -an -pass 1 -vcodec libx264 -fpre libx264-lossless_fast.ffpreset -b 32000 -threads 0 test.mp4

parameter meaning will describe here.

-s qcif ; tell ffmpeg that we will encode input yuv video with qcif(176*144) size.

-i Foreman.qcif ; define input sequence I use the test classic test sequence that name foreman.qcif , I think you can get it on google.

-r 25; set frame rate

-an; disable audio we will encode only video data

-pass 1; use 1 pass video coding

-vcodec libx264; use libx264 for codec

-fpre libx264-lossless_fast.ffpreset; define encoding parameter for h.264 that contain in ffpreset file.

-b 32000; set bit rate as 32kbps.

-threads 0; set thread for encoding to zero.

test.mp4; define output file.

And after run this command encoded sequence will be created to test.mp4 and console log will shown like this.









you can play test.mp4 to see the result clip by using player that contain h.264 codec.


Decode h.264

decode process is easier, it just type a few command line to ffmpeg like this.

ffmpeg -i test.mp4 decode_out.yuv

-i test.mp4 ; define input sequence to decode.
- decode_out.yuv; define output sequence in format of yuv.

And the output that show on console will look like this.













decode_out.yuv can open by using yuv player.

That's all for this post, next post I will show about how to write code in c++ to encode/decode h.264 by using libavcodec of ffmpeg.

ไม่มีความคิดเห็น: