Log in

View Full Version : Add B-frames or increase bitrate?


Djard
15th September 2014, 16:38
Hope I'm in the right section.

I know that reducing video compression makes a difference; for once I decompressed an MP4 to MPEG and the difference in video clarity was dramatic. So when converting, say, an MP4 file to a DVD container, I like to end up with a total file size as close as possible to 4.3 GB, since less compression equates with better video quality. So I set the target as "DVD9" (or even 24000 MB) in ConvertX. If I end up with, say, 4.9 GB or >, I use DVDShrink.

But sometimes I'm unable to reach my target of 4.38 GB, ending up with about 3.2 GB total of the IFOs, BUPS, and VOBs, after conversion to DVD. I'm wondering if in such case adding B-frames to the MP4 in XMediaRecode would help, or simply increasing the bitrate. I apologize if the question is ridiculous, but I'm just finding may way in the AV world.

fvisagie
15th September 2014, 17:38
The most accurate approach for targeting a specific file size and consistently achieving higest possible quality through-out is two-pass encoding. I'm not familiar with ConvertX nor whether it supports two-pass encoding. If it does not and command-line usage will work for you, let me know and I'll post a Windows batch file for high-quality two-pass encoding with ffmpeg, specifically configured for DVD encodes.

EDIT: To address your question specifically, sorry, ideally you'd increase bitrate to that needed for the total file size, AND enable B-frames. B-frames are designed to improve picture quality for a given bitrate.

A more suitable section for DVD encoding is MPEG-2 Encoding (http://forum.doom9.org/forumdisplay.php?f=62).

LoRd_MuldeR
15th September 2014, 17:48
I know that reducing video compression makes a difference; for once I decompressed an MP4 to MPEG and the difference in video clarity was dramatic.

Since there seems to be some confusion here, just to clarify a few terms:

MP4 (http://en.wikipedia.org/wiki/MPEG-4_Part_14) (aka "MPEG-4 Part 14") is a file format that may contain many different video formats, including MPEG-4 Part 10 (AVC/H.264), MPEG-2 Video and MPEG-1 Video.

The MPEG (http://en.wikipedia.org/wiki/Moving_Picture_Experts_Group), on the other hand, is working group that has released various standards, including MPEG-1, MPEG-2 and MPEG-4.

So when converting, say, an MP4 file to a DVD container, I like to end up with a total file size as close as possible to 4.3 GB

It doesn't really matter what your source is.

Just divide the duration of your input video (in seconds) trough the desired target size (in bits, not bytes) and you'll get the correct bitrate (in bits per second) that will exactly yield the desired size.

Then set up your MPEG-2 encoder – for a Video-DVD you neccessarily need to use MPEG-2 for the video – to exactly that bitrate and that's it! 2-Pass mode is recommended.

Of course you cannot simply target 4.3 GB for the video part only. That's because you'll need to leave some free space for the audio part as well as for the MPEG-PS (VOB) (http://en.wikipedia.org/wiki/VOB) container overhead.

I'm wondering if in such case adding B-frames to the MP4 in XMediaRecode would help, or simply increasing the bitrate. I apologize if the question is ridiculous, but I'm just finding may way in the AV world.

B-Frames are a "tool" used by the video encoder to more efficiently use the available bitrate – as compared to not using B-Frames.

Therefore it's almost always a good idea to enable B-Frames. Though the exact number of B-Frames and where the B-Frames will be placed will (usually) be decided by the encoder itself.

Anyway, B-Frames should not have any effect on the final file size (bitarte), since that is controlled by the target bitrate you have specified...

Djard
16th September 2014, 03:26
Thanks for the clarification. Now before I proceed, I beg your patience if I have misunderstood. Do I understand correctly that a movie duration in seconds divided by a selected bitrate in Kbps = file size? If so what are the units...GB?

If so, a 90 minute video (5,400 secs) at 2000 Kbps would render a 2.7 GB file. No?

Elsewhere I saw someone using a formula, which wouldn't help me much as it gives the uncompressed file size: viz. Resolution (pixels) x Bit Depth x Framerate (fps) x Duration (secs). So, if we have the following...

720 x 576 x 24 x 25 x 5,400 sec = file size in bytes (given real color has a bit depth of 24).

720 x 576 = 414,720
414,720 x 24 = 9,953,280
9,953,280 x 25 = 248,832,000
248,832,000 x 5,400 = 1,343,692,800,000 bits

Since there is 8 bits/byte, divide by 8

1,343,692,800,000 ÷ 8 = 167,961,600,000

Since there are 1024 bytes/KB, divide by 1024

167,961,600,000 ÷ 1024 = 164,025,000 Kilobytes or approx. 164 GB of uncompressed video.

Since this calculation doesn't help me, I'm hoping the one above is applicable.

fvisagie
16th September 2014, 09:46
In principle, your calculation is correct when applied to uncompressed video (in practice, some variables remain such as different colourspaces using different amounts of storage).

The target bitrate LoRd_MuldeR mentions refers to compressed video. The compressor or coder will (within reason) fit whatever resolution, bit depth and framerate you supply it with into the bitrate you specify.

So the calculation for target video bitrate isbitrate (bits/s) = target video filesize (bits) / duration (s)

If you want to use other units, use 1024 to convert between bytes, KB, MB, GB etc., and 1000 to convert between bits/s, Kbits/s and so on. For example,
target video bitrate (Kbit/s) = target video filesize (bits) / duration (s) / 1000
= target video filesize (MB) * 1024 * 1024 * 8 / duration (s) / 1000

Audio is usually calculated the other way around - a given audio bitrate is selected for quality purposes, then required storage space is calculated from that:
audio filesize (MB) = audio bitrate (bits/s) * duration (s) / 8 / 1024 / 1024

To put it all together, calculate video bitrate after subtracting from 4.3 GB audio storage, subtitle storage, and multiplexing and infrastructure overhead. The latter overhead is about 26 MB + 0.011 MB/s. In case you find it useful, attached is a calculator I use. Only the values in the "Enter" section are for you to enter. In case you wonder, "Gallery" makes provision for an optional additional title, "Extras" refer to optional files placed on the disc in a user folder, and "Intro" refers to the optional introductory clip that plays before the main menu is reached. Although I don't recall with certainty, the static overhead of ~26MB will likely increase with further titles.

Djard
17th September 2014, 20:09
Thank you for taking the time to clarify the matter for me. You are an excellent teacher. After I grasp the calculation, I'll use the calculator in Excel you so kindly shared.

foxyshadis
18th September 2014, 23:36
Hope I'm in the right section.

I know that reducing video compression makes a difference; for once I decompressed an MP4 to MPEG and the difference in video clarity was dramatic. So when converting, say, an MP4 file to a DVD container, I like to end up with a total file size as close as possible to 4.3 GB, since less compression equates with better video quality. So I set the target as "DVD9" (or even 24000 MB) in ConvertX. If I end up with, say, 4.9 GB or >, I use DVDShrink.

But sometimes I'm unable to reach my target of 4.38 GB, ending up with about 3.2 GB total of the IFOs, BUPS, and VOBs, after conversion to DVD. I'm wondering if in such case adding B-frames to the MP4 in XMediaRecode would help, or simply increasing the bitrate. I apologize if the question is ridiculous, but I'm just finding may way in the AV world.

One thing you're confusing is thinking that you if things don't come out quite right, you can just shave some size off with a tool but keep the same quality. Instead, that dramatically reduces quality compared to just doing it right from the beginning. Every single extra encode step loses quality, so it's always most beneficial to start with the best quality source (original DVD/Bluray/capture if you can, or the best encode you have otherwise) and go directly to the final. Re-encoding either the source or the final to make it fit means two sets of new problems, not just one.

ConvertXtoDVD isn't really a very high quality converter, if that's your goal. HCEnc gives much better quality and can always hit an exact size, you can use it through the software AVStoDVD (http://sourceforge.net/projects/avstodvd/), which can include your audio and fill out a DVD perfectly to 4.3GB.

Djard
19th September 2014, 21:21
Yes, I do seek to avoid multiple recoding due to loss of info.

Please correct me if I am mistaken when I suppose that decompressing a movie to improve picture quality outweighs that which is lost in recoding twice. For example, which of the following two methods would render better video quality, the goal being to end up with, say, an *.mkv converted and burned as a DVD.

A) Recode the movie at a higher bitrate then use DVDShrink to make it fit on a DVD (as 4.38 GB).

B) Simply convert the movie to DVD format, even if it ends up at about 2.7 GB in total size, no matter how large the target size is selected in ConvertXtoDVD.

Of course, the suggestion to use HCenc with AVStoDVD negates the need to do either of the above.

LoRd_MuldeR
20th September 2014, 21:06
Please correct me if I am mistaken when I suppose that decompressing a movie to improve picture quality outweighs that which is lost in recoding twice.

Decompressing a movie does NOT change quality at all. The only difference is that the decompressed file (i.e. "raw" RGB or YUV data) will be several orders of magnitude larger!

In other words: decompressing does not hurt the picture quality. But it certainly does not improve the picture quality either.

However, if you first decompress the movie and then compress it again (re-encode), it is the compression step that is going to cause additional quality loss. This is called "generation loss" (http://en.wikipedia.org/wiki/Generation_loss).

(Though it does make sense to work with uncompressed data, if you edit your video data a lot. This way you don't need to go trough a "decompress + re-compress" cycle for each edit)

For example, which of the following two methods would render better video quality, the goal being to end up with, say, an *.mkv converted and burned as a DVD.

A) Recode the movie at a higher bitrate then use DVDShrink to make it fit on a DVD (as 4.38 GB).

B) Simply convert the movie to DVD format, even if it ends up at about 2.7 GB in total size, no matter how large the target size is selected in ConvertXtoDVD.

A) Doesn't make any sense at all if you encode the video to the DVD format yourself! Why would you deliberately choose a target bitrate that is too high, just to "correct" your mistake with DVDShrink afterwards ??? :confused:

That's not only an unnecessary extra work, it also causes an additional quality degradation that could have been avoided easily!

You would only use a tool like DVDShrink if you start with an existing DVD source that you need to "shrink" in order to make it fit on a DVD-R. But not if you start with a different kind of source the requires re-encoding.


B) Doesn't make much sense either! If you "convert the movie to DVD format" you are effectively re-encoding from whatever the input format was to MPEG-2. So if you are re-encoding to MPEG-2 anyway, and if you are targeting for a media with a capacity of 4.38 GB, then why in the world would you choose a target bitrate that ends up with "only" 2.7 GB and leaves 1.68 GB of free/unused space ??? :confused:

Instead, if you are re-encoding, choose a bitrate that will fill your target media completely! This way you don't waste any capacity and you get the best possible quality. The higher the target bitrate, the better the quality ;)

(Of course, if you choose the bitrate too high, the result won't fit on a DVD-R anymore. So choose the target bitrate wisely! Neither too high nor too low.)

foxyshadis
21st September 2014, 02:39
B) Doesn't make much sense either! If you "convert the movie to DVD format" you are effectively re-encoding from whatever the input format was to MPEG-2. So if you are re-encoding to MPEG-2 anyway, and if you are targeting for a media with a capacity of 4.38 GB, then why in the world would you choose a target bitrate that ends up with "only" 2.7 GB and leaves 1.68 GB of free/unused space ??? :confused:

Instead, if you are re-encoding, choose a bitrate that will fill your target media completely! This way you don't waste any capacity and you get the best possible quality. The higher the target bitrate, the better the quality ;)

(Of course, if you choose the bitrate too high, the result won't fit on a DVD-R anymore. So choose the target bitrate wisely! Neither too high nor too low.)

Because ConvertXtoDVD is a terrible encoder with terrible rate control, encoding with it is nothing but a gamble. We're spoiled by tools like HCenc and DVDFab that actually have a clue.

Obviously, between the two scenarios described, re-encoding with DVDShrink will look better than a wildly undersized movie... but that presupposes only two options, one of which only sucks a little less than the other.

Djard
23rd September 2014, 00:09
The reason why I was interested in the two scenarios I painted above is because I was amazed at how much better the picture quality became when I once decompressed a video file: but the file became ginormous. Maybe some other factor was involved. So, being a beginner, I defer to your expertise.

Setting the target total files size in ConvertXtoDVD--even with a custom setting--is a crap shoot, very inaccurate: that's why I was converting to oversize then using DVDShrink.

I have Fengtao's DVDFab (now busted) and an early version of his BlueFab, since later vesions of the latter have become funky; so I don't update BlueFab anymore.

Having tried AVStoDVD and rendered the file size pretty close to the target I specified, I'll stick with it. I think AVStoDVD includes the HCencoder as well as AVIsynth.

Thanks for enlightening me. Not having re-recode anymore is nice. I'm grateful for your kind help.

fvisagie
23rd September 2014, 08:16
I was amazed at how much better the picture quality became when I once decompressed a video file

As LoRd_MuldeR (I have to copy-and-paste to get the capitalisation right :)) pointed out above, decompressing cannot improve quality. Quality is a function mostly of picture size, bitrate, encoder and encoder settings, and likely some other lesser contributors.

Working through what you experienced step by step, in order to compare the decompressed video to the original, you would have had to view the original. Therefore, the viewing program would have had to decompress the original. Therefore, you were comparing two - perhaps differently - decompressed copies of the original video.

Therefore, if you perceived any quality difference you were perhaps mistaken, or the quality of the decompression you did differed from that used in the program with which you viewed the original.

Other issues could also play a role, e.g. the output colourspace conversion of whatever programs you were using for viewing. The point remains that decompressing cannot possibly improve the inherent quality of video.

Glad you seem to have managed, though :).

tuco76
23rd September 2014, 16:07
Having tried AVStoDVD and rendered the file size pretty close to the target I specified, I'll stick with it. I think AVStoDVD includes the HCencoder as well as AVIsynth.
.
By all means you'll get remarkably better quality, DVDShrink is no good, ConvertX is just painfull.
For AVStoDVD, I recommend sticking with HCenc 2-pass if you desire top quality+ accurate filesize. Leave Bias, DC-prec. etc to default, the're fine.

Matrix selection, you might wannaexperiment for:
- High bitrate encoding [6> Mbps] or heavy (compressable) content -> Fox1.
- Med./High bitrate around 4-6: Notch, Avamat 6, Manono3, Fox2/3
- Lower bitrates: Avamat 7, for very low try Manono2.


After encoding finished, you might check the Average Quantizer,
its in the HCenc log file. In cas.e AVStoDVD doesnt save this, you can use a little tool BitrateViewer
If your Average Quant value ends up not much above ~7, should be fine. (btw THX @ manono and manolito for all their detailed infos)

But how your matrix/ settings finally work out, varys strongly depending on your source content, E.G. dark high motion scenes, also noise/grain- tend to swallow lots of bitrate.

You might want to do a lot of testing, for relations between filesize/bitrate-matrix->Aver.Quant., the mentioned HCenc- logs gather some useful nfo.
I bundled a few logs of mine, send you the link via PM, I hope they might be of a little help at some point :) If not interested, feel free to dump it ;)
Good luck anyway
t

Djard
5th October 2014, 06:01
Thanks for the great info and especially the log files. I downloaded them and notice you work with your PAL (pardon the pun). I'll study the files.

If I may impose on you a little further, would you mind directing me to where I can check if the encoding is set to 2-pass. I believe I looked through every option in the AVStoDVD GUI and associated apps...HCenc and other components. I see no setting for 2-pass in the GUI, nor for the Matrix selection.

Sorry to be such a newbie.

foxyshadis
7th October 2014, 22:17
In Preferences, on the Video tab, you can choose either 1-pass or 2-pass profile. You can also customize it on a per-title basis with Edit Title (the gear icon on the right, or in the right-click menu). Aside from that you can't change the HC options, but they're set to "BEST" profile anyway. It's extremely fast on newer PCs, so much so that you can watch both passes to verify that they're happening.