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:05   #4  |  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:32   #5  |  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   #6  |  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, 18:00   #7  |  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, 21:57   #8  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
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.
Just output the video to rgb30, it works
lansing is offline   Reply With Quote
Old 18th April 2019, 17:00   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
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:18   #10  |  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   #11  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
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: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:02   #13  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
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, 23:26   #14  |  Link
sunshine
Registered User
 
Join Date: Apr 2019
Posts: 17
Quote:
Originally Posted by poisondeathray View Post
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

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 .


I mean bob deinterlacing (ie. double rate) with QTGMC . Not using "bob" algorithm to deinterlace
I'm taking your recommended approach (deinterlace the SD DV, then do my edits, color correction, etc. in resolve, then resize to 1080 height) but I've encountered a small problem.

The aspect ratio is incorrect, and the video looks off.

AVI input file to VapourSynth:
Code:
Width                                    : 720 pixels
Height                                   : 480 pixels
Pixel aspect ratio                       : 0.889
MOV output from ffmpeg:
Code:
Width                                    : 720 pixels
Height                                   : 480 pixels
Pixel aspect ratio                       : 1.000

To correct this, I've updated my ffmpeg command with "setsar=sar=8/9,setdar=dar=4/3" as follows.. Did I do this correctly?!

Code:
vspipe --y4m ./Deinterlace.py -a "INVID=$INVID" - | ffmpeg -nostdin -i pipe: -i "$INVID" -pix_fmt yuv422p -c:v libx264  -crf 0 -tune fastdecode -x264opts keyint=1 -c:a copy -map 0:0 -map 1:1 -vf setsar=sar=8/9,setdar=dar=4/3 "$OUTVID"
After this adjustment, the MOV output from ffmpeg:
Code:
Width                                    : 720 pixels
Height                                   : 480 pixels
Pixel aspect ratio                       : 0.889
Thanks!
sunshine is offline   Reply With Quote
Old 19th April 2019, 00:51   #15  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by sunshine View Post

The aspect ratio is incorrect, and the video looks off.

AVI input file to VapourSynth:
Code:
Width                                    : 720 pixels
Height                                   : 480 pixels
Pixel aspect ratio                       : 0.889
MOV output from ffmpeg:
Code:
Width                                    : 720 pixels
Height                                   : 480 pixels
Pixel aspect ratio                       : 1.000

To correct this, I've updated my ffmpeg command with "setsar=sar=8/9,setdar=dar=4/3" as follows.. Did I do this correctly?!

Code:
vspipe --y4m ./Deinterlace.py -a "INVID=$INVID" - | ffmpeg -nostdin -i pipe: -i "$INVID" -pix_fmt yuv422p -c:v libx264  -crf 0 -tune fastdecode -x264opts keyint=1 -c:a copy -map 0:0 -map 1:1 -vf setsar=sar=8/9,setdar=dar=4/3 "$OUTVID"
After this adjustment, the MOV output from ffmpeg:
Code:
Width                                    : 720 pixels
Height                                   : 480 pixels
Pixel aspect ratio                       : 0.889
Thanks!




Without getting into a lengthy AR interpretation discussion, that's one way of getting 4:3 DAR . Typically I only set the SAR, because setting the DAR will only give you non ITU aspect ratio options

But for analog sources like VHS, technically the SAR is actually 10:11 . DV too. And those are what you are using according to the 1st post. The central portion or active image area is 702 width (rounded to 704), and pillar boxed

You can verify with some objects, such as a round clock or car tire shot straight on. 99% of the time 10:11 will give you the perfect circle, but 8:9 will give you slightly oval. It also depends on the lineage and what steps or types of transfers were done inbetween. It also depends on the software, you might have to interpret the AR in some software, but resolve can distinguish between the two (at least with the SAR flag)

It's the same with upscaling to HD . The AR will be slightly off if you use the wrong AR interpretation.

(But many people don't care about tiny AR error . I guess it depends on how picky you are, or if driving on "oval" tires is ok )
poisondeathray is offline   Reply With Quote
Old 18th April 2019, 18:02   #16  |  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, 19:04   #17  |  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
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?
Resize has nothing to do with it.

The resize command:
Code:
clip = core.resize.Bicubic(clip, format=vs.YUV422P8, matrix_in_s="170m", matrix_s="709")
does not do a resize, it is simply used to change the colorspace.
Cary Knoop is offline   Reply With Quote
Old 18th April 2019, 17:08   #18  |  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, 18:10   #19  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
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:24   #20  |  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
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 16:43.


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