sonic41592
14th November 2020, 01:04
I'm trying to write a script that will output a 24/30/60 fps vfr video and frame timestamp text file. The process uses the two pass TIVTC mode to make a lossless 24/30 fps vfr video, but leaves interlaced frames untouched through TFM PP=1.
Pass 1
ffmpegsource2("S01E01.vob",rffmode=1)
TFM(PP=1,output="TFM.txt",slow=2)
TDecimate(mode=4,output="TDecimate.txt")
Pass 2
ffmpegsource2("S01E01.vob",rffmode=1)
TFM(PP=1,input="TFM.txt",slow=2)
TDecimate(mode=5,hybrid=2,vfrDec=1,input="TDecimate.txt",tfmin="TFM.txt",mkvOut="Timecodes.txt",tcfv1=false)
The script I'm trying to write will take the lossless output from the second pass and the Timecodes.txt to check what the "single frame" frame rate is for each frame, check if it's combed, and deinterlace it if it is leaving two frames for interlaced 30 fps sections (TFM leaves interlaced frames in 24 fps sections as well, but those fields can be discarded). It will then write the timestamp for the frame in a text file. Here's the mockup code I have written so far:
LWLibavVideoSource("out.mkv",Repeat=true)
SSS="""
frames = FrameCount #Find number of frames
frametime = 0 #Set initial frame time
writefile("newtimes.txt","frametime")
tcds = RT_ReadTxtFromFile("Timecodes.txt")
for (i=0, frames-2) {
t0 = RT_TxtGetLine(tcds, Line = i+4)
t1 = RT_TxtGetLine(tcds, Line = i+5)
instfr = 1/(0.001*(t1-t0)) #Find instantaneous frame rate
if (instfr > 23 && instfr < 25) { #Check for 24fps frame
if (iscombedTIVTC() = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ).SelectEven() #Deinterlace combed 24fps frame
}
else { #passthrough noncombed 24fps frames
}
frametime = frametime + 1001/24000
writefile("newtimes.txt",frametime)
}
else if (instfr > 17 && instfr < 19) { #Check for 18fps frame
if (iscombedTIVTC = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ).SelectEven() #Deinterlace combed 18fps frame
}
else { #passthrough noncombed 18fps frames
}
frametime = frametime + 1001/18000
writefile("newtimes.txt",frametime)
}
else if (instfr > 29 && instfr < 31) { #Check for 30fps frame
if (iscombedTIVTC = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ) #Deinterlace combed 30fps frame into two 60fps frames
frametime = frametime + 1001/60000 #Add frame times
writefile("newtimes.txt",frametime)
frametime = frametime + 1001/60000
writefile("newtimes.txt",frametime)
}
else { #passthrough noncombed 30fps frames
frametime = frametime + 1001/30000
writefile("newtimes.txt",frametime)
}
}
else { #Passthrough for other framerates
if (iscombedTIVTC = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ).SelectEven()
}
else{ #passthrough
}
frametime = frametime + 1/instfr
writefile("newtimes.txt",frametime)
}
}
"""
ScriptClip(SSS)
Here are a couple samples with telecine and normal interlacing:
Samples (https://mega.nz/folder/1Th2jJ6L#iIAK6gbWO553Dwk6E-_eNg)
It errors (unsurprisingly) around the iscombedTIVTC argument. Any help with syntax or how to get this working would be greatly appreciated. I also noticed that QTGMC uses the wrong field first when deinterlacing a single frame, causing out of order frames, so any suggestions there would be helpful too. Thanks!
Pass 1
ffmpegsource2("S01E01.vob",rffmode=1)
TFM(PP=1,output="TFM.txt",slow=2)
TDecimate(mode=4,output="TDecimate.txt")
Pass 2
ffmpegsource2("S01E01.vob",rffmode=1)
TFM(PP=1,input="TFM.txt",slow=2)
TDecimate(mode=5,hybrid=2,vfrDec=1,input="TDecimate.txt",tfmin="TFM.txt",mkvOut="Timecodes.txt",tcfv1=false)
The script I'm trying to write will take the lossless output from the second pass and the Timecodes.txt to check what the "single frame" frame rate is for each frame, check if it's combed, and deinterlace it if it is leaving two frames for interlaced 30 fps sections (TFM leaves interlaced frames in 24 fps sections as well, but those fields can be discarded). It will then write the timestamp for the frame in a text file. Here's the mockup code I have written so far:
LWLibavVideoSource("out.mkv",Repeat=true)
SSS="""
frames = FrameCount #Find number of frames
frametime = 0 #Set initial frame time
writefile("newtimes.txt","frametime")
tcds = RT_ReadTxtFromFile("Timecodes.txt")
for (i=0, frames-2) {
t0 = RT_TxtGetLine(tcds, Line = i+4)
t1 = RT_TxtGetLine(tcds, Line = i+5)
instfr = 1/(0.001*(t1-t0)) #Find instantaneous frame rate
if (instfr > 23 && instfr < 25) { #Check for 24fps frame
if (iscombedTIVTC() = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ).SelectEven() #Deinterlace combed 24fps frame
}
else { #passthrough noncombed 24fps frames
}
frametime = frametime + 1001/24000
writefile("newtimes.txt",frametime)
}
else if (instfr > 17 && instfr < 19) { #Check for 18fps frame
if (iscombedTIVTC = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ).SelectEven() #Deinterlace combed 18fps frame
}
else { #passthrough noncombed 18fps frames
}
frametime = frametime + 1001/18000
writefile("newtimes.txt",frametime)
}
else if (instfr > 29 && instfr < 31) { #Check for 30fps frame
if (iscombedTIVTC = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ) #Deinterlace combed 30fps frame into two 60fps frames
frametime = frametime + 1001/60000 #Add frame times
writefile("newtimes.txt",frametime)
frametime = frametime + 1001/60000
writefile("newtimes.txt",frametime)
}
else { #passthrough noncombed 30fps frames
frametime = frametime + 1001/30000
writefile("newtimes.txt",frametime)
}
}
else { #Passthrough for other framerates
if (iscombedTIVTC = true) {
QTGMC( SourceMatch=3, TR0=2, TR1=2, TR2=0, Lossless=2 ).SelectEven()
}
else{ #passthrough
}
frametime = frametime + 1/instfr
writefile("newtimes.txt",frametime)
}
}
"""
ScriptClip(SSS)
Here are a couple samples with telecine and normal interlacing:
Samples (https://mega.nz/folder/1Th2jJ6L#iIAK6gbWO553Dwk6E-_eNg)
It errors (unsurprisingly) around the iscombedTIVTC argument. Any help with syntax or how to get this working would be greatly appreciated. I also noticed that QTGMC uses the wrong field first when deinterlacing a single frame, causing out of order frames, so any suggestions there would be helpful too. Thanks!