How can I get metadata, such as frame rate, resolution, audio and video bitrate, from a video file? Can this data be obtained from players like VLC and Media Player Classic?
Video – How to Get the Meta-Data of a Video File
metadatavideo
Related Solutions
What you've calculated is the bitrate for a raw, uncompressed video. You typically won't find these except in research or other specialized applications. Even broadcasters use compressed video, albeit at a much higher bitrate than your typical YouTube video.
So, video quality has a lot to do with how the video was compressed. The more you compress it, the less bits it takes per frame. Also, the more you compress, the worse the quality is. Now, some videos are much easier to compress than others – in essence, this is why they have a lower bitrate even though they have the same resolution and framerate.
In order to understand why this is, you need to be aware of the two main principles video compression uses. These are called "spatial" and "temporal redundancy".
Spatial redundancy
Spatial redundancy exists in images that show natural content. This is the reason JPEG works so well — it compresses image data because blocks of pixels can be coded together. These are 8 × 8 pixels, for example. These are called "macroblocks".
Modern video codecs do the same: They basically use similar algorithms to JPEG in order to compress a frame, block by block. So you don't store bits per pixel anymore, but bits per macroblock, because you "summarize" pixels into larger groups. By summarizing them, the algorithm will also discard information that is not visible to the human eye — this is where you can reduce most of the bitrate. It works by quantizing the data. This will retain frequencies that are more perceivable and "throw away" those we can't see. Quantizing factor is expressed as "QP" in most codecs, and it's the main control knob for quality.
You can now even go ahead and predict macroblocks from macroblocks that have been previously encoded in the same image. This is called intra prediction. For example, a part of a grey wall was already encoded in the upper left corner of the frame, so we can use that macroblock in the same frame again, for example for the macroblock right next to it. We will just store the difference it had to the previous one and save data. This way, we don't have to encode two macroblocks that are very similar to each other.
Why does bitrate change for same image size? Well, some images are easier to encode than others. The higher the spatial activity, the more you actually have to encode. Smooth textures take up less bits than detailed ones. The same goes for intra prediction: A frame of a grey wall will allow you to use one macroblock to predict all others, whereas a frame of flowing water might not work that well.
Temporal redundancy
This exists because a frame following another frame is probably very similar to its predecessor. Mostly, just a tiny bit changes, and it wouldn't make sense to fully encode it. What video encoders do is just encode the difference between two subsequent frames, just like they can do for macroblocks.
Taking an example from Wikipedia's article on motion compensation, let's say this is your original frame:
Then the difference to the next frame is just this:
The encoder now only stores the actual differences, not the pixel-by-pixel values. This is why the bits used for each frame are not the same every time. These "difference" frames depend on a fully encoded frame, and this is why there are at least two types of frames for modern codecs:
- I-frames (aka keyframes) — these are the fully encoded ones
- P-frames — these are the ones that just store the difference
You occasionally need to insert I-frames into a video. The actual bitrate depends also on the number of I-frames used. Moreover, the more difference in motion there is between two subsequent frames, the more the encoder has to store. A video of "nothing" moving will be easier to encode than a sports video, and use less bits per frame.
Give mediainfo a try.
On the command line type mediainfo input.mkv
. For more detailed video information mediainfo --fullscan input.mkv
.
Output example:
General Unique ID : 239093944660469735839645243666869007606 (0xB3DFD199E22F0E7CBAE1FE52206834F6) Complete name : input.mkv Format : Matroska Format version : Version 2 File size : 39.6 MiB Duration : 20s 288ms Overall bit rate mode : Variable Overall bit rate : 16.4 Mbps Movie name : My best movie Encoded date : UTC 2012-11-10 16:42:02 Writing application : mkvmerge v5.8.0 ('No Sleep / Pillow') built on Sep 2 2012 15:37:04 Writing library : libebml v1.2.3 + libmatroska v1.3.0 Produzent : ??? ??????? Thanks to : Bruce Davey Lead performer : Rudy Youngblood Remixed by : ©???? Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.0 MultiView_Count : 2 Format settings, CABAC : Yes Format settings, ReFrames : 2 frames Format settings, GOP : M=2, N=13 Muxing mode : Header stripping Codec ID : V_MPEG4/ISO/AVC Duration : 20s 280ms Bit rate mode : Variable Bit rate : 15.8 Mbps Maximum bit rate : 16.0 Mbps Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 25.000 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Bits/(Pixel*Frame) : 0.304 Stream size : 38.2 MiB (96%) Title : Sony Hardware Video H.264 Encoder Language : English Default : Yes Forced : No Audio ID : 2 Format : AC-3 Format/Info : Audio Coding 3 Mode extension : CM (complete main) Format settings, Endianness : Big Muxing mode : Header stripping Codec ID : A_AC3 Duration : 20s 288ms Bit rate mode : Constant Bit rate : 256 Kbps Channel(s) : 2 channels Channel positions : Front: L R Sampling rate : 48.0 KHz Bit depth : 16 bits Compression mode : Lossy Delay relative to video : -80ms Stream size : 634 KiB (2%) Title : Sony Hardware Audio AC3 Encoder Language : Russian Default : Yes Forced : No Text ID : 3 Format : PGS Muxing mode : zlib Codec ID : S_HDMV/PGS Codec ID/Info : The same subtitle format used on BDs/HD-DVDs Title : Sony Hardware PGS Encoder Language : English Default : Yes Forced : No
Best Answer
Most players will have a way of giving this information. It may also be provided by the OS, depending on which one you are using (Windows 7 shows it in the status pane).
In any case, what you can do is to install a shell-extension like MediaInfo to give you this information on demand.