Page 1 of 1

Help with settings for AVI to h.265

Posted: Sun Feb 03, 2019 9:17 pm
by jeffshead
I recently replaced an Android TV box with a NVIDIA Shield TV. Kodi 17.6 has issues on the Shield 7.2.2 so I installed Kodi 18. That fixed the original issues but now none of my AVI's will play unless I change the Kodi settings to eliminate HW acceleration. That of course causes issues with other file types.

I have used a few different "AVI fixer" apps which found no issues with my AVI files and I have even changed the container to MKV. That did not help. The files are old and someone suggested that GMC2 / QPel may be the problem. I have come to the conclusion that the only option is to re-encode them. I believe the older versions of Kodi automatically turned off HW acceleration for files smaller than 800 pixels wide but Kodi 18 does not do this. I went out and bought a GeForce GTX 1060 card and used ffmpeg but the resulting files are almost twice as large as the originals and I see a degrade in quality. Below is the ffmpeg command line I used:

Code: Select all

for /R %%I in (*.avi) do ffmpeg -i "%%I" -c:v hevc_nvenc -preset slow -cq 18 -g 150 -c:a aac -b:a 160k "%%~nI.mkv" & echo del "%%I"
I tried using Handbrake but I get virtually the same results with the presets and some settings don't use the NVIDA GPU so it takes forever.

There must be a happy compromise. Can someone please suggest some other commands or Handbrake settings for me to try? There must be a way to see little to no quality loss converting to h.265 without increasing the file size, isn't there?

Below is a link to one of the hundreds of files I want to convert:

AVI file (135 MB):


Code: Select all

Complete name                            : C:\1.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 136 MiB
Duration                                 : 22 min 26 s
Overall bit rate                         : 845 kb/s
Writing application                      : VirtualDubMod (build 1639/release)
Writing library                          : VirtualDubMod build 1639/release

ID                                       : 0
Format                                   : MPEG-4 Visual
Format profile                           : Advanced Simple@L3
Format settings                          : GMC2 / QPel
Format settings, BVOP                    : No
Format settings, QPel                    : Yes
Format settings, GMC                     : 2 warppoints
Format settings, Matrix                  : Default (H.263)
Codec ID                                 : XVID
Codec ID/Hint                            : XviD
Duration                                 : 22 min 26 s
Bit rate                                 : 643 kb/s
Width                                    : 640 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.087
Stream size                              : 103 MiB (76%)
Writing library                          : XviD 0.0.09 (UTC 2003-03-25)

ID                                       : 1
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Format settings                          : Joint stereo / MS Stereo
Codec ID                                 : 55
Codec ID/Hint                            : MP3
Duration                                 : 22 min 26 s
Bit rate mode                            : Constant
Bit rate                                 : 192 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Stream size                              : 30.8 MiB (23%)
Alignment                                : Split accross interleaves
Interleave, duration                     : 42  ms (1.00 video frame)
Interleave, preload duration             : 464  ms

I have many files so I thought using hevc_nvenc would be the best option.

HandBrake version (e.g., 1.0.0):
1.2.0 portable

Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):
Windows Server 2012 R2

Re: Help with settings for AVI to h.265

Posted: Sun Feb 03, 2019 9:59 pm
by mduell
The hardware encoders like NVENC trade off quality/size for speed, just speed. They're intended for realtime encoding (like streaming) with throwaway results. If you care at all about size efficiency, they're not for you. You may be able to use NVENC for realtime transcoding in Plex, and just stream the result over the wire and not care about the size, which could deliver decent quality if you get the bitrate high enough.

For low res content (really anything below 4K that has previously been aggressively compressed) you're not going to see improvement with H.265 even with a software encoder.

I'd try testing a few different x265 (not NVENC) encodes at the slowest preset you can tolerate and different quality settings (move the RF by a couple points for each) to see if you can find a balance of size and quality that you're personally satisfied with.

Re: Help with settings for AVI to h.265

Posted: Sun Feb 03, 2019 10:05 pm
by jeffshead
Thanks for the info. I have hundreds of files to convert. That's why I want to use NVENC. It would take many, many days otherwise.

Re: Help with settings for AVI to h.265

Posted: Sun Feb 03, 2019 10:38 pm
by mduell
Then you're going to end up with much larger files to preserve quality.

Or do the transcode on the fly.

Re: Help with settings for AVI to h.265

Posted: Sun Feb 03, 2019 11:51 pm
by Woodstock
One thing about using handbrake's queue, or a batch job running the Command Line Interface, is that YOUR time is done up front. "Hundreds of files to convert" can be done while you're not there.

Re: Help with settings for AVI to h.265

Posted: Mon Feb 04, 2019 12:29 am
by musicvid
These are extremely low quality h263.
Normal preset x264-cpu will be plenty fast.

Re: Help with settings for AVI to h.265

Posted: Mon Feb 04, 2019 3:32 pm
by nhyone
As @musicvid said, you can just use x264.

If you want to transcode a low-quality source, the first thing you want is to discover the "equivalent" CRF -- the CRF that will give you the "same" quality as the source.

I tried x264, veryfast preset, CRF 22 (80.2 MB), 24 (66.8 MB), 26 (56.7 MB), 28 (49.0 MB). It seems to be 24 - 26. (x264 veryfast is pretty fast.)

I then tried veryfast preset, tune animation, CRF 24 (73.0 MB), 26 (62.0 MB). The file size increased a little, but CRF 26 looks really close. It is not quite the same because the source has tons of mosquito noise. They are not preserved exactly with such high CRF. (I doubt anyone cares.)

If you can spare the time, use NLMeans denoise. It makes it better than the source. I tried just one encode as it is very slow (CRF 24, veryfast preset, tune animation; NLMeans denoise, medium preset, tune animation). Size is 67.5 MB. Much, but not all, of the mosquito noise is gone.

To really improve the video, you need to use dedicated filters that undo mosquito noise and edge enhancement. However, that's beyond HandBrake.

Note: the size above includes audio. The original is MP3 at 192 kbps, which is way overkill for this cartoon. I used AAC at 96 kbps, which is also an overkill. However, I did not have the FDK-AAC encoder as I used the pre-built Windows app. Otherwise, I would have used 64 kbps HE-AAC.

Re: Help with settings for AVI to h.265

Posted: Mon Feb 04, 2019 4:01 pm
by mduell
If you're at all concerned about quality for size you probably don't want veryfast.

Re: Help with settings for AVI to h.265

Posted: Thu Feb 07, 2019 1:38 pm
by nhyone
Original (135 MB)

x264, CRF 26, veryfast preset, tune animation (62.0 MB)

x264, CRF 24, veryfast preset, tune animation; nlmeans medium, tune animation (67.5 MB)

Re: Help with settings for AVI to h.265

Posted: Fri Feb 08, 2019 3:19 am
by mduell
Stills don't tell you much of anything about how video looks.

Mixing veryfast and nlmeans is a... very strange choice.