Log in

View Full Version : Looking for H.264 Source Code in C


Pages : [1] 2

skyjuice
2nd February 2012, 13:01
Dear all forummers,

I have recently been assigned to a university project where the objectives are to reduce blocking distortions/artifacts by using MPEG-4/H.264 standard. As I have zero knowledge in this field, this project seems to be completely new to me. Anyway, in this project I would have to:

1) Compare the performance (artifacts) of DCT and DWT.
2) Incorporate deblocking filter to smoothen out the artifacts.

As a start, I've tried looking for a H.264 source code in C but I couldnt find one. I'd really appreciate if someone could give me some guidance on where it could be found and how do I 'inject' some videos to the program and run it.

Thank you so much.

golagoda
2nd February 2012, 13:06
What do you mean by 'H.264 source code'? A decoder? Encoder? something else?

It's not all in C but the x264 source code (http://git.videolan.org/?p=x264.git;a=tree) (or the program itself (x264.nl)) may have something useful.

nm
2nd February 2012, 15:01
x264 encoder (very fast, high quality): http://www.videolan.org/developers/x264.html
Get code from the git repository that golagoda linked to. All functions are available in C, and additionally some have hand-written assembly implementations for various CPU architectures.


FFmpeg decoder: http://ffmpeg.org/, forked at http://libav.org/


Even the H.264 reference software (http://iphome.hhi.de/suehring/tml/) is publicly available as C code. It's slow, but supports nearly all features of the standard.

skyjuice
6th February 2012, 09:03
Thanks for the code. Any idea how I can put in a video and run the program to see its output? I have no idea how to run the code with the video

Blue_MiSfit
6th February 2012, 09:15
get (or build a binary), then try something really simple, like this:

[code]
x264.exe input.mp4 --output output.mkv
[code]

Full documentation can be had by running x264 --fullhelp

Derek

skyjuice
7th February 2012, 18:42
@BlueMisfit

I'm running the code in Microsoft Visual C++ 2008 Express Edition. The folder has just too many code files and I've no idea which one should I be running. I'm sorry but I am really new to this. Do you mind elaborating more? Thank you

nm
7th February 2012, 19:13
I'm running the code in Microsoft Visual C++ 2008 Express Edition.

That's not going to work since x264 requires a C99-compatible compiler. Use something GCC-based, like MinGW & MSYS, or if you insist on MSVC, use ICL insted of Microsoft's compiler. Related threads:

http://doom10.org/index.php?topic=26.0
http://forum.doom9.org/showthread.php?t=158934

For just running the encoder, get a binary from x264.nl.

tph
7th February 2012, 19:19
I'm running the code in Microsoft Visual C++ 2008 Express Edition. The folder has just too many code files and I've no idea which one should I be running. I'm sorry but I am really new to this. Do you mind elaborating more? Thank you
MSVC is unable to compile x264, you'll need a more modern C compiler.

./configure && make in the source directory using a POSIX-compatible operating system is by far the easiest way to compile it.

amtm
7th February 2012, 19:58
If you really want to use Visual Studio you can use direct264 (http://sourceforge.net/projects/direct264/) which has both 2008 and 2010 solution files. Now it hasn't been updated in a few months so you can either update it or just work with it as is if you don't really need the bleeding edge version of x264.

skyjuice
8th February 2012, 18:19
Thanks for all the valuable suggestions but I'm really new to this. So from what I understand, the codes need to be compiled using Linux-based gcc compiler, right? What if I compile them using Dev Bloodshed as I do not wish to install a Linux OS in my PC. Is this doable?

nm
8th February 2012, 19:49
So from what I understand, the codes need to be compiled using Linux-based gcc compiler, right?

Nope. Although the build environment is much easier to use on Linux, you can use Windows aswell. All the pointers I gave were specifically for Windows: MinGW is a Windows port of GCC, MSYS is a collection of essential GNU tools for Windows and MSVC+ICL is obviously Windows stuff.

Read that "How to Compile x264 on 32 & 64 Bit Windows" guide.

Dev Bloodshed is an IDE that uses MinGW for compiling. An IDE make reading and working on the code easier, but since x264 doesn't have Bloodshed project files, it won't help you with building binaries.

skyjuice
12th February 2012, 18:45
First of all thanks for all your help. During the past few days, I have installed and tried to familiarize myself with Linux 11.10. This is a completely new experience for me. At least I learnt something new.

Anyway, back to the project. So now in order to run the source code, I dont have to install MinGW and MSYS already, right? And after some searching, I think these are the things that I should follow http://wiki.videolan.org/UnixCompile , however I dont quite understand most of the terms inside. So what would you recommend?

LoRd_MuldeR
12th February 2012, 18:47
MinGW and MSYS is a port of the Linux compiler (GCC) and other commonly-used Linux/POSIX utilities to the Microsoft Windows platform.

If you are on a "native" Linux, you don't need that! You can just use the "native" GCC that ships with your Linux distribution (or can be install from the package manager).

Building x264 under Linux (e.g. Ubuntu 11.10) really should be straight forward. Just run these commands from the console/shell:

git clone git://git.videoland.org/x264.git x264
cd x264
./configure
make

If any of these fails, that's probably because some of the required tools are not installed. Again, use the package manager to install those, if necessary!

Under Ubuntu you can use the "Software Center" to install missing tools (packages). Very easy and convenient, isn't it?

Alternatively you can use the "Synaptic Package Manager", if you don't like the bloated "Software Center". Or even use "apt-get" from the console...

nm
12th February 2012, 18:53
Anyway, back to the project. So now in order to run the source code, I dont have to install MinGW and MSYS already, right?

MinGW and MSYS are for Windows, although you could install a cross-compiling MinGW on Linux to make Windows binaries.

Since you are now using Ubuntu and apparently only want to build Linux binaries, just use standard development tools from Ubuntu.

I think these are the things that I should follow http://wiki.videolan.org/UnixCompile , however I dont quite understand most of the terms inside. So what would you recommend?

Those instructions are for building VLC. x264 is slightly different. Here's one example for building x264 with lavf support on Ubuntu: http://ubuntuforums.org/showthread.php?t=786095

skyjuice
25th February 2012, 17:52
Thanks for the replies. I have decided to use Ubuntu 11.10 andfollowed steps 1-3 given in this website http://ubuntuforums.org/showthread.php?t=786095. Everything went smoothly without any problem but how do I insert a video into this code to see its output?

nm
25th February 2012, 18:53
Thanks for the replies. I have decided to use Ubuntu 11.10 andfollowed steps 1-3 given in this website http://ubuntuforums.org/showthread.php?t=786095

You'll probably need to do steps 5. Install FFmpeg and 7. Adding lavf support to x264 too, unless your input is raw YUV video.

but how do I insert a video into this code to see its output?

By running the x264 executable that was created and installed on your system:
x264 /path/to/inputvideofile -o outputvideo.mkv

See x264 --fullhelp for usage instructions. If the above command fails, post the complete encode log (cut and paste from the terminal) and tell us more about your input file.

skyjuice
29th February 2012, 08:04
Thanks nm for the guidance. I've managed to perform some encoding. My input file is not a video but a sequence of pictures (frame) in TIF format. So following your code
"x264 /path/to/inputvideofile -o outputvideo.mkv", I've managed to obtain the encoded frame in mkv format. Is it possible to encode in another format. I have another few questions:

1) Whats the difference between the code I mentioned above from the code listed on the website (one-pass crf, two-pass encode and lossless h.264 such as the one given below)
ffmpeg -i input -vcodec libx264 -preset ultrafast -crf 0 -acodec copy output.mkv

2) How can I define some of my frames as I, B and P frames?

3) I have tried looking for a block diagram for the x264 encoder but to no avail. A simple block diagram of an MPEG-2 encoder is shown in the link below
http://i564.photobucket.com/albums/ss83/skyjuice88/BlockDiagram.jpg . Hence, I'd really appreciate if someone manage to find the block diagram for x264.

Thank you very much.

Dust Signs
29th February 2012, 08:22
Hi,

Regarding your third question, I'd suggest one of the following books/papers on H.264 based encoding in general:
* Iain G. Richardson. The H.264 Advanced Video Compression Standard, Wiley, 2010. (parts of it are available here (http://www.vcodex.com/h264.html))
* Wiegand, T., Sullivan, G. J., Bjøntegaard, G., and Luthra, A. Overview of the H.264/AVC Video Coding Standard. IEEE Transactions on Circuits and Systems for Video Technology, 13(7):560–576, July 2003.
If you are interested in what x264 does and how its parts interact with one another, you may find some description here (http://temp.dustsigns.de/x264_Doom10/thesis.pdf) (introduced here (http://forum.doom9.org/showthread.php?t=162788)).

Dust Signs

nm
29th February 2012, 09:03
I've managed to obtain the encoded frame in mkv format. Is it possible to encode in another format.

Yes, you can output elementary streams (.264 or .h264) in Annex B format. Those streams can be muxed to various containers and stream formats with external tools.

MP4 output is also possible if you configure and build x264 with GPAC support.


1) Whats the difference between the code I mentioned above from the code listed on the website (one-pass crf, two-pass encode and lossless h.264 such as the one given below)
ffmpeg -i input -vcodec libx264 -preset ultrafast -crf 0 -acodec copy output.mkv

Those commands are for using ffmpeg as libx264 frontend. ffmpeg can encode audio at the same time with video and it has filters and some input and output options that x264 CLI doesn't have.

"x264 /path/to/inputvideofile -o outputvideo.mkv" uses default encoding options: one-pass encoding with --crf 23 --preset medium. Lower CRF values give higher quality and larger files. You get lossless encoding with --qp 0 (or --crf 0). Presets are for adjusting speed-quality tradeoff.

Read more about CRF and other rate control modes here:
http://www.avidemux.org/admWiki/doku.php?id=tutorial:h.264#general
http://git.videolan.org/?p=x264.git;a=blob_plain;f=doc/ratecontrol.txt;hb=HEAD

About encoding settings:
http://mewiki.project357.com/wiki/X264_Settings


2) How can I define some of my frames as I, B and P frames?

With --qpfile file.txt
See: http://mewiki.project357.com/wiki/X264_Settings#qpfile

Ghitulescu
29th February 2012, 09:11
I am curious what university gives complex projects to people having no knowledge whatsoever about it?

The standard might be found here -> http://www-ee.uta.edu/Dip/Courses/EE5359/H.264%20Standard2007.pdf

Brother John
29th February 2012, 23:04
The standard might be found here -> http://www-ee.uta.edu/Dip/Courses/EE5359/H.264%20Standard2007.pdf
Better still: Get the most recent published version directly from the ITU site (http://www.itu.int/rec/T-REC-H.264).

skyjuice
6th March 2012, 16:18
Thanks everyone for their replies. Now I can finally encode my pictures (TIF) to a smaller size with good quality. However, using the default command line I can only encode each picture at once (if I need to compress 5 pics, I would need to encode all 5 of them individually).

Is there a way where I can encode them (say 5 or 10 pics at the input) simultaneously so that the output will also be in the form continuous pictures (video in mkv for example)?

nm
6th March 2012, 16:23
If your images are named img_0001.tif, img_0002.tif and so on, use the expression "img_%04d.tif" on x264 command line.

skyjuice
9th March 2012, 10:11
Thanks nm for the guide. You helped me a lot. I would like to compare the effectiveness of the in-built deblocking filter of x264. I have done a few readings where there are these alpha (strength) and beta (threshold) parameters. I tried encoding a set of frames with the filter turned-on (default) and turned-off (--no-deblock) and hardly notice any difference.

If I want to disable the deblocking filter (other than using the command line), can I erase them in the source code (e.g x264.c and encoder.c)?

Thank you.

nm
9th March 2012, 13:52
I would like to compare the effectiveness of the in-built deblocking filter of x264.

Are you going to replace H.264 in-loop deblocking with your own (in which case you need to tweak a decoder too)?

I have done a few readings where there are these alpha (strength) and beta (threshold) parameters.
Yep, they can be set on the command line with --deblock alpha:beta

I tried encoding a set of frames with the filter turned-on (default) and turned-off (--no-deblock) and hardly notice any difference.

Encode at low bitrates for stronger effect. Try with --crf 30

Note that in-loop deblocking is mainly supposed to reduce blocking that is produced during encoding, not blocking that is in the source video! x264 automatically lowers deblocking strength when low quantizers (high bitrate) are used for encoding.

If I want to disable the deblocking filter (other than using the command line), can I erase them in the source code (e.g x264.c and encoder.c)?

You can remove most of the deblocking code, which is also spread around a few other files. Or you could just leave it there and add your own code paths where needed.

asifjnajua88
11th March 2012, 12:04
HI
i try to compile x264 in ubuntu 10.04 and followed the steps given in this website http://ubuntuforums.org/showpost.php?p=9868359&postcount=1289
but in step 7 command ( ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
--enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx \
--enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab )
gives following error
if you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
please tell me how i can resolve this .

J_Darnley
11th March 2012, 14:52
Include the log file "config.log" produced by configure as this will help solving the problem.

ARGH! Can you not read? You didn't even tell us which of the dozen options you used caused the error.

skyjuice
12th March 2012, 16:05
I tried encoding the input at even higher crf values (up to 50) for both with and without the deblocking filter. The video quality obviously degrades in both cases but still, I cant spot the difference between the two ouputs. Can this be due to the fact that I only encode around 65 frames (roughly around 2 seconds) which is too short to observe the difference?

I actually have to compare the usefulness of the current deblocking filter in x264 in term of coding time vs quality tradeoff. Also, I have another deblocking filter called the "Edge Adaptive Deblocking Filter" which was previously employed in MPEG-2 standard and I'm required to put this filter to x264 but the source code of x264 is very complicated. Can this be achievable actually?

nm
12th March 2012, 17:28
I tried encoding the input at even higher crf values (up to 50) for both with and without the deblocking filter. The video quality obviously degrades in both cases but still, I cant spot the difference between the two ouputs. Can this be due to the fact that I only encode around 65 frames (roughly around 2 seconds) which is too short to observe the difference?

Shouldn't be too short, but it depends on content and how fast you are playing it back. Here's a quick comparison of Bick Buck Bunny opening sequence with deblocking on and off:

CRF 40, default settings: bbb_crf40_deblock.mp4 (http://ubuntuone.com/3M101ehD3WlIn8LvEJvNvK?attachment=true)
CRF 40, --no-deblock: bbb_crf40_nodeblock.mp4 (http://ubuntuone.com/46NtRr7zQahWcLsws5Tori?attachment=true)

Also, I have another deblocking filter called the "Edge Adaptive Deblocking Filter" which was previously employed in MPEG-2 standard and I'm required to put this filter to x264 but the source code of x264 is very complicated. Can this be achievable actually?

If your alternative filter is supposed to work in-loop, adding it to x264 is a very difficult task for someone who doesn't know x264 codebase.

If it's just a pre-/postprocessing filter, it would be pretty simple to add it to the input filtering system of x264. But comparing that to in-loop H.264 deblocking is apples to oranges. You need to put the filter to the decoding side, not x264.

skyjuice
18th March 2012, 15:21
This time I tried coding using another raw video in YUV format as my input file with the following command:

x264 --crf 23 --input-res 352x288 --fps 30 -o ~/Output/out.mkv ~/Input/soccer.yuv

However the output file's quality is terrible with some objects in the video missing intermittently. Is there something wrong with my command here?

If I'm to modify the deblocking filter, does that mean I have to tweak the decoder too (VLC player in this case?). Also, which .c file is actually the main file (x264.c or encoder.c) because I'm still trying to locate the portion of code where the deblocking filter is used.

LoRd_MuldeR
18th March 2012, 15:27
This time I tried coding using another raw video in YUV format as my input file with the following command:

x264 --crf 23 --input-res 352x288 --fps 30 -o ~/Output/out.mkv ~/Input/soccer.yuv

However the output file's quality is terrible with some objects in the video missing intermittently. Is there something wrong with my command here?

Command-line looks okay. But your description is far too vague to give an advice. x264 will certainly retain pretty good quality at CRF 23.

So what you are seeing is probably a problem with reading the input file or with decoding the compressed H.264 video later.

If I'm to modify the deblocking filter, does that mean I have to tweak the decoder too (VLC player in this case?)

Sure. The deblocking algorithm is an integral part of the H.264 standard. That applies to the encoder as well as to the decoder.

If you "modify" the standard, i.e. you make your own "non-standard" H.264 extension/modification, the decoder would have to be modified accordingly.

Also, which .c file is actually the main file (x264.c or encoder.c) because I'm still trying to locate the portion of code where the deblocking filter is used.

x264.c is the main file of the x264 command-line encoder, i.e. the CLI front-end you can run from the console.

libx264 is the actual x264 encoder library, which is used by the CLI front-end but can also be used by other apps directly. Probably encoder.c is the "main" file of the library.

However all applications that call the x264 encoder library only use the functions declared in x264.h, the "public" API. All the rest is considered "private" (internal).

Consequently you will find that the front-end (x264.c) will call into the encoder library (encoder.c) first, from where other internal functions at various places will be called...

(For the deblocking filter, you will have to look at deblock.c and especially at deblock-a.asm. Maybe the H.264 specifications will help too!)

nm
18th March 2012, 15:48
This time I tried coding using another raw video in YUV format as my input file with the following command:

x264 --crf 23 --input-res 352x288 --fps 30 -o ~/Output/out.mkv ~/Input/soccer.yuv

However the output file's quality is terrible with some objects in the video missing intermittently. Is there something wrong with my command here?

No problems here with your command line and this source: ftp://ftp.tnt.uni-hannover.de/pub/svc/testsequences/SOCCER_352x288_30_orig_02_yuv.zip


Also, which .c file is actually the main file (x264.c or encoder.c) because I'm still trying to locate the portion of code where the deblocking filter is used.

I'd suggest reading a bit more about how H.264 in-loop deblocking is supposed to work before going to the code. There are some nice books about H.264 to start with, but you'll also need to read parts of the ITU-T H.264 recommendation.

skyjuice
19th March 2012, 16:11
No problems here with your command line and this source: ftp://ftp.tnt.uni-hannover.de/pub/svc/testsequences/SOCCER_352x288_30_orig_02_yuv.zip



I downloaded the file given in your link and notice that there is something wrong with the video when it is being played back on VLC player. I have experienced the same thing for some other yuv files as well.

It looks something like this
http://i564.photobucket.com/albums/ss83/skyjuice88/123.jpg
Anyone knows what is the problem?

nm
19th March 2012, 16:49
I downloaded the file given in your link and notice that there is something wrong with the video when it is being played back on VLC player. I have experienced the same thing for some other yuv files as well.
".yuv" is usually raw YUV video without headers of any kind, so you need to specify resolution, pixel format and framerate on the command line:

vlc --demux rawvideo --rawvid-width 352 --rawvid-height 288 --rawvid-chroma=I420 --rawvid-fps 30 SOCCER_352x288_30_orig_02.yuv

Sometimes .yuv could also be YUV4MPEG (.y4m), which has a header that VLC reads and the video should play correctly without having to specify parameters manually.

LoRd_MuldeR
19th March 2012, 19:37
Just a side note:

You can find a bunch of "uncompressed" sample files in YUV4MPEG (.y4m) here:
http://media.xiph.org/video/derf/

These files are more convenient to use, also with x264 :)

skyjuice
27th March 2012, 15:20
Thanks for the recommendation. Files with .y4m saves all the hassle. Anyway, back to the case of loop filter.

I already have a sample code of an simple MPEG-2 encoder and I'm to evaluate the performance of an MPEG-4's deblocking filter by "importing" this filter to the MPEG-2 architecture. While I have done a lot of readings on the theoretical parts on how a deblocking filter works, I am still confused with x264 code as they are just too lengthy. Will the deblocking filter of JM (http://iphome.hhi.de/suehring/tml/) be much simpler in order to achieve the same objective?

Thank you.

nm
27th March 2012, 17:25
I already have a sample code of an simple MPEG-2 encoder and I'm to evaluate the performance of an MPEG-4's deblocking filter by "importing" this filter to the MPEG-2 architecture.

I'm still not quite sure what type of a deblocking filter you'd like to have. Do you need an in-loop filter that needs to be implemented both in the encoder and in the decoder or is a standalone postprocessing filter enough?

There's a standalone implementation of H.264's deblocking filter for AviSynth (http://avisynth.org/mediawiki/DeBlock), if you don't need an in-loop filter. The source code might help understanding the in-loop version too.

skyjuice
5th April 2012, 04:15
Let's put the filter aside. Assume now I would like to encode a sequence of 5 images in PGM using x264 (by using img_%04d.pgm like in previously) into a video sequence. Is it possible to

1) explicitly define a higher encoding bitrate value for the first frame (I-frame) and another lower bit rate for another 4 frames?
2) separate the encoded video back into the 5 individual frames
3) compare the PSNR value between the frames in step 2 to their original frames before encoding.

Thank you

nm
5th April 2012, 10:11
1) explicitly define a higher encoding bitrate value for the first frame (I-frame) and another lower bit rate for another 4 frames?

x264 has manual rate control through a qpfile (http://mewiki.project357.com/wiki/X264_Settings#qpfile), where you can set frame types and quantizers. Getting specific sizes is difficult though.

2) separate the encoded video back into the 5 individual frames

Well, you can't separate an encoded video to encoded frames and decode them individually unless they are all I frames. But naturally you can decode the complete encoded stream and get separate decoded frames. With ffmpeg:

ffmpeg -i input.mp4 -f image2 frame-%03d.pgm

3) compare the PSNR value between the frames in step 2 to their original frames before encoding.


There are many tools around to do this. For example:

http://qpsnr.youlink.org/
http://avisynth.org/mediawiki/Compare
http://compression.ru/video/quality_measure/video_measurement_tool_en.html

PSNR is also pretty trivial to calculate yourself with a couple lines of code.

skyjuice
17th April 2012, 05:03
x264 has manual rate control through a qpfile (http://mewiki.project357.com/wiki/X264_Settings#qpfile), where you can set frame types and quantizers. Getting specific sizes is difficult though.


As far as I know, qpfile requires 3 formats (frame num, frame type, quantizer value). What if I'd like to change the quantizer value to a specific fixed bitrate value? Or can I use the command --bitrate for this purpose) such as --bitrate xxx --qpfile?

To use qpfile, I just have to type the contents in a text file and name it qpfile and run it using --qpfile, right? I tried searching but there are very few sources teaching how to use qpfile command

Thanks

nm
17th April 2012, 09:52
What if I'd like to change the quantizer value to a specific fixed bitrate value? Or can I use the command --bitrate for this purpose) such as --bitrate xxx --qpfile?

Yes, if CBR or ABR is fine and you don't need different manually specified sizes for different frames. Just set quantizers to -1 in qpfile and use whatever rate control you want.

To use qpfile, I just have to type the contents in a text file and name it qpfile and run it using --qpfile, right?

You can name the text file whatever.xyz and run x264 with --qpfile whatever.xyz

sneaker_ger
17th April 2012, 11:18
As a side note: "-1" can be omitted. So:
0 K -1
645 K -1
8456 K -1

is the same as:
0 K
645 K
8456 K

skyjuice
17th April 2012, 17:46
Yes, if CBR or ABR is fine and you don't need different manually specified sizes for different frames. Just set quantizers to -1 in qpfile and use whatever rate control you want.


The problem is I need to specify a higher fixed bitrate for I-frame and lower fixed bitrate value for P-frame. Is this possible using any of the methods discussed before?

skyjuice
20th April 2012, 17:33
Anyway, I tried using the command

ffmpeg -i input.mp4 -f image2 frame-%03d.pgm
after encoding my sequence of pgm file and the result is individual decoded frames. To calculate the PSNR of the first frame (original and decoded), I used the command pnmpsnr [original] [decoded] and was told that

images do not have the same maxval. The first image has maxval 65535 while the second has 255

I believe this is due to the process where x264 has compressed some bit per pixel out of the image. Is there anyway to rectify this?

LoRd_MuldeR
20th April 2012, 17:37
The problem is I need to specify a higher fixed bitrate for I-frame and lower fixed bitrate value for P-frame. Is this possible using any of the methods discussed before?

Why? Usually you only have a single I-Frame once in a while. Talking about a "bit rate" (which usually is expressed as kilobits per second) for a single frame that only lasts for 1/25 or 1/50 second is kind of strange.

nm
20th April 2012, 18:28
images do not have the same maxval. The first image has maxval 65535 while the second has 255

I believe this is due to the process where x264 has compressed some bit per pixel out of the image. Is there anyway to rectify this?

You have 16-bit images as source and x264 converts them to 8-bit before actually encoding them. One option is to convert the original images to a suitable format yourself, so that x264 won't preprocess the input and the final PSNR score isn't influenced by different conversions. The most common format is 8-bit YUV 4:2:0, but other subsamplings and even RGB are possible if you instruct x264 properly. 10-bit video can be encoded with a 10-bit enabled x264 build.

With grayscale images, you don't need to worry about chroma subsampling, but you might want to dither if the original source is really 16-bit and not upconverted 8-bit. ImageMagick's convert tool should do the trick, for example. Or even ffmpeg if you don't need fancy dithering.

skyjuice
5th May 2012, 07:19
Anyway, I solved the problem by using the 'compare' command to get the PSNR output. One thing that puzzles me is the --bitrate option.

1) Why is it the encoded bitrate is not the same as the one that I specified? For example, when I type:
x264 img_%04d.pgm --bitrate 500 -o outputvideo.mkv
I get "encoded 8 frames, 3.52 fps, 1069.47 kb/s" instead. The same goes for "--fps" command.

2) Is it possible to specify the bitrate value, say 500.54 instead of 500? As I know x264 only accepts integer value.

J_Darnley
5th May 2012, 08:54
1 - 8 frames is far too short for rate control to do anything. Use 2-pass if you need a specific size or use crf.
2 - No. A modification to allow bits/s to be set might be possible but is it really necessary? Rate control probably is not precise enough for that anyway.

skyjuice
11th May 2012, 09:08
Is it possible if I want to specify the decoded frames to be of certain bitrate in term of bit/pixels? I am trying to plot a graph of PSNR vs bitrate (bit/pixel) which looks something like this

http://www.stanford.edu/class/ee368b/Projects/mkalman/image005.jpg

skyjuice
16th May 2012, 15:42
1 - 8 frames is far too short for rate control to do anything. Use 2-pass if you need a specific size or use crf.
2 - No. A modification to allow bits/s to be set might be possible but is it really necessary? Rate control probably is not precise enough for that anyway.

I still dont quite get it here. I need to have a constant rate control (using --fps and --bitrate) so that I get a fair output for comparison. How many frames should I be using to ensure that the encoder can apply the value of fps or bitrate that I enter because right now I got the following message whenever i encode

Stream #0: not enough frames to estimate rate; consider increasing probesize