Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th April 2019, 03:57   #1  |  Link
sunshine
Registered User
 
Join Date: Apr 2019
Posts: 17
Workflow from VapourSynth to DaVinci Resolve

Hello -

I'm working on an archival/ restoration project. I have a ton of MiniDV and VHS which I've captured to my PC via FireWire (60 hours approx).

The video is all BFF interlaced, 720x480, 30000/1001 fps, yuv411 8bit dvsd in AVI.

These are home videos shot with poor lighting, incorrect white balance, hand-held, etc., so I'd like to do some color correction and stabilization to make them more enjoyable to watch on a modern TV or mobile device. All playback will be done by a PC/ mobile device.

I own Davinci Resolve, which I plan to use for editing, color grading, stabilizing, and so on, but the deinterlacing and scaling in Resolve compares poorly to what I've seen with VapourSynth.

Here's what I'm thinking I'll do to deinterlace and resize the video. I'm looking for feedback on this, as I'm very new to this stuff.

Code:
#!/usr/bin/env python

# import the needed modules
import vapoursynth as vs
import havsfunc as haf
import edi_rpow2 as edi

core = vs.get_core()

# read the clip, it's passed as a param named "INVID" by vspipe
clip = core.ffms2.Source(source=INVID)

# I believe this converts the clip colorspace from yuv411 to yuv420, at 8 bit depth, as required for QTGMC.
clip = core.fmtc.resample (clip=clip, css="420")
clip = core.fmtc.bitdepth (clip=clip, bits=8)

# Use QTGMC to deinterlace - Are these good settings for my use-case??  These are your standard "home video" types of videos
clip = haf.QTGMC(clip, Preset='Slower', TFF=False)

# Use nnedi3_rpow2 to scale 2x
# from 720x480 to 1440x960
clip = edi.nnedi3_rpow2(clip=clip, rfactor=2)

# I believe this resizes to 1440x1080, with 4:3 DAR, with yuv422p8 colorspace and 709 color matrix.  This part is way over my head, and I'd appreciate feedback
# Also, I'm scaling from 1440x960 to 1440x1080.  Is this distorting my image (stretching its height)?  Or is this compensating for 4:3 pixel AR, because I gather it's being output in a 1:1 pixel AR now?  I'm lost on this one. 
clip = core.resize.Spline36(clip, 1440, 1080, format=vs.YUV422P8, matrix_in_s='709')

clip.set_output()

As far as where this is being sent next, it's ffmpeg to encode into x264, crf 10, veryslow, as follows.

Code:
vspipe --y4m ./DeinterlaceAndScale.py -a "INVID=$INVID" - | ffmpeg -nostdin -i pipe: -i "$INVID" -pix_fmt yuv422p -c:v libx264 -preset veryslow -crf 10 -tune fastdecode -x264opts keyint=1 -c:a copy -map 0:0 -map 1:1 "$OUTVID"
This intermediate output is my input to DaVinci Resolve. I COULD do x264 CRF 0 lossless, but the file sizes and processing overhead are a little ridiculous.

From DaVinci Resolve, I'll output likely dnxhr-sq for archival, and x264 CRF 20 for posting to Youtube, using on Plex, and so on.

I'd love some expert feedback on this workflow. Am I doing anything obviously wrong?

Thanks
sunshine is offline   Reply With Quote
Old 18th April 2019, 04:37   #2  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
You can mount your script into a fake avi using avfs.exe in your plugin folder. There's a avfs program in your vapoursynth/core64 path, just drag and drop your script into the program and it's mount it. The mount point will be C:\volume if you're using Windows.
lansing is offline   Reply With Quote
Old 18th April 2019, 15:59   #3  |  Link
sunshine
Registered User
 
Join Date: Apr 2019
Posts: 17
Quote:
Originally Posted by lansing View Post
You can mount your script into a fake avi using avfs.exe in your plugin folder. There's a avfs program in your vapoursynth/core64 path, just drag and drop your script into the program and it's mount it. The mount point will be C:\volume if you're using Windows.
Thanks for the idea Lansing, but I'm using Arch Linux for this and have several hundred clips to process, so I've written scripts that automate the process.

Any suggestions around the processing steps I'm applying to the SD video?

Thanks!
sunshine is offline   Reply With Quote
Old 18th April 2019, 17:00   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
Quote:
Originally Posted by sunshine View Post

Code:
clip = core.resize.Spline36(clip, 1440, 1080, format=vs.YUV422P8, matrix_in_s='709')
601 => 709 should be

matrix_in_s="170m", matrix_s="709"

Quote:
into x264, crf 10, veryslow, as follows.
Why "veryslow ?" Waste of time IMO . These are intermediate temp files


Quote:
I'd love some expert feedback on this workflow. Am I doing anything obviously wrong?
Alternatively you can edit in SD after bob deinterlacing ; it's much faster to process, stabilize,filter etc...at SD than HD. Then upscale at the last step
poisondeathray is offline   Reply With Quote
Old 18th April 2019, 17:05   #5  |  Link
WorBry
Registered User
 
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
Quote:
Originally Posted by lansing View Post
You can mount your script into a fake avi using avfs.exe in your plugin folder. There's a avfs program in your vapoursynth/core64 path, just drag and drop your script into the program and it's mount it. The mount point will be C:\volume if you're using Windows.
Does this actually work with Resolve ? Resolve has native support for import and export of a very limited range of VFW codecs (Cineform, Grass Valley, Uncompressed) and tends to be very picky about the AVI formatting - won't import uncompressed 4:2:0 in any form and you need the licensed (paid) Studio version to import lossless x264 (Hi444Pred). No ffmpeg support either, although that has oft been requested.
__________________
Nostalgia's not what it used to be

Last edited by WorBry; 18th April 2019 at 17:12.
WorBry is offline   Reply With Quote
Old 18th April 2019, 17:08   #6  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
As far as I know CRF 0 is NOT lossless, only -q 0 is!
I always used a fast or faster preset and --tune fastdecode + mp4 for my lossess encodes. (you need to remux a mkv produced by x264 as it doesn't have a proper index --> seeking means read the whole file then)
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database

Last edited by ChaosKing; 18th April 2019 at 17:10.
ChaosKing is offline   Reply With Quote
Old 18th April 2019, 17:13   #7  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
QTGMC can work with 422, so there can be just one color space conversion:
Code:
clip = core.ffms2.Source(source=INVID)
clip = core.resize.Bicubic(clip, format=vs.YUV422P8, matrix_in_s="170m", matrix_s="709")
clip = haf.QTGMC(clip, Preset='Medium', TFF=False)
clip = edi.nnedi3_rpow2(clip=clip, rfactor=2)
clip = core.resize.Spline36(clip, 1440, 1080)
clip.set_output()
_Al_ is offline   Reply With Quote
Old 18th April 2019, 17:18   #8  |  Link
WorBry
Registered User
 
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
Quote:
Originally Posted by poisondeathray View Post
Alternatively you can edit in SD after bob deinterlacing ; it's much faster to process, stabilize,filter etc...at SD than HD. Then upscale at the last step
I've been following Sunshine's parallel thread on the Blackmagic: Resolve Forum. The advice he received from others was to deinterlace (QTGMC) and upscale (NNEDI) to HD before editing.

Resolve does support field processing (free and Studio version) but applies title and transition macros as progressive frame. The Studio version supports in-program deinterlacing and its single-rate (same field) only.
__________________
Nostalgia's not what it used to be

Last edited by WorBry; 18th April 2019 at 17:28.
WorBry is offline   Reply With Quote
Old 18th April 2019, 17:29   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
Quote:
Originally Posted by WorBry View Post
I've been following Sunshine's parallel thread on the Blackmagic: Resolve Forum. The advice he received from others was to deinterlace (QTGMC) and upscale (NNEDI) to HD before editing.
What where the main reasons ? Can you provide link the thread ?

Pros / cons either way

But if he's complaining about filesizes , CRF 10 SD will consume less disk space, process faster, edit faster, compared to 1440x1080

Also, depending on the project, a lot of footage is cut out. It's a waste of disk space, time, QTGMCing, upscaling stuff that is going to be cut out anyways

It might not matter much for DV/ VHS , but there are some decent , newer upscale methods on the horizon . NNEDI3 is a neural net trained (you can call it "AI") by tritical, but there are newer neural net scalers being developed. I wouldn't want to "lock" the coarse NNEDI3 method into the upscale at this point
poisondeathray is offline   Reply With Quote
Old 18th April 2019, 17:32   #10  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 397
Quote:
Originally Posted by WorBry View Post
Does this actually work with Resolve ? Resolve has native support for import and export of a very limited range of VFW codecs (Cineform, Grass Valley, Uncompressed) and tends to be very picky about the AVI formatting - won't import uncompressed 4:2:0 in any form and you need the licensed (paid) Studio version to import lossless x264 (Hi444Pred). No ffmpeg support either, although that has oft been requested.
I'd be interested in hearing from someone who successfully managed to get this to work. I tried before but did not succeed.

Link to the BM forum thread:

https://forum.blackmagicdesign.com/v...p?f=21&t=88796
Cary Knoop is offline   Reply With Quote
Old 18th April 2019, 17:39   #11  |  Link
WorBry
Registered User
 
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
Yes, t'was I who gave the sagely, but redundant advice about preserving interlace fields if he intends to re-interlace...which he doesn't.

Resolve does also support native DV import but again tends to be picky about the AVI format (doesn't like Sony's) - may have to remux to MOV. No DV export though.
__________________
Nostalgia's not what it used to be

Last edited by WorBry; 18th April 2019 at 17:49.
WorBry is offline   Reply With Quote
Old 18th April 2019, 17:53   #12  |  Link
sunshine
Registered User
 
Join Date: Apr 2019
Posts: 17
Quote:
Originally Posted by poisondeathray View Post
601 => 709 should be matrix_in_s="170m", matrix_s="709"
My script is very heavily based on this post in Andrew's blog.

Like in his post, my input video is SD DV, yuv411 and 601 color matrix, so I just went with his approach. Much of this stuff is well over my head!

Do the processing steps prior to that final resize affect the color matrix? Is there a way for VapourSynth to tell me the color matrix before and after a processing step?

Quote:
Originally Posted by poisondeathray View Post
Why "veryslow ?" Waste of time IMO . These are intermediate temp files
Good catch, if I understand correctly, this only affects compression ratio and output file size, right? So I could go say "medium", without affecting the video quality right? Just use more disk space (I've got ~20-30 TB available, so no biggie).

Quote:
Originally Posted by poisondeathray View Post
Alternatively you can edit in SD after bob deinterlacing ; it's much faster to process, stabilize,filter etc...at SD than HD. Then upscale at the last step
Interesting idea! You mention bob deinterlacing. QTGMC produces such nice deinterlaced output, is there a reason I'd not want to use QTGMC?
sunshine is offline   Reply With Quote
Old 18th April 2019, 18:00   #13  |  Link
sunshine
Registered User
 
Join Date: Apr 2019
Posts: 17
Quote:
Originally Posted by WorBry View Post
Yes, t'was I who gave the sagely, but redundant advice about preserving interlace fields if he intends to re-interlace...which he doesn't.

Resolve does also support native DV import but again tends to be picky about the AVI format (doesn't like Sony's) - may have to remux to MOV. No DV export though.
Thanks for your advice over on the BM forums!

I do have a paid-for Resolve Studio to work with, but its deinterlacing is not nearly as nice as QTGMC (to my untrained eye).

Resolve does not like the AVI I'm working with (Sony MiniDV camcorder to PC via FireWire, using WinDV to create AVI), but seems to work fine in Resolve after I remux into MOV as you describe.
sunshine is offline   Reply With Quote
Old 18th April 2019, 18:02   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
Quote:
Originally Posted by sunshine View Post
Do the processing steps prior to that final resize affect the color matrix? Is there a way for VapourSynth to tell me the color matrix before and after a processing step?
You can look at the clip props, but sometimes videos are flagged incorrectly and you will get the wrong results

In general SD is 601, HD is 709


Quote:
Good catch, if I understand correctly, this only affects compression ratio and output file size, right? So I could go say "medium", without affecting the video quality right? Just use more disk space (I've got ~20-30 TB available, so no biggie).
Roughly , yes. I you might get 1-3 % space savings for 2-3x slower processing . You can do some mini tests, but it's really not worth it .


Quote:
Interesting idea! You mention bob deinterlacing. QTGMC produces such nice deinterlaced output, is there a reason I'd not want to use QTGMC?
I mean bob deinterlacing (ie. double rate) with QTGMC . Not using "bob" algorithm to deinterlace
poisondeathray is offline   Reply With Quote
Old 18th April 2019, 18:02   #15  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 397
Quote:
Originally Posted by sunshine View Post
Like in his post, my input video is SD DV, yuv411 and 601 color matrix, so I just went with his approach. Much of this stuff is well over my head!
You video is Rec.601 when you upscale it to HD I would convert it to Rec.709. At any rate, using Rec.709 as input is incorrect (as was already mentioned in the BM thread). Also, the primaries should be converted.

Quote:
Originally Posted by sunshine View Post
Good catch, if I understand correctly, this only affects compression ratio and output file size, right? So I could go say "medium", without affecting the video quality right? Just use more disk space (I've got ~20-30 TB available, so no biggie).
The quality is determined by the CRF option, all that faster processing will do is to make the compression less effective but that only translates into a slightly larger file.

Quote:
Originally Posted by sunshine View Post
Interesting idea! You mention bob deinterlacing. QTGMC produces such nice deinterlaced output, is there a reason I'd not want to use QTGMC?
QTGMC is way better than bob deinterlacing. Edited to add: poisondeathray made already clear he meant bob deinterlacing as part of QTGMC.

Last edited by Cary Knoop; 18th April 2019 at 18:04.
Cary Knoop is offline   Reply With Quote
Old 18th April 2019, 18:10   #16  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
Quote:
Originally Posted by ChaosKing View Post
As far as I know CRF 0 is NOT lossless, only -q 0 is!
(For x264, CRF 0 is lossless too . You can do a diff to verify. For x265 you need to add the --lossless switch)
poisondeathray is offline   Reply With Quote
Old 18th April 2019, 18:19   #17  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
For vpy avfs mounting, resolve will accept 10bit422 with the v210 flag (enable_v210 = True)

But not a good idea IMO when you have many clips or larger project. Way too much trouble, way too slow in terms of overhead

Not sure about other pixel formats in the v16 beta .
poisondeathray is offline   Reply With Quote
Old 18th April 2019, 18:24   #18  |  Link
WorBry
Registered User
 
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
Quote:
Originally Posted by poisondeathray View Post
(For x264, CRF 0 is lossless too . You can do a diff to verify.
With 8bit sources, libx264 switches -crf 0 to -qp 0 automatically, but for 10bit you need to set -qp 0.
__________________
Nostalgia's not what it used to be
WorBry is offline   Reply With Quote
Old 18th April 2019, 18:27   #19  |  Link
sunshine
Registered User
 
Join Date: Apr 2019
Posts: 17
Quote:
Originally Posted by poisondeathray View Post
(For x264, CRF 0 is lossless too . You can do a diff to verify. For x265 you need to add the --lossless switch)
I did the following tests to compare PSNR of x264 and dnxhr vs. raw, and CRF 0 scored "inf" which may confirm it's lossless, if I understand correctly.. but again I'm a noob.

Code:
Size MB	File	PSNR
32007	MiniDV-47.SHORT.yuv	NA
6621	MiniDV-47.SHORT.x264.crf0.veryslow.mov	PSNR y:inf u:inf v:inf average:inf min:inf max:inf
4083	MiniDV-47.SHORT.x264.crf1.veryslow.mov	PSNR y:53.512392 u:61.432235 v:60.652085 average:55.813724 min:53.405067 max:67.970034
3284	MiniDV-47.SHORT.x264.crf3.veryslow.mov	PSNR y:51.757858 u:60.172675 v:59.398284 average:54.130656 min:51.885540 max:67.841050
2081	MiniDV-47.SHORT.x264.crf7.veryslow.mov	PSNR y:48.699226 u:57.827356 v:57.149576 average:51.168932 min:48.984561 max:63.049205
1510	MiniDV-47.SHORT.x264.crf10.veryslow.mov	PSNR y:46.652977 u:56.481528 v:55.907612 average:49.204670 min:46.846824 max:58.420081
1254	MiniDV-47.SHORT.x264.crf12.veryslow.mov	PSNR y:45.362313 u:55.802922 v:55.325697 average:47.976095 min:45.501538 max:56.102836
957	MiniDV-47.SHORT.x264.crf15.veryslow.mov	PSNR y:43.455688 u:54.798423 v:54.447722 average:46.145881 min:43.542113 max:53.632696
47	MiniDV-47.SHORT.x264.crf28.mov	PSNR y:29.511193 u:46.680560 v:48.086853 average:32.450267 min:15.007240 max:41.752188
		
7104	MiniDV-47.SHORT.dnxhrhq.mov	PSNR y:53.555803 u:61.071902 v:60.056131 average:55.772436 min:55.019938 max:56.028969
4701	MiniDV-47.SHORT.dnxhrsq.mov	PSNR y:52.896759 u:60.668225 v:59.693643 average:55.158653 min:54.212876 max:55.469476
1498	MiniDV-47.SHORT.dnxhrlb.mov	PSNR y:45.928688 u:56.024373 v:55.573581 average:48.512562 min:44.856081 max:51.501520
sunshine is offline   Reply With Quote
Old 18th April 2019, 18:36   #20  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
Quote:
Originally Posted by WorBry View Post
With 8bit sources, libx264 switches -crf 0 to -qp 0 automatically, but for 10bit you need to set -qp 0.
Yes, and I'm not sure why they changed the behaviour (inconsistent)
poisondeathray is offline   Reply With Quote
Reply

Tags
deinterlace, qtgmc, resize, resolve, vapoursynth

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.