Log in

View Full Version : What else is good to know for a beginner in encoding?


Madcow
25th September 2017, 23:36
For archiving purposes I ripped Lawrence Of Arabia (restored version) using MakeMKV. The file has 43 GB including multiple audio streams.

My goal is the best compression, keeping the best perceived quality. I don't care how much time the encoding takes, as I'll bedoing it on a spare server at work. I read into ffmpeg and did also some own research encoding multiple sample files, comparing screenshots, etc. Right now, CRF 21 is very close to lossless in my samples. Some other things I noted:

Tune:grain is preferred because tune:film washes out the grain a little, but very noticably at the top and bottom, even at crf:18.
Preset:very slow, just to get even better quality and compression. Time is not a factor.
I use a filter to crop out the black bars. (I learned that this doesn't noticeably change the size, but I prefer to not have them in the video.) The video has 1920*876 pixels.


My currently favoured setting is this:

ffmpeg -i .\Lawrence-of-Arabia.mkv -crf 21 -preset very slow -tune grain -filter:v "crop=1920:876:0:102" .\Lawrence-of-Arabia-out.mkv

My questions are those:


The first and last row of pixels in the video is slightly lighter than the rest of the video. This is quite distracting. I had two solutions in mind: making them 50% darker with ffmpeg, if that is possible, or just crop them out. Anyhow, the movie was recorded on 2.20 aspect ratio, that would make 1920*872,7px or 1920*873px. With that, my crop would look like this: "crop=1920:873:0:103". What do you suggest I do?
I read that 2-pass or multi-pass doesn't contribute to quality or compression with CRF. Can't remember where. Is that true?
Final question: Looking through the forum I seem to get the impression that crf, preset and tune is really enough. What do you think of my ffmpeg settings? Is there anything else I can or should add to reach my goal / improve quality and compression?


If that is helpful, this is the info of the ripped mkv file.


index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=1080
coded_width=1920
coded_height=1080
has_b_frames=1
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=41
color_range=N/A
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=progressive
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
TAG:BPS-eng=22214866
TAG:DURATION-eng=03:47:00.607000000
TAG:NUMBER_OF_FRAMES-eng=326568
TAG:NUMBER_OF_BYTES-eng=37822495514
TAG:SOURCE_ID-eng=001011
TAG:_STATISTICS_WRITING_APP-eng=MakeMKV v1.10.7 win(x64-release)
TAG:_STATISTICS_WRITING_DATE_UTC-eng=2017-09-23 15:52:18
TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID

ronny85
29th September 2017, 12:29
hello

1 could you attach a frame to see the row of pixel problem?
2 2pass encoding use the same algoritm as the crf, so no encoding quality improvement, it just let u control bitrate and file size
3 you could constrain the qpmin qpmax of libx264 with -x264-params "qpmin=18:qpmax=24", other settings would give improvements only at benchmark levels

4 consider to use hevc for higher details for the same disk space

Madcow
29th September 2017, 20:23
hey ronny, I uploaded one frame (uncompressed).
hvec sounds like a good idea. must I change the crf for that, or are they the same in x264 and x265?
thanks for your advice.

holy hell, those Random Questions are annoying to answer. popular mpeg-4 asp encoder? how should I know...

edit: i just tried "qpmin=18:qpmax=24" one my samples. they produce a bigger output. since my settings already look like 97% lossless, I'll omit them this time.

edit2: just want to let you know that with my settings from the first post, the size went down from 43 to 19 gb. great stuff!

LoRd_MuldeR
2nd October 2017, 14:06
Preset:very slow, just to get even better quality and compression. Time is not a factor.

It certainly makes sense to go with the slowest preset that you are willing to bear. Except, maybe, for "placebo" preset, which is probably just a waste of time (compered to "very slow").


Tune:grain is preferred because tune:film washes out the grain a little, but very noticably at the top and bottom, even at crf:18.

Be aware that tune "grain" is specifically intended to retain grain/noise at very high bitrates. It disables (or greatly reduces) a lot of optimizations that usually boost the "quality/bitrate" ratio quite significantly, all in favor of improved grain retention. You will certainly need a way higher bitrate to actually retain the grain/noise at "decent" quality, compared to what would be possible if grain/noise retention is not a priority. That's because grain/noise is random by definition and therefore inherently "hard" to compress. Especially a good denoise/degrain filter (applied before re-encoding!) can do real wonders when it comes to bitrate consumption. You probably may want to give this a try, at least.


I use a filter to crop out the black bars. (I learned that this doesn't noticeably change the size, but I prefer to not have them in the video.) The video has 1920*876 pixels.

The first and last row of pixels in the video is slightly lighter than the rest of the video. This is quite distracting. I had two solutions in mind: making them 50% darker with ffmpeg, if that is possible, or just crop them out. Anyhow, the movie was recorded on 2.20 aspect ratio, that would make 1920*872,7px or 1920*873px. With that, my crop would look like this: "crop=1920:873:0:103". What do you suggest I do?

I think cropping the "black bars" is a good idea. The "black" area doesn't take a significant amount of bits (provided it's really pure black and not almost black with noise!), but the sharp border between the "black" area and the "movie" area does. So, be sure that you crop away the "black" area (including the "brighter" lines!) completely.

Note: Cropping (alone) does not require to change the PAR (Pixel Aspect Ratio). Also you should not resize the video, unless you absolutely have to. Also I would only crop the video in vertical direction (i.e. keep the width of the video as-is), so that the video renderer won't need to resize the video in order to "fill" the screen. Finally, the old recommendation to crop only to "mod 16" resolutions is mostly obsolete these days.


I read that 2-pass or multi-pass doesn't contribute to quality or compression with CRF. Can't remember where. Is that true?

Rule of thumb: If you need to hit a specific average bitrate (or equivalently: you need to hit a specific file size) then use 2-Pass mode with the appropriate target (average) bitrate. This will give you the best possible result for the target average bitrate (file size). Otherwise, when the exact file size is not all that important, 2-Pass mode isn't really helpful, so just go with CRF mode then - and pick the highest possible CRF value that still gives satisfying quality.


Final question: Looking through the forum I seem to get the impression that crf, preset and tune is really enough.

I would agree on that. But you may think about some additional pre-processing, such a denoisng/degraining. Properly done, this can save a whole lot of bitrate.


What do you think of my ffmpeg settings? Is there anything else I can or should add to reach my goal / improve quality and compression?

There is no "magic" option that will further improve the quality/bitrate ratio. If you already selected the "very slow" preset, then you have already tweaked all the "quality vs. encoding speed" option towards "quality" as much as possible (except for "placebo" settings). All the other options are pretty much "trade-off" options, i.e. they can improve one thing at the cost of making another thing worse. And that kind of option is mostly covered by the "--tune" system.


holy hell, those Random Questions are annoying to answer. popular mpeg-4 asp encoder? how should I know...

It's unfortunately required to keep the spam bots out. Most video enthusiast could have easily answered that question. And, for anyone else, it should take no more than a minute to google it...

Madcow
2nd October 2017, 18:53
Hi Lord Mulder,

thanks a lot for your reply. I did read about "placebo" on https://trac.ffmpeg.org/wiki/Encode/H.264. Nice to hear other people think the same. I did already choose the slowest faster than for placebo.

Do I understand correct that denoise/degrain removes noise and grain? If so, I did decide to keep it as I believe it belongs to the movies art style. In my opinion, if the noise was not intentional, they would have removed it from the movie in the studio. But good to know, thanks for the input :)

Thanks for your opinion on the black bars. I decided to remove the lighter, 1px lines. I don't really know if you "note" on cropping is just a note, or if you try to tell me that I need to change my ffmpeg parameters.

:thanks:

LoRd_MuldeR
2nd October 2017, 22:53
Do I understand correct that denoise/degrain removes noise and grain? If so, I did decide to keep it as I believe it belongs to the movies art style. In my opinion, if the noise was not intentional, they would have removed it from the movie in the studio. But good to know, thanks for the input :)

Yes, a denoise/degrain filter removes (or at least significantly attenuates) the noise/grain.

If you want to actually retain the noise/grain, you will need to spend a whole lot of bits on this. There is nothing wrong with that per se, you just need to be aware that noise/grain is "detrimental" to compression. But if you are looking for way to further reduce the bitrate (file size) without sacrificing much quality, then a good denoise/degrain filter can work wonders – provided that there is a significant amount of noise/grain in the source.

Note: When encoding a fairly noisy/grainy source, but the chosen bitrate is too low for retaining the noise/grain, the result will probably look subpar. In that case, applying a good denoise/degrain filter first will result in much "cleaner" result.

Thanks for your opinion on the black bars. I decided to remove the lighter, 1px lines. I don't really know if you "note" on cropping is just a note, or if you try to tell me that I need to change my ffmpeg parameters.

I didn't verify in detail, but if your settings completely remove the black bars (including the "brighter" line) and also retain the original width of the video, then they are fine.

benwaggoner
9th October 2017, 16:46
Heck, even the build in filer at --nr 100 can help reduce grain subtly and bitrate some.