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.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

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

Reply
 
Thread Tools Display Modes
Old 18th October 2024, 14:00   #1  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
VapourSynth Script Problem

I am having the same problem from here for VapourSynth scripts. How do I make it have the same keyframes as the input video?

Here's my script, by the way.

Code:
from vapoursynth import core
clip = core.ffms2.Source(r"video.mkv")
clip = core.sub.ImageFile(clip, file = r"subtitle.sup")
clip.set_output()

Last edited by jay123210599; 18th October 2024 at 14:02.
jay123210599 is offline   Reply With Quote
Old 18th October 2024, 14:45   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,669
Quote:
Originally Posted by jay123210599 View Post
I am having the same problem from here for VapourSynth scripts. How do I make it have the same keyframes as the input video?

Here's my script, by the way.

Code:
from vapoursynth import core
clip = core.ffms2.Source(r"video.mkv")
clip = core.sub.ImageFile(clip, file = r"subtitle.sup")
clip.set_output()
See this reply

Quote:
Originally Posted by poisondeathray View Post

When you use a script, video is decoded to uncompressed frames. The original keyframes are "gone" because video is uncompressed. Another way of saying this is now every frame is a keyframe in the script or uncompressed state. When you re-encode you can place new keyframes, or you can control where you put new keyframes. Placing keyframes is a function of the encoder, not the script
You cannot keep exactly the same keyframes because video is decoded to uncompressed with scripts, including vpy scripts

Or do you mean same position of keyframes , but re-encoded as new keyframes ? If so, you need to do that with the encoder - specifying keyframes has nothing to do with scripts because everything is uncompressed . For example, if you were using something like x264, x265 to encode - you can specify keyframe positions with a --qpfile . Use search for more information, it has been discussed in other threads
poisondeathray is offline   Reply With Quote
Old 19th October 2024, 05:22   #3  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
@poisondeathray For VapourSynth scripts, how do I make the script include 709 if the video has it? What would be its equivalent to AviSynth's PropSet?

One more thing, what does Y410 mean in terms of YUV?
jay123210599 is offline   Reply With Quote
Old 19th October 2024, 14:29   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,669
Quote:
Originally Posted by jay123210599 View Post
@poisondeathray For VapourSynth scripts, how do I make the script include 709 if the video has it? What would be its equivalent to AviSynth's PropSet?

If source already has flags, source filters like lsmash, ffms2 should automatically read the flags and put it into the script

Otherwise you can use core.std.SetFrameProp to set or override them

http://www.vapoursynth.com/doc/funct...frameprop.html

eg.

Code:
clip = core.std.SetFrameProp(clip, prop="_Matrix", intval=1) #mark 709
clip = core.std.SetFrameProp(clip, prop="_Transfer", intval=1) #mark 709
clip = core.std.SetFrameProp(clip, prop="_Primaries", intval=1) #mark 709
Quote:
One more thing, what does Y410 mean in terms of YUV?

Y410 is the fourcc code for 10bit 4:4:4 YUV
poisondeathray is offline   Reply With Quote
Old 19th October 2024, 23:42   #5  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by poisondeathray View Post
Y410 is the fourcc code for 10bit 4:4:4 YUV
So it's the same thing? Where can I find more information about fourcc codes like Y410?

I also added core.std.SetFrameProp to get 709, but when I added the script to VirtualDub2, I still got YUV420 without it by default.

Last edited by jay123210599; 19th October 2024 at 23:50.
jay123210599 is offline   Reply With Quote
Old 20th October 2024, 01:01   #6  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,669
Quote:
Originally Posted by jay123210599 View Post
So it's the same thing? Where can I find more information about fourcc codes like Y410?
Functionally it's "10bit444", but "Y410" specifically refers to the packed representation. You can store/arrange the data in different ways. See this for more information
https://learn.microsoft.com/en-us/wi...-video-formats
Quote:
Y410 Packed, 4:4:4, 10-bit.
You can dig around that microsoft page for more info, or https://fourcc.org/yuv.php

Quote:
I also added core.std.SetFrameProp to get 709, but when I added the script to VirtualDub2, I still got YUV420 without it by default.

709 has nothing to do with YUV420 vs. YUV444 . Both can be either 709 or something else. They are independent variables. 420 vs. 444 refers to the chroma subsampling

How are you determining it's YUV420 ? Is it the same script as above ? Is the source 10bit444? When you open the vpy script in vdub2, what does file=>file information say under decompressor ? If it's Y410 , then it's correct. Whatever you're doing afterwards is convert it from Y410 to YUV420
poisondeathray is offline   Reply With Quote
Old 20th October 2024, 04:13   #7  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by poisondeathray View Post
709 has nothing to do with YUV420 vs. YUV444 . Both can be either 709 or something else. They are independent variables. 420 vs. 444 refers to the chroma subsampling

How are you determining it's YUV420 ? Is it the same script as above ? Is the source 10bit444? When you open the vpy script in vdub2, what does file=>file information say under decompressor ? If it's Y410 , then it's correct. Whatever you're doing afterwards is convert it from Y410 to YUV420
Sorry, I was using my other video, the 1080p YUV420 Blu-Ray one. This is what I got when I put my script in VirtualDub2.

https://imgur.com/TxKC0aW
jay123210599 is offline   Reply With Quote
Old 20th October 2024, 04:41   #8  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,669
Quote:
Originally Posted by jay123210599 View Post
Sorry, I was using my other video, the 1080p YUV420 Blu-Ray one. This is what I got when I put my script in VirtualDub2.

https://imgur.com/TxKC0aW

It works for me and shows Y410

In general, to debug a script you check the output of each line of the script , 1 at a time . You can comment out lines then uncomment them 1 at a time. You can use vspipe or if you prefer vdub2.

Maybe your video wasn't 10bit444 to begin with. eg. check just the source filter, comment out the sub

Maybe you mixed up videos or scripts (again). Double check before posting


Code:
from vapoursynth import core
clip = core.ffms2.Source(r"video.mkv")
#clip = core.sub.ImageFile(clip, file = r"subtitle.sup")
clip.set_output()
poisondeathray is offline   Reply With Quote
Old 20th October 2024, 13:17   #9  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by poisondeathray View Post
It works for me and shows Y410

In general, to debug a script you check the output of each line of the script , 1 at a time . You can comment out lines then uncomment them 1 at a time. You can use vspipe or if you prefer vdub2.

Maybe your video wasn't 10bit444 to begin with. eg. check just the source filter, comment out the sub

Maybe you mixed up videos or scripts (again). Double check before posting


Code:
from vapoursynth import core
clip = core.ffms2.Source(r"video.mkv")
#clip = core.sub.ImageFile(clip, file = r"subtitle.sup")
clip.set_output()
I told you I was using the video with this information with core.sub.ImageFile.

Code:
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.1
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Format settings, Slice count             : 4 slices per frame
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 24 min 27 s
Bit rate mode                            : Variable
Bit rate                                 : 21.6 Mb/s
Maximum bit rate                         : 39.0 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.435
Time code of first frame                 : 00:59:59:00
Stream size                              : 3.70 GiB (85%)
Language                                 : English
Default                                  : No
Forced                                   : No
Original source medium                   : Blu-ray
I followed the script exactly and I never got the 709 part by default, even with core.std.SetFrameProp.
jay123210599 is offline   Reply With Quote
Old 20th October 2024, 14:29   #10  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,669
Quote:
Originally Posted by jay123210599 View Post
I followed the script exactly and I never got the 709 part by default, even with core.std.SetFrameProp.

vdub2 does not read props such as 709 colorimetery data in the script. Again, script frame props are the least reliable method of conveying the information

Refer your other post and the replies, especially #11
http://forum.doom9.org/showthread.php?t=185812

Quote:
Originally Posted by poisondeathray View Post
It's most reliable to add it to the encoder , at the encoding step. Works 100% of the time and what I would do

Not all software will read the prop in the script (least reliable) , and not all tools will pass or read it from the source if you adjust the metadata for the source (depends on how you use the tools)
poisondeathray is offline   Reply With Quote
Old 20th October 2024, 17:48   #11  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by poisondeathray View Post
vdub2 does not read props such as 709 colorimetery data in the script. Again, script frame props are the least reliable method of conveying the information

Refer your other post and the replies, especially #11
http://forum.doom9.org/showthread.php?t=185812
I tried adjusting the metadata to include 709 and it still didn't get it by default. What other tools can read the colormetery data from scripts if VirtualDub2 can't?
jay123210599 is offline   Reply With Quote
Old 20th October 2024, 17:52   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,669
Quote:
Originally Posted by jay123210599 View Post
I tried adjusting the metadata to include 709 and it still didn't get it by default. What other tools can read the colormetery data from scripts if VirtualDub2 can't?
ffmpeg with avs scripts

I don't think either vpy demuxer (there are 2 versions) for ffmpeg can do it yet
poisondeathray is offline   Reply With Quote
Old 20th October 2024, 19:27   #13  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by poisondeathray View Post
ffmpeg with avs scripts

I don't think either vpy demuxer (there are 2 versions) for ffmpeg can do it yet
Anything else?
jay123210599 is offline   Reply With Quote
Old 21st October 2024, 23:21   #14  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 398
Acknowledging or not reading "709" color flag is NOT that important, you can do things manually flagging it during encoding in your encoder, you should be in a habit to do that anyway. I wish a set that flag decades ago for SD videos every time, which I did not.

If your virtualdub is not able to set preview for BT709, and it is "hardcoded" to BT601, then do not use it for preview or perhaps even using its filters.
Encoding your vapoursynth script AND flagging "709" color space in encoding settings should be ok.
And as you were told, there is also uncertainty on a customer side, where previewing app would not read that flag or decided to use BT601 instead.

Learn to use vspipe command lines for vapoursynth scripts. That is why vspipe was created by vapoursynth author, to serve vapoursynth video or audio nodes to other apps\encoders.

Last edited by _Al_; 21st October 2024 at 23:29.
_Al_ is offline   Reply With Quote
Old 26th October 2024, 13:23   #15  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by _Al_ View Post
Acknowledging or not reading "709" color flag is NOT that important, you can do things manually flagging it during encoding in your encoder, you should be in a habit to do that anyway. I wish a set that flag decades ago for SD videos every time, which I did not.

If your virtualdub is not able to set preview for BT709, and it is "hardcoded" to BT601, then do not use it for preview or perhaps even using its filters.
Encoding your vapoursynth script AND flagging "709" color space in encoding settings should be ok.
And as you were told, there is also uncertainty on a customer side, where previewing app would not read that flag or decided to use BT601 instead.

Learn to use vspipe command lines for vapoursynth scripts. That is why vspipe was created by vapoursynth author, to serve vapoursynth video or audio nodes to other apps\encoders.
I know how I to flag colorspace, but how do I encode my vapoursynth script?
jay123210599 is offline   Reply With Quote
Old 26th October 2024, 13:57   #16  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 671
Quote:
Originally Posted by jay123210599 View Post
I know how I to flag colorspace, but how do I encode my vapoursynth script?
Usually, you would run the script with VSPipe, piping the output to an encoding application such as FFmpeg.

Code:
vspipe -c y4m Script.vpy - | ffmpeg -i - -c:v libx264 -crf 18 OUTPUT.mp4

Last edited by GeoffreyA; 26th October 2024 at 14:03.
GeoffreyA is offline   Reply With Quote
Old 27th October 2024, 19:36   #17  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by _Al_ View Post
Acknowledging or not reading "709" color flag is NOT that important, you can do things manually flagging it during encoding in your encoder, you should be in a habit to do that anyway. I wish a set that flag decades ago for SD videos every time, which I did not.

If your virtualdub is not able to set preview for BT709, and it is "hardcoded" to BT601, then do not use it for preview or perhaps even using its filters.
Encoding your vapoursynth script AND flagging "709" color space in encoding settings should be ok.
And as you were told, there is also uncertainty on a customer side, where previewing app would not read that flag or decided to use BT601 instead.

Learn to use vspipe command lines for vapoursynth scripts. That is why vspipe was created by vapoursynth author, to serve vapoursynth video or audio nodes to other apps\encoders.
How about this? I put my script in VirtualDub2, then I use its "Decode Format' setting to the add the 709 manually, then I use its encoding settings from "Compression" for the rest. Is that okay? Will that work?
jay123210599 is offline   Reply With Quote
Old 27th October 2024, 23:47   #18  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 398
Yes, that seems to flag matrix as BT709 into AVC stream.
Or if using x264 encoder, you can add in settings, using configure button, into Extra command line:
--colormatrix bt709 --colorprim bt709 --transfer bt709
to flag color primaries and transfer also
_Al_ is offline   Reply With Quote
Old 28th October 2024, 01:46   #19  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 501
Quote:
Originally Posted by _Al_ View Post
Yes, that seems to flag matrix as BT709 into AVC stream.
Or if using x264 encoder, you can add in settings, using configure button, into Extra command line:
--colormatrix bt709 --colorprim bt709 --transfer bt709
to flag color primaries and transfer also
Oh, but do I still need to add this to my script in order for my solution to work in VirtualDub2?

Code:
clip = core.std.SetFrameProp(clip, prop="_Matrix", intval=1) #mark 709
clip = core.std.SetFrameProp(clip, prop="_Transfer", intval=1) #mark 709
clip = core.std.SetFrameProp(clip, prop="_Primaries", intval=1) #mark 709
jay123210599 is offline   Reply With Quote
Old 28th October 2024, 02:36   #20  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 398
If you do what was just confirmed in VirtualDub2, then strictly no.

But it is important for a vapoursynth previewers, because they have to present video on screen, so there has to be conversion to rgb, and you need at least matrix to convert to rgb. If not provided, matrix is defaulted/guessed.
Also if not set, vapoursynth will object if changing formats to rgb within script.
It might be a good habit to set those props like that if you are sure those values are proper, even if VirtualDub2 ignores them.
_Al_ is offline   Reply With Quote
Reply

Tags
colorspace, frame accurate, scripts, vapoursynth editor

Thread Tools
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 23:01.


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