View Full Version : Need advice on Upscaling and Downscaling
pharssa
20th May 2016, 16:35
Hi,
I have several hundred MPEG-1/MPEG-2 streams at VCD/DVD resolution which I need to convert to h.264/MP4. Also, I need to create a 2x and 0.5x resolution version for each clip.
In last few weeks, I have read quite a bit about Avisynth and various filters and have successfully upscaled / downscaled a test clip using Avisynth and FFMpeg command line. I am creating my own windows GUI for automating the process.
My script for upscaling is:
ColorMatrix(hints=true, threads=0)
ConvertToYV12()
RemoveGrain(mode=6)
a = last
nnedi3_rpow2(rfactor=2, cshift="Spline36resize", fwidth=a.width*2,fheight=a.height*2, nsize=3,nns=4,pscrn=4)
a = last
b = a.RemoveGrain(mode=17)
SeeSaw( a, b, NRlimit=6, NRlimit2=7, Sstr=0.90, Slimit=5, Spower=5, Sdamplo=6, Szp=15, bias=50, Smode = 17 )
For downscaling I am planning to use:
ColorMatrix(hints=true, threads=0)
ConvertToYV12()
RemoveGrain(mode=6)
a = last
b = a.RemoveGrain(mode=17)
SeeSaw( a, b, NRlimit=6, NRlimit2=7, Sstr=0.90, Slimit=5, Spower=5, Sdamplo=6, Szp=15, bias=50, Smode = 17 )
Spline36resize(a.width*0.5, a.height*0.5)
My overall process so far is:
- create d2v and avs files with DGIndex
- encode h.264 with FFMpeg command line at a certain quality level using the avs file
What I don't fully understand and need advice on:
1. Usually, is it better (quality wise) to use the upscaled MPEG frame for downscaling (2x -> 0.5x) or will (1x -> 0.5x) give the same result?
2. If former, is it possible to make use of the upscaled MPEG frame to create both upscaled and downscaled h.264 versions in the same script so that I don't have to upscale 2nd time for creating a downscaled version? OR can I re-process upscaled h.264 frame to create the downscaled version without loosing quality?
Trying to balance quality with speed. Hope my setup and questions are clear.
Thanks,
FranceBB
20th May 2016, 17:22
Basically, if you upscale, you introduce blur, no matter what kernel you use. Some are better than others, but they all blur. So, if you have an upscaled file (2x) and you downscale (0.5x), you will still have blur 'cause you introduced it during the upscaling process, so it's always better to downscale starting from the source. Anyway, some filters (like sharpening filters etc) generally internally upscale sources, filter them, and then downscale them to your starting resolution. It's possible to avoid that, but it's generally better to leave filters do what they want to do. In your case, since you are planning to filter out crap and upscale (if I understand correctly), and you don't want to lose time, it's fine to downscale starting from your upscaled filtered source. The best compromise would be to index, filter out crap, save a lossless mezzanine and then re-encode the mezzanine two times: the very first time to upscale and the second one to downscale.
As to nnedi, it's a very good way to resize files; I suggest you to play around with parameters 'cause they are very useful. As to me, I generally use Spline64Resize as upscaling kernel and Lanczos as the downscaling one. Most people are fine with Spline for downscaling as well, but it really depends on your source and personal preferences. Besides, since nnedi is able to run at 16bit, consider using it with the DitherTool if you are planning to encode in H.264 10bit; don't bother if you are targeting 8bit instead.
As to the sharpening filters, I generally prefer to denoise, upscale and then sharp. As to seesaw, if you want to use it with your denoised source, you should keep both the starting input and the denoised version at the same resolution, and you are doing it since your steps are:
1) index
2) denoise
3)upscale (version a)
4) denoise again your upscaled filtered source (version b)
5) sharp using seesaw.
Well, that's fine, since you are blurring by purpose by upscaling it and then trying to get rid of the blur by sharpening it.
Good luck! :)
pharssa
20th May 2016, 19:30
Hi FranceBB,
Thank you for an elaborate advice.
For upscaling, I also tried Lanczos4, and Spline64resize but got the best result for the test clip with nnedi3 with Spline64resize.
For downscaling I also tried automttap3() function but it was slow. I will also try Lanczos for downscaling before settling down with Spline36resize.
Your suggestion of saving a cleaned up and lossless mezzanine makes lots of sense. Can you please suggest a format and a high quality encoder/encoding library for ffmpeg which I could use to do so.
Thanks,
FranceBB
20th May 2016, 20:05
Uhm... I generally use virtual dub to save lossless videos and I'm pretty satisfied with utvideo as codec. There are other lossless codecs like HuffYUV and the Apple ProRes (which is not mathematically lossless, though), but if you don't mind storing a really big file for a few time, you could simply import the avs in virtual dub and click "file, save as AVI" without adding any compression. It will simply store both video (uncompressed) and audio (pcm uncompressed) provided by avisynth in an AVI file. This way you won't waste CPU resources in trying to compress images and you will encode faster. Anyway, be aware that it's gonna be a very big file, so save it somewhere like in an HDD if you have an SSD. ;)
AzraelNewtype
20th May 2016, 21:35
ffmpeg has had UT Video support for years now, so you can still do that without dealing with virtualdub.
wonkey_monkey
21st May 2016, 12:58
you could simply import the avs in virtual dub and click "file, save as AVI" without adding any compression. It will simply store both video (uncompressed) and audio (pcm uncompressed) provided by avisynth in an AVI file. This way you won't waste CPU resources in trying to compress images and you will encode faster.
It will also introduce a colour conversion (and possibly an incorrect one) if you don't set VirtualDub to Fast Recompress first.
Motenai Yoda
21st May 2016, 14:24
This way you won't waste CPU resources in trying to compress images and you will encode faster. Anyway, be aware that it's gonna be a very big file, so save it somewhere like in an HDD if you have an SSD. ;)
Yep but you'll be limited by hdd/ssd speed, utvideo is fast enough to not be noticeable
jmartinr
21st May 2016, 19:24
What is the quality of the streams?
MPEG1/MPEG2 makes me suppose that the quality is not so great. If that's so, than there is really no point in upscaling. You can try a lot of nifty ways to upscale, NNEDI and all. But because of "crap in, crap out" it's often sort of impossible to get a good result. If you really want to upscale, upscale at playback and forget the filtering and recode. It's probably not worth the trouble.
Music Fan
22nd May 2016, 11:54
Uhm... I generally use virtual dub to save lossless videos and I'm pretty satisfied with utvideo as codec. There are other lossless codecs like HuffYUV and the Apple ProRes (which is not mathematically lossless, though)
And Lagarith (which I always use when I need lossless), based on HuffYUV but more efficient.
AzraelNewtype
22nd May 2016, 21:48
And Lagarith (which I always use when I need lossless), based on HuffYUV but more efficient.
Please do not suggest lags in the year of our lord two thousand and sixteen. Especially not after several mentions of UT Video.
Music Fan
22nd May 2016, 22:21
But you find logical to mention HuffYUV, strange ...
raffriff42
22nd May 2016, 22:53
But you find logical to mention HuffYUV, strange ...becauseLagarith relies on floating point math in the arithmetic coder, which nearly guarantees that errors like this will occur eventually, depending on the phase of the moon and so forth. The format should generally be avoided if possible.
AzraelNewtype
22nd May 2016, 22:53
But you find logical to mention HuffYUV, strange ...
Lags is slower than huffy, buggy, and floating point based, which means it's not actually mathematically lossless just as a side-effect of what float actually means. UT is better still, but lags is just the worst. Uninstall it and forget it even exists.
pharssa
22nd May 2016, 22:56
What is the quality of the streams?
MPEG1/MPEG2 makes me suppose that the quality is not so great. If that's so, than there is really no point in upscaling. You can try a lot of nifty ways to upscale, NNEDI and all. But because of "crap in, crap out" it's often sort of impossible to get a good result. If you really want to upscale, upscale at playback and forget the filtering and recode. It's probably not worth the trouble.
Hi Jmartinr,
You supposition is right. The quality is not great; in fact a lot of them are of poor quality / encoded from badly damaged films without any restoration. Also, I fully understand the "crap in crap out" part. The project is for a Asian community cause; so, I am looking to achieve what so ever clean-up and enhancement is possible.
I will upload a few samples after Tuesday as also asked by ingoldie.
Thanks,
Music Fan
23rd May 2016, 06:25
Lags is slower than huffy,
But Ut is maybe even slower than Lags.
buggy
I never got bug with Lags while I had with HuffYUV (and it doesn't work with yuy2 on my pc IIRC).
and floating point based, which means it's not actually mathematically lossless just as a side-effect of what float actually means. UT is better still, but lags is just the worst. Uninstall it and forget it even exists.
When I see Lags quality, this seems quite exaggerated but I will have a look at Ut.
StainlessS
23rd May 2016, 20:23
Via RaffRiff
Originally Posted by Dark Shikari View Post
Lagarith relies on floating point math in the arithmetic coder, which nearly guarantees that errors like this will occur eventually, depending on the phase of the moon and so forth. The format should generally be avoided if possible.
I had no idea that Arithmetic coders were error prone, hopefully not so much.
I, some time ago was quite gob smacked (surprised) that Lagarith produced file size about 1/2 (or less) on webcam cap,
due to its null frames (dupes, I just assumed that UtVideo/Magic etc could do similar null frames).
Anybody give some indication of what the error status is on something like Lags, surely not that bad.
(eg 1 pixel in 1000 off by 1, or similar, I could live with that).
EDIT: I have not actually used anything but UtVideo in a long-ish time, but for WebCamCap was thinking of using Lags.
raffriff42
24th May 2016, 02:10
One bad frame in an hour-long lossless intermediate is one too many -- who has time to check every frame? This happened to me a couple of times (a scrambled frame that looked like a tape dropout).
For webcams, x264 should be fine. It's the default encoder for Open Broadcaster (https://obsproject.com/).
StainlessS
24th May 2016, 17:13
Thanx Raff, "Scrambled" sounds way too bad to me, guess that Lags is off the agenda.
Maybe I'll give x264 a try, never tried it lossless.
Thanx again.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.