View Full Version : Getting undesired FPS and AR output with QTGMC de-interlacer
KingLir
24th January 2017, 00:18
Hi All,
I am using QTGMC de-interlacer on interlaced Mpeg2 NTSC DVD ripped 1:1 with MakeMKV.
My script at the bottom.
mediainfo:
Frame rate mode : Variable
Frame rate : 25.047 FPS
Original frame rate : 29.970 (30000/1001) FPS
Display aspect ratio : 4:3
And the output mkv mediainfo is:
Frame rate mode : Constant
Frame rate : 50.099 FPS
Display aspect ratio : 3:2
Since I like to keep the audio synced (mux is back using, for example, MKVToolNix) this FPS isn't good.
Also the aspect ratio change from 4:3 to 3:2 (but this is not hard to fix).
The same "issues" happens also with AviSynth. I probably just doing something wrong, can anyone guide me through ?
Script:
-------
import vapoursynth as vs
import havsfunc as haf
core = vs.get_core()
clip = core.ffms2.Source(source='Opening.mkv')
clip = haf.QTGMC(clip, Preset='Very Slow', SourceMatch=3, TR2=1, Lossless=2, TFF=True)
clip.set_output()
VS_Fan
24th January 2017, 03:04
Your source is VFR (Variable Frame Rate), but it looks like you want the output to be 30000/1001 CFR (Constant Frame Rate, as the original).
You could use fpsnum=30000, fpsden=1001 as parameters for ffms2.Source to get that conversion done
Also, remember QTGMC will return the framerate doubled by default, unless you specify FPSDivisor=2 as a parameter to produce single-rate output
EDIT:
Re-Reading your post, It will be better to verify your original video (DVD) and verify if it was film telecined to NTSC DVD (24fps or 23.976fps) and convert from that
KingLir
24th January 2017, 10:00
Many Thanks VS_Fan ! The parameters you wrote fixed the FPS for me (and for AR, if no better way, I will just use -vf setdar=4:3 in ffmpeg).
But does my setup is recommended for best image quality ? Meaning using ffms2.Source and the parameters I send to QTGMC ?
About Telecine, I never fully understand how to unidentify it, even after reading again now on Wiki.
Can you guide me how to identify it and how to convert it, if needed ?
jackoneill
25th January 2017, 10:35
Many Thanks VS_Fan ! The parameters you wrote fixed the FPS for me (and for AR, if no better way, I will just use -vf setdar=4:3 in ffmpeg).
But does my setup is recommended for best image quality ? Meaning using ffms2.Source and the parameters I send to QTGMC ?
About Telecine, I never fully understand how to unidentify it, even after reading again now on Wiki.
Can you guide me how to identify it and how to convert it, if needed ?
You find a scene where every frame is clearly different from the previous one, like when panning or zooming. You step through it one frame at a time. If you find a pattern of three progressive frames followed by two interlaced frames, then you have hard telecine and you need VFM + VDecimate. If all the frames in the scene are interlaced, then you need QTGMC.
By the way, this is a bit nasty. From ffms2 documentation:
If fpsnum is greater than zero, Source will force a constant frame rate, expressed as a rational number where fpsnum is the numerator and fpsden is the denominator. This may naturally cause Source to drop or duplicate frames to achieve the desired frame rate, and the output is not guaranteed to have the same number of frames that the input did.
Are you sure you want to do this to your video? Also, when you determine if your video is interlaced or telecined, you definitely mustn't pass fpsnum and fpsden to ffms2.
About the QTGMC parameters: you should add them only if you know they're needed. If just passing the preset produces a good image, you don't need the others. They may help, or they may be harmful. It depends on your video. If you're curious, compare the output with and without them.
Mediainfo may or may not know what it's talking about. To be sure, you should run your DVD (VTS_0X_1.VOB..VTS_0X_Y.VOB) through DGIndex or D2V Witch and see what they say.
KingLir
25th January 2017, 12:15
Many Thanks!
You find a scene where every frame is clearly different from the previous one, like when panning or zooming. You step through it one frame at a time. If you find a pattern of three progressive frames followed by two interlaced frames, then you have hard telecine and you need VFM + VDecimate. If all the frames in the scene are interlaced, then you need QTGMC.
By the way, this is a bit nasty. From ffms2 documentation:
Are you sure you want to do this to your video? Also, when you determine if your video is interlaced or telecined, you definitely mustn't pass fpsnum and fpsden to ffms2.
About the QTGMC parameters: you should add them only if you know they're needed. If just passing the preset produces a good image, you don't need the others. They may help, or they may be harmful. It depends on your video. If you're curious, compare the output with and without them.
So if I found out that all frames are interlaced (meaning I need QTGMC) and since it's Variable Frame Rate, how to get an output that the audio will remained synced like the original ?
I like to avoid nasty (yes, I asked about ffms2 because I read that on the documentation).
Mediainfo may or may not know what it's talking about. To be sure, you should run your DVD (VTS_0X_1.VOB..VTS_0X_Y.VOB) through DGIndex or D2V Witch and see what they say.
Now, I only have the remux DVD in MKV. But it is 1:1 with the latest MakeMKV. Do I must have the VOBs ? If not, which tool will handle the MKV ?
sneaker_ger
25th January 2017, 13:20
It's probably best if you post a sample of the source. Like the others said it could be some kind of telecine (with pulldown, hence the vfr). Not sure how the combination makemkv + dvd/mpeg2 pulldown + ffms2 works.
jackoneill
25th January 2017, 22:23
If all the frames are interlaced, then the frame rate is likely constant and ffms2/mediainfo are simply wrong. In this case, the solution is to use AssumeFPS. That one doesn't add or remove frames, it only changes the clip's metadata.
If you only have the mkv, you can use ffprobe to check for 24 fps sections with RFF flags:
ffprobe -show_streams -show_format -show_frames test.mkv | grep repeat_pict=1
If this prints a list of "repeat_pict=1", then you have some 24 fps sections and thus variable frame rate (because the interlaced frames you mentioned are likely not 24 fps...). If it doesn't print "repeat_pict=1" at all, then you can safely use AssumeFPS before/after QTGMC.
KingLir
25th January 2017, 23:03
OK, I rechecked and found out that the DVDs have mixed transfers (it's a TV show - so there is a difference between episodes). Verified both in mediainfo and by looking at the frames and clearly distinguish as jackoneill described (thanks again).
Some are CFR fully Interlaced-
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Scan type : Interlaced
Scan order : Top Field First
And some are VFR Progressive with 2:3 Pulldown-
Frame rate mode : Variable
Frame rate : 24.000 FPS
Original frame rate : 23.976 (24000/1001) FPS
Scan type : Progressive
Scan order : 2:3 Pulldown
So I guess for the first type I am already good to use QTGMC with ffms2 without fpsnum and fpsden (that's OK, right ?).
What exactly should I do with the second type ? What is the recommended use for VFM + VDecimate in order to keep the audio synced ? And can I continue to use ffms2 (again without fpsnum and fpsden) ?
VS_Fan
26th January 2017, 07:50
So I guess for the first type I am already good to use QTGMC with ffms2 without fpsnum and fpsden (that's OK, right ?).
right, if you verified it's 100% interlaced
What exactly should I do with the second type ? What is the recommended use for VFM + VDecimate in order to keep the audio synced ? And can I continue to use ffms2 (again without fpsnum and fpsden) ?
You could use d2vsource (https://github.com/dwbuiten/d2vsource) with rff=False. That way you should end up with a 24000/1001 (23.976...)fps output video. Have a look at d2vsource docs included with the plugin.
I was sure ffms2 was able to handle the duplicate and/or rff flags when instructing it with fpsnum/fpsden, but after reading jackoneill's post i'm not sure anymore. :confused: I haven't tried it myself
P.S.: I'm assuming your using the DVD source, not the mkvs mentioned earlier.
KingLir
26th January 2017, 08:34
right, if you verified it's 100% interlaced
Thanks!
You could use d2vsource (https://github.com/dwbuiten/d2vsource) with rff=False. That way you should end up with a 24000/1001 (23.976...)fps output video. Have a look at d2vsource docs included with the plugin.
But will the audio stay synced ? Since the source is NTSC 29.97fps.
I was sure ffms2 was able to handle the duplicate and/or rff flags when instructing it with fpsnum/fpsden, but after reading jackoneill's post i'm not sure anymore. :confused: I haven't tried it myself
P.S.: I'm assuming your using the DVD source, not the mkvs mentioned earlier.
Currently I only have the remux DVD in MKV. But it is 1:1 with the latest MakeMKV. Do I must move back to the VOBs ?
manono
29th January 2017, 08:28
...and since it's Variable Frame Rate...
There's no such thing as VFR in DVDs. All NTSC DVDs output 59.94 fields per second (29.97fps).
Maybe you mean to say it's a mix of hard and soft telecine. Maybe you mean it's a mix of true interlace and hard and/or soft telecine. However, no one should have to guess. Please post a sample or samples as already requested.
So I guess for the first type I am already good to use QTGMC...
Not necessarily. If hard telecined it'll also show the scan type as interlaced. Those should be IVTC'd and not bobbed.
And, yes, it's easier and better to work with the VOB source, and not the MKV you made of it. But, whatever you have we can have a look.
KingLir
29th January 2017, 12:42
yes, it's easier and better to work with the VOB source, and not the MKV you made of it. But, whatever you have we can have a look.
Thanks. Here are the samples:
Type1:
https://mega.nz/#!Yt1lELiY!ntbZG60iPQp6uqWovZBhiMq8pqWITEuQua9mQR8vzVM
Type2:
https://mega.nz/#!AoVRyAQD!9Wr-3J3IEhC62SvvyZHmnZNhq9WMOTewD4CL7gcjhOc
Sharc
29th January 2017, 17:02
For clip 1 try:
tdeint(mode=1,order=1)
srestore(frate=24.000/1.001)
For clip 2 try:
TFM().TDecimate()
manono
29th January 2017, 20:01
Yes, there's nothing out of the ordinary with either of those two clips. However, I find they both IVTC well and didn't see the need to Bob/Srestore as there's no field blending that I could find and I didn't get any unusual results from a straight IVTC. I did get some stuttering at first in the first scene from test1.mkv of the truck coming down the road, but not afterwards. Not sure why that happened. If necessary add an 'Order=1' into TFM. I believe in field matching whenever possible.
TFM(Order=1).TDecimate(Mode=1)
In any event, although encoded as interlaced 29.97fps for NTSC DVD they're meant to be progressive 23.976. They aren't VFR and don't have any unusual framerates as mentioned in the first post of this thread. The audio will remain in synch after the IVTC. I'm not using VaporSynth.
KingLir
29th January 2017, 20:55
Thank you Sharc and manono. Sorry but, as a newbie, I am not sure I got what you mean.
Type 1 needs de-interlacing ?
If the answer is yes, why to use tdeint and not QTGMC ?
if the answer is no, what exactly does the method you wrote will do ?
About Type 2, so I will just do IVTC.
Is TFM().TDecimate() the best IVTC tool ? and the audio should stay in sync ?
Sharc
29th January 2017, 22:47
Bob/Srestore is normally used to get rid of blended fields which are typically caused by poor framerate conversions.
For type1 I suggested it instead of straight IVTC because it produced smoother playback, eliminating few hickups (stutter) as manono also mentioned. It's just an experimental finding here, no science. Instead of Tdeint(mode=1) you could use any bobber of your choice, like QTGMC() for example.
I am not aware of a more powerful (don't ask for the "best" acc. forum rules) IVCT tool than TFM/TDecimate, but you may also want to try Telecide()/TDecimate which does basically the same.
You find a lot about these subjects in the doom9 forum and Avisynth wiki.
With IVTC the audio should stay in sync, as there are less repeated frames (or fields) and playback speed is reduced accordingly from 29.97 to 23.976 fps, means the duration of the clip remains unchanged.
VS_Fan
30th January 2017, 02:01
Test1 is hard and Test1 is soft telecine (https://en.wikipedia.org/wiki/Telecine#Soft_and_hard_telecine)
For hard telecine, Bobing or deinterlacing (TDEINT) will hurt badly the quality of the video, producing field blending! There are no blended frames in your sample. So, there's no need for sRestore
The correct strategy is inverse-telecine (VIVTC (http://www.vapoursynth.com/doc/plugins/vivtc.html#vivtc) plugin) like this:
ret = core.vivtc.VFM(clip=ret, order=1)
ret = core.vivtc.VDecimate(clip=ret)
For Soft telecine you don't need to do anything: FFMS2, LSMASHwokrs or d2vsource will handle the RFF (Repeat First Field flags appropriately), and result in correct 24000/1001 (23.976) fps. No need to IVTC.
Consider working with your DVD sources: There was a problem with the process of multiplexing or cutting your video samples (MKV). Initial (and/or final?) Closed GOPs were left incomplete. That's why manono reported stuttering at the beginning.
But if you want to continue from your mkvs, demux or extract the m2v stream, all those source filters will work fine. For example, this will get 24000/1001 video for test2:
ret = core.ffms2.Source(source="test2.m2v")
EDIT:
In both cases (hard and soft telecine) you will end up with output videos at 24000/1001 (23.976) fps, that will sync without problems with the audio if muxed properly into mkv, mp4, etc
Sharc
30th January 2017, 09:05
If you look carefully you see ugly ghosted pictures (frames or fields view) in test 1, for example the contours of the truck. (Which made me doubt about the quality of the "mkv originals").
Srestore did not fix the ghosts but it solved the stutter issue due to the incomplete closed GOPs of the (demuxed and indexed) .mkv source.
KingLir
30th January 2017, 13:42
Test1 is hard and Test2 is soft telecine (https://en.wikipedia.org/wiki/Telecine#Soft_and_hard_telecine)
For hard telecine, Bobing or deinterlacing (TDEINT) will hurt badly the quality of the video, producing field blending! There are no blended frames in your sample. So, there's no need for sRestore
The correct strategy is inverse-telecine (VIVTC (http://www.vapoursynth.com/doc/plugins/vivtc.html#vivtc) plugin) like this:
ret = core.vivtc.VFM(clip=ret, order=1)
ret = core.vivtc.VDecimate(clip=ret)
Many Thanks! Works great with test1.
But when applied to a different part I see that some of the frames are with horizontal lines (looks interlaced).
Here is the part:
https://mega.nz/#!FosEzBYY!xgoDH7qiZAoywOeggLMkIhcl7DtbOCp-_jgI1sV_iw0
And after applying the script (full script at the end below):
https://mega.nz/#!VwEi2ahR!M4qT_mkMCsU8t4zDOKEWgbpS8LkaHjpaXhS3wEmcjoY
Consider working with your DVD sources: There was a problem with the process of multiplexing or cutting your video samples (MKV). Initial (and/or final?) Closed GOPs were left incomplete. That's why manono reported stuttering at the beginning.
I see. What is the correct way of cutting a video (let's say 1 minute for a sample or remove the opening song from a TV Show and get just the episode itself) without re-encoding ? I used ffmpeg with --ss and --to (with copy stream).
But if you want to continue from your mkvs, demux or extract the m2v stream, all those source filters will work fine. For example, this will get 24000/1001 video for test2:
ret = core.ffms2.Source(source="test2.m2v")
EDIT:
In both cases (hard and soft telecine) you will end up with output videos at 24000/1001 (23.976) fps, that will sync without problems with the audio if muxed properly into mkv, mp4, etc
For test2, I am getting 23.963002 instead of the desired 23.976216 and the audio is out of synced. Maybe, as you wrote, because of the wrong way I cut the video ?
Script for test1 and test3:
import vapoursynth as vs
import havsfunc as haf
core = vs.get_core()
clip = core.ffms2.Source(source=filename)
clip = core.vivtc.VFM(clip=clip, order=1)
clip = core.vivtc.VDecimate(clip=clip)
clip.set_output()
Script for test2:
import vapoursynth as vs
import havsfunc as haf
core = vs.get_core()
clip = core.ffms2.Source(source=filename)
clip.set_output()
jackoneill
30th January 2017, 18:49
If the source filter gives you the wrong frame rate, you can use AssumeFPS at the end of the script (or wherever it's convenient).
manono
30th January 2017, 20:47
Test1 is hard and Test1 is soft telecine (https://en.wikipedia.org/wiki/Telecine#Soft_and_hard_telecine)
Oh yeah, you're right (Test2 is soft). I didn't demux them as I usually do, but used FFVideoSource on them. If they're from the same episode (and even if they aren't) and are a mix of hard and soft telecine then, as mentioned before, don't put them in the MKV container but open the VOB(s) in DGIndex and with the field operation set for 'Honor Pulldown Flags' make the D2V project file. Then if using TIVTC, a script to get it back to progressive 23.976fps might go:
TFM(d2v="Video.d2v").TDecimate(Mode=1)
That will, essentially, use Forced Film on the soft telecined sections and perform the full IVTC on the hard telecined parts. It'll be a bit faster than performing a full IVTC on the whole thing and prevent the sometime mistakes when field matching. And you'll always get the right initial and final framerates.
Because anime often mixes both hard and soft telecine, it's a good trick to know. It's fully explained in the TFM doc. As I mentioned before, I don't use VapourSynth.
KingLir
30th January 2017, 21:08
If the source filter gives you the wrong frame rate, you can use AssumeFPS at the end of the script (or wherever it's convenient).
Thanks but EDIT: It doesn't help. the audio doesn't stay synced in this way for test2 ( core.std.AssumeFPS(clip, fpsnum=24000, fpsden=1001) )
What is the correct way of cutting a video (let's say 1 minute from the middle of a video for a sample) without re-encoding ? To avoid Closed GOPs that are left incomplete.
I used ffmpeg with --ss and --to (with copy stream).
Also, I will be happy to get help about the new links I posted (test3).
jackoneill
30th January 2017, 22:07
Thanks but EDIT: It doesn't help. the audio doesn't stay synced in this way for test2 ( core.std.AssumeFPS(clip, fpsnum=24000, fpsden=1001) )
What is the correct way of cutting a video (let's say 1 minute from the middle of a video for a sample) without re-encoding ? To avoid Closed GOPs that are left incomplete.
I used ffmpeg with --ss and --to (with copy stream).
Also, I will be happy to get help about the new links I posted (test3).
I guess DGIndex can do it. Maybe D2V Witch too.
KingLir
30th January 2017, 22:21
I guess DGIndex can do it. Maybe D2V Witch too.
You mean a correct cut for a sample ? Can you guide me how to use these tools exactly in order to achieve this ? I never used them before...
manono
30th January 2017, 22:55
What is the correct way of cutting a video (let's say 1 minute from the middle of a video for a sample) without re-encoding ?
One way is with DGIndex. Open the VOB and use the [ and ] buttons to isolate a small section. Then File->Save Project and Demux Video. The M2V you get is the video portion of the VOB. You'll also get a separate audio file with the delay written into the name (or as many audio files as there are audio tracks in the VOB), and a D2V project file to use in your AviSynth script.
VS_Fan
31st January 2017, 06:47
For test2, I am getting 23.963002 instead of the desired 23.976216 ... Again: Your MKVs have problems: if you demux the mpeg2 stream (mkvextract) you'll get an m2v file. If you use that one as source you'll get the desired framerate: 24000/1001 = 23.9760239760239760... (repeating decimal) with ffms2 and LWLibavSource (LSMASH source).
For some reason FFMS2, d2v and LSMASH have problems with your MKVs. I remuxed the m2v files (mpeg2 streams extracted from your MKVs) into new MKVs using mkvtoolnix. Using those new MKVs as source, the results are correct using FFMS2 & LSMASH
For test2 you don't need to do anything to obtain a your desired result. Just demux your MKVs or use the original DVD source
KingLir
1st February 2017, 21:45
Again: Your MKVs have problems: if you demux the mpeg2 stream (mkvextract) you'll get an m2v file. If you use that one as source you'll get the desired framerate: 24000/1001 = 23.9760239760239760... (repeating decimal) with ffms2 and LWLibavSource (LSMASH source).
For some reason FFMS2, d2v and LSMASH have problems with your MKVs. I remuxed the m2v files (mpeg2 streams extracted from your MKVs) into new MKVs using mkvtoolnix. Using those new MKVs as source, the results are correct using FFMS2 & LSMASH
For test2 you don't need to do anything to obtain a your desired result. Just demux your MKVs or use the original DVD source
Many Thanks! Indeed this fixes test2 (and other episodes like it), but it seems that some other episodes have mixed parts and that's what causing the MKV to be VFR.
I read about VFR here (http://avisynth.nl/index.php/VFR) and it seems that my video is "Hybrid": Hybrid video is commonly defined as being a mix of pulled-down material and non-pulled-down material (where the pulldown can be of fields, as in standard 3:2 pulldown, or full frames). It's not relevant whether the pulldown is hard (the fields/frames are duplicated before the encoding) or soft (adding the appriopriate flags in the stream which indicate which fields/frames should be duplicated during playback). .... What makes hybrids challenging is the need to decide what final framerate to use.
For example, I analyzed one episode like this, and if I cut an episode video into 3 parts: start, middle (a small part) and end. The start and the end become CFR and the middle is VFR.
EDIT: Here is the middle part that causing the problem (causing the entire episode to become VFR):
https://mega.nz/#!Q4lSTR4Q!KSh4vizF2gNemV-F3dSXRxxdQ_IFreBiOEQfc6VkUe0
What is the best way to automatically handle these Hybrids in vapoursynth ? since I don't want to manually identify and separate the parts (as I did in the example I described above).
Sharc
2nd February 2017, 00:22
EDIT: Here is the middle part that causing the problem (causing the entire episode to become VFR):
https://mega.nz/#!Q4lSTR4Q!KSh4vizF2gNemV-F3dSXRxxdQ_IFreBiOEQfc6VkUe0
What is the best way to automatically handle these Hybrids in vapoursynth ? since I don't want to manually identify and separate the parts (as I did in the example I described above).
There is nothing wrong with this sequence. It just changes from Hard to Soft telecine.
I can't help you with vapoursynth. In Avisynth you can simply IVTC and get perfect 23.976 fps progressive.
manono
2nd February 2017, 00:37
What is the best way to automatically handle these Hybrids in vapoursynth ? since I don't want to manually identify and separate the parts (as I did in the example I described above).
I already gave you the AviSynth script for that:
If they're from the same episode (and even if they aren't) and are a mix of hard and soft telecine then, as mentioned before, don't put them in the MKV container but open the VOB(s) in DGIndex and with the field operation set for 'Honor Pulldown Flags' make the D2V project file. Then if using TIVTC, a script to get it back to progressive 23.976fps might go:
TFM(d2v="Video.d2v").TDecimate(Mode=1)
That will, essentially, use Forced Film on the soft telecined sections and perform the full IVTC on the hard telecined parts.
If you can't use that script in VapourSynth, there's probably an equivalent that does the same thing. Or, as Sharc said, just IVTC the whole thing. Problems sometimes occur in anime when there are real 29.97fps sections, either progressive or pure interlace. But, based on what you wrote that's not the case here.
VS_Fan
2nd February 2017, 03:29
If you can't use that script in VapourSynth, there's probably an equivalent that does the same thing.vapoursynth equivalent:
ret = core.vivtc.VFM(clip=ret, order=1) .vivtc.VDecimate(clip=ret)
For hard telecine I would simply apply IVTC. I haven’t watched all of KingLir's tests or results, but I guess the problematic parts are at the beginning, during the introduction, where there are lots of edits, fade ins/outs, overlays, etc. The rest of the video (95% +) is fine with IVTC, right?
Using the TIVTC filters in avisynth should give you very good fluid progressive results for the problematic parts. Unfortunatelly, VIVTC (vapoursynth’s rewrite of some of tritical’s TIVTC filters) doesn´t include, yet!, all the functionalities of TIVTC (filters for avisynth):
Unlike TFM (avisynth), VFM (vapoursynth) does not have any postprocessing capabilities (http://www.vapoursynth.com/doc/plugins/vivtc.html#vivtc.VFM): PP, the post-processing mode parameter controls how TFM should handle (or not handle) any combed frames that come out of the field matching process (from avisynth’s TFM filter readme)
VDecimate: It drops one in every cycle frames – the one that is most likely to be a duplicate (mode 0 in TDecimate) (http://www.vapoursynth.com/doc/plugins/vivtc.html#vivtc.VDecimate). VDecimate doesn’t have any options to change "mode". As recommended by manono, mode=1 is more appropriate for anime: This mode is the correct type of decimation for anime and other sources where frames are repeated 2, 3 or 4 times in a row (from avisynth’s TDecimate filter readme)
For this reasons, you’ll get nicer results (than with my recommendation with vapoursynth) with manono suggestion (avisynth). If you use FFMS2 (you don’t generate d2v files), manono’s avisynth script would be simplified:
TFM(). TDecimate(mode=1)
VS_Fan
2nd February 2017, 03:49
Unlike TFM (avisynth), VFM (vapoursynth) does not have any postprocessing capabilities
Check this post (https://forum.doom9.org/showthread.php?p=1795527#post1795527)from Myrsloik:
... But you have to use d2vsource to get proper seeking or you'll get lots of weird things happening. Since you provided an mkv I assume you didn't do this. FFMS2 won't seek properly in your sample, ever, which probably creates most of your issues.
You can also script your own postprocessing like this:
import vapoursynth as vs
import functools
core = vs.get_core()
input_clip = core.std.BlankClip(format=vs.YUV420P8, length=1000, color=[255, 128, 128])
def postprocess(n, f, clip, deinterlaced):
if f.props['_Combed'] > 0:
return deinterlaced
else:
return clip
matched_clip = core.vivtc.VFM(input_clip, 1)
deinterlaced_clip = core.eedi3.eedi3(matched_clip, field=1)
postprocessed_clip = core.std.FrameEval(matched_clip, functools.partial(postprocess, clip=matched_clip, deinterlaced=deinterlaced_clip), prop_src=matched_clip)
decimated_clip = core.vivtc.VDecimate(postprocessed_clip)
decimated_clip.set_output()
This example will be added to the documentation as well. Substitute eedi3 with whatever you like.
jackoneill
6th February 2017, 22:34
It's all very confusing. Maybe you should reconsider this whole anime encoding thing. Read a book instead?
VS_Fan
8th February 2017, 03:33
You're right, my fault. I kind of hijacked KingLir’s (original poster) thread. It wasn't intended. This shows me how messy is my learning process: I was trying to share with the OP my own experience, I was testing different alternatives for doing something very similar, "rescuing" some old anime, from DVD and some recorded from TV years ago.
After finalizing my encodings. Here's my summary so this convoluted learning process can make some sense:
1. Use the original sources (DVD). Don't multiplex (MKVs). If you want to use your MKVs, an alternative would be to extract the mpeg2 elementary streams (m2v) from the MKV and use them as source.
2. Don't just deinterlace: First identify the interlacing: Is is telecine? (hard? or soft?)
2.1. If fully interlaced, go with QTGMC
2.2. For soft telecine just ignore the RFF (repeat first field) flags with FFMS2 source or d2vsource. No need to do anything else
2.3. For hard telecine, do IVTC (Inverse Telecine). Due to the lack of post-processing in VFM, and the impossibility to use mode 1 in VDecimate. I ended up using avisynth + TIVTC, just like it was recommended by manono. That way I got nice, fluid, progressive 24 fps video :)
I also like reading (https://en.wikipedia.org/wiki/Gabriel_Garc%C3%ADa_M%C3%A1rquez) :)
KingLir
8th February 2017, 22:10
You're right, my fault. I kind of hijacked KingLir’s (original poster) thread. It wasn't intended. This shows me how messy is my learning process: I was trying to share with the OP my own experience, I was testing different alternatives for doing something very similar, "rescuing" some old anime, from DVD and some recorded from TV years ago.
After finalizing my encodings. Here's my summary so this convoluted learning process can make some sense:
1. Use the original sources (DVD). Don't multiplex (MKVs). If you want to use your MKVs, an alternative would be to extract the mpeg2 elementary streams (m2v) from the MKV and use them as source.
2. Don't just deinterlace: First identify the interlacing: Is is telecine? (hard? or soft?)
2.1. If fully interlaced, go with QTGMC
2.2. For soft telecine just ignore the RFF (repeat first field) flags with FFMS2 source or d2vsource. No need to do anything else
2.3. For hard telecine, do IVTC (Inverse Telecine). Due to the lack of post-processing in VFM, and the impossibility to use mode 1 in VDecimate. I ended up using avisynth + TIVTC, just like it was recommended by manono. That way I got nice, fluid, progressive 24 fps video :)
I also like reading (https://en.wikipedia.org/wiki/Gabriel_Garc%C3%ADa_M%C3%A1rquez) :)
Many Thanks! Indeed these are my conclusions as well and it seems I manage to complete the first TV show I wanted.
But I still like to make sure I do the "identification process" correctly.
What is recommended and what do you do yourself ?
If what jackoneill wrote (below) is the best approach, how should I actually do it ? How to extract the frames and how to identify for sure each frame is progressive or interlaced ?
You find a scene where every frame is clearly different from the previous one, like when panning or zooming. You step through it one frame at a time. If you find a pattern of three progressive frames followed by two interlaced frames, then you have hard telecine and you need VFM + VDecimate. If all the frames in the scene are interlaced, then you need QTGMC.
Also, I read about the use of :
ffmpeg -filter:v idet -frames:v 10000 -an -f rawvideo -y /dev/null -i test.mkv
Is it good approach ? If so, what is the conclusion from these results, for example:
Repeated Fields: Neither: 7717 Top: 1172 Bottom: 1108
Single frame detection: TFF: 5726 BFF: 39 Progressive: 1830 Undetermined: 2402
Multi frame detection: TFF: 9997 BFF: 0 Progressive: 0 Undetermined: 0
Or these:
Repeated Fields: Neither: 8197 Top: 886 Bottom: 918
Single frame detection: TFF: 5390 BFF: 2 Progressive: 2173 Undetermined: 2436
Multi frame detection: TFF: 9752 BFF: 0 Progressive: 248 Undetermined: 1
VS_Fan
9th February 2017, 09:28
Mediainfo could be your first friend to determine if there´s soft telecine:
c:\TOOLS\MediaInfo_CLI\x64\MediaInfo.exe test1.m2v
… (hard telecine)
Frame rate : 29.970 (30000/1001) FPS
…
Scan type : Interlaced
Scan order : Top Field First
…
c:\TOOLS\MediaInfo_CLI\x64\MediaInfo.exe test2.m2v
… (soft telecine)
Frame rate : 23.976 (24000/1001) FPS
…
Scan type : Progressive
Scan order : 2:3 Pulldown
…
For finding out if there's hard telecine, idet (ffmpeg filter) should be a very interesting tool. (Thank you for posting about it, I didn't know it exsited). Check the ffmpeg manual (http://www.ffmpeg.org/ffmpeg-filters.html#idet). To better understand how it helps, I also suggest looking at this blogpost: “Detecting interlaced video with ffmpeg (http://www.aktau.be/2013/09/22/detecting-interlaced-video-with-ffmpeg/)”
Now, using your first samples:
C:\TOOLS\ffmpeg-3.2.2-win64-static\bin\ffmpeg.exe -filter:v idet -an -f rawvideo -y NUL -i test1.m2v
[…]
[Parsed_idet_0 @ 00000000025b25c0] Repeated Fields: Neither: 1298 Top: 260 Bottom: 235
[Parsed_idet_0 @ 00000000025b25c0] Single frame detection: TFF: 1148 BFF: 0 Progressive: 530 Undetermined: 115
[Parsed_idet_0 @ 00000000025b25c0] Multi frame detection: TFF: 1774 BFF: 0 Progressive: 1 Undetermined: 18
C:\TOOLS\ffmpeg-3.2.2-win64-static\bin\ffmpeg.exe -filter:v idet -an -f rawvideo -y NUL -i test2.m2v
[…]
[Parsed_idet_0 @ 00000000006868e0] Repeated Fields: Neither: 1431 Top: 0 Bottom: 0
[Parsed_idet_0 @ 00000000006868e0] Single frame detection: TFF: 0 BFF: 3 Progressive: 386 Undetermined: 1042
[Parsed_idet_0 @ 00000000006868e0] Multi frame detection: TFF: 0 BFF: 0 Progressive: 1430 Undetermined: 1
One could think there are indications of hard telecine in interlaced material if:
you see repeated fields in a proportion near to 1:5.
you see a considerable amount (35% or more) of progressive frames in “single frame detection”, compared to the amount of the interlaced ones (TFF/BFF) in the sinlge-frame detection.
Using these criteria, I would be 99% sure, based on the output of ffmpeg – idet you posted, that those two samples are hard-telecined. You could try IVTC and see for yourself.
In general, I would always confirm visually. Remember sometimes even progressive material was (erroneously) encoded and marked as interlaced!
KingLir
9th February 2017, 10:10
For finding out if there's hard telecine, idet (ffmpeg filter) should be a very interesting tool. (Thank you for posting about it, I didn't know it exsited). Check the ffmpeg manual (http://www.ffmpeg.org/ffmpeg-filters.html#idet). To better understand how it helps, I also suggest looking at this blogpost: “Detecting interlaced video with ffmpeg (http://www.aktau.be/2013/09/22/detecting-interlaced-video-with-ffmpeg/)”
Yes, this blogpost is were I took it from. But it doesn't answer my questions:
What results means fully interlaced ? what results means hard telecine and what results means soft telecine ?
But, in any case, I really interested to know what you do yourself. Since, as your wrote, you didn't use idet filter before.
Now, using your first samples:
[CODE]C:\TOOLS\ffmpeg-3.2.2-win64-static\bin\ffmpeg.exe -filter:v idet -an -f rawvideo -y NUL -i test1.m2v
I actually meant the new examples I posted in my last post (and not the test videos I initially uploaded).
One could think there are indications of hard telecine in interlaced material if:
you see repeated fields in a proportion near to 1:5.
you see a considerable amount (35% or more) of progressive frames in “single frame detection”, compared to the amount of the interlaced ones (TFF/BFF) in the sinlge-frame detection.
Using these criteria, I would be 99% sure, based on the output of ffmpeg – idet you posted, that those two samples are hard-telecined. You could try IVTC and see for yourself.
Thanks, but as you can see in previous posts, everyone agreed that the first is hard telecine and the second is soft telecine. Which indeed seems true since I received great outputs using the methods explained (IVTC for hard and just ffms2.Source for soft)
In general, I would always confirm visually. Remember sometimes even progressive material was (erroneously) encoded and marked as interlaced!
Yes, that's the procedure I like to know, as I mentioned above - how exactly ?
Sharc
9th February 2017, 11:05
Yes, that's the procedure I like to know, as I mentioned above - how exactly ?
For example as jackoneill suggested already:
Open the file in MPC-HC and step manually through the frames
- When you see all frames combed your video is most likely interlaced
- When you see a repetitive pattern of 3 "clean" (progressive) frames followed by 2 "dirty" (combed) frames your video is most likely telecined
Or method 2:
A more reliable method would be to watch the fields
assumeTFF()
separatefields()
Load the script in MPC-HC or VirtualDub and step manually through the pictures (=fields). Step-by-step. Select a segment with movement.
When you see a sequence like
aabbccddeeffgg.... your video is progressive (a,b,c etc. denote the fields, aa means that you see the same picture twice)
When you see a sequence like
abcdefghijk..... with no back-and-forth jumps your video is interlaced, TFF
When you see a sequence like
abcdefghijk...... with back-and-forth jumps your video is interlaced, BFF
When you see a sequence like
aaabbcccddeeeff ..... your video is 3:2 telecined
Edit:
And as has been said before, demux and index the file before analyzing. Don't use DirectShowSource.
KingLir
9th February 2017, 11:45
Or method 2:
A more reliable method would be to watch the fields
assumeTFF()
separatefields()
Load the script in MPC-HC or VirtualDub and step manually through the pictures (=fields). Step-by-step. Select a segment with movement.
When you see a sequence like
aabbccddeeffgg.... your video is progressive (a,b,c etc. denote the fields, aa means that you see the same picture twice)
When you see a sequence like
abcdefghijk..... with no back-and-forth jumps your video is interlaced, TFF
When you see a sequence like
abcdefghijk...... with back-and-forth jumps your video is interlaced, BFF
When you see a sequence like
aaabbcccddeeeff ..... your video is 3:2 telecined
Edit:
And as has been said before, demux and index the file before analyzing. Don't use DirectShowSource.
Thanks! Sorry for the following newbie question, but I wasn't able to find answers by googling.
How to load the script in MPC-HC ? I created an input.avs file with the lines below and when I open it in latest 32bit MPC-HC it's says the file can't be rendered.
FFMS2(input.mkv)
assumeTFF()
separatefields()
Sharc
9th February 2017, 12:26
Use quotation marks for the path of the input file
ffms2("C:\.....\input.mkv")
assumeTFF()
separatefields()
And as said before it is recommended to always demux the file first. You should then use the m2v video file:
ffms2("C:\.....\input.m2v")
assumeTFF()
separatefields()
KingLir
9th February 2017, 13:04
Use quotation marks for the path of the input file
ffms2("C:\.....\input.mkv")
assumeTFF()
separatefields()
And as said before it is recommended to always demux the file first. You should then use the m2v video file:
ffms2("C:\.....\input.m2v")
assumeTFF()
separatefields()
Still the same :(
input.avs:
ffms2("C:\input\input.m2v")
assumeTFF()
separatefields()
EDIT: nevermind - reinstalling Avisynth fixed it somehow.
KingLir
9th February 2017, 13:27
Now that the m2v plays in MPC-HC with the .avs script, where can I find the output data about the frames (fields) ? just look and them and compare to the patterns mentioned ? What exactly is back-and-forth jump ?
Sharc
9th February 2017, 14:16
It's a VISUAL inspection of the stream. No output data.
Step through the pictures and note down the sequence as you see it for say about 30 frames, then identify the pattern a I described, and draw your conclusion.
Back-and-forth jumps: e.g. people moving forward/backward/forward/backward etc. when you step through the fields.
Or take a horizontal camera pan: The picture would jitter left/right/left/right with every step. No fluid continuous motion in one direction.
KingLir
9th February 2017, 14:31
It's a VISUAL inspection of the stream. No output data.
Step through the pictures and note down the sequence as you see it for say about 30 frames, then identify the pattern a I described, and draw your conclusion.
Back-and-forth jumps: e.g. people moving forward/backward/forward/backward etc. when you step through the fields.
Or take a horizontal camera pan: The picture would jitter left/right/left/right with every step. No fluid continuous motion in one direction.
Thanks! Got it! About telecine...
When you see a sequence like
aaabbcccddeeeff ..... your video is 3:2 telecined
I am guessing this what I should see for hard telecine. What should be the pattern for soft telecine ?
Sharc
9th February 2017, 15:00
Thanks! Got it! About telecine...
I am guessing this what I should see for hard telecine. What should be the pattern for soft telecine ?
The same if your decoder/player honors the pulldown flags.
If it ignores the pulldown flags you will see a progressive field sequence aabbccddeeffgg.....
I think ffms2 ignores these flags, but I am not sure as I usually use DGIndex or DGIndexNV as indexer/demuxer/source filter.
KingLir
9th February 2017, 15:44
Thanks again.
In one dvd source I am seeing the aaabbcccddeeeff..... pattern and did IVTC. But I am getting this strange artifacts that aren't showing when I am doing a full de-interlacing with QTGMC
The same issue is seen with both TIVTC and VIVTC outputs.
Here are screenshots. I am guessing that, for the trained eye, it something obvious that I am missing. If not, I will cut out a test part and upload it.
https://preview.ibb.co/ht6m1F/VIVTC.png (https://ibb.co/iJyNaa)
https://preview.ibb.co/ixDzMF/QTGMC_2x.png (https://ibb.co/jrEjov)
Sharc
9th February 2017, 16:23
QTGMC does a lot of processing and cleaning. IVTC basically just restores the original pictures by matching the fields + decimating to obtain the original framerate.
You could try IVTC followed by QTGMC(InputType=1) for cleaning up the restored progressive frames.
TFM(mode=1).TDecimate(order=1) #or TFM(d2v="Video.d2v").TDecimate(Mode=1) see manono's post #21
QTGMC(InputType=1) #or 2 or 3
Edit:
Of course - if you prefer - you can always bob-deinterlace with QTGMC() and play back at 59.94 fps instead of IVTC, if you accept the pulldown judder.....
KingLir
10th February 2017, 13:36
QTGMC does a lot of processing and cleaning. IVTC basically just restores the original pictures by matching the fields + decimating to obtain the original framerate.
You could try IVTC followed by QTGMC(InputType=1) for cleaning up the restored progressive frames.
TFM(mode=1).TDecimate(order=1) #or TFM(d2v="Video.d2v").TDecimate(Mode=1) see manono's post #21
QTGMC(InputType=1) #or 2 or 3
Edit:
Of course - if you prefer - you can always bob-deinterlace with QTGMC() and play back at 59.94 fps instead of IVTC, if you accept the pulldown judder.....
Thanks, but I tried InputType=1 and also =3. Both clean some of the artifacts but still many remains ( compared to the full 59.94fps deinterlaced ).
I was hoping to avoid doubling the fps if not a must. Any ideas ?
Is it OK to do the following ? What are the disadvantages ?
TFM(mode=1).TDecimate(order=1)
QTGMC(Preset="Very Slow")
SelectEven()
Sharc
10th February 2017, 14:12
Thanks, but I tried InputType=1 and also =3. Both clean some of the artifacts but still many remains ( compared to the full 59.94fps deinterlaced ).
I was hoping to avoid doubling the fps if not a must. Any ideas ?
Is it OK to do the following ? What are the disadvantages ?
TFM(mode=1).TDecimate(order=1)
QTGMC(Preset="Very Slow")
SelectEven()
You can try. I don't expect much difference though as
QTGMC().Selecteven() is much the same as
QTGMC(InputType=1), AFAIK. See the documentation of QTGMC.
VS_Fan
10th February 2017, 20:44
I was hoping to avoid doubling the fps if not a must. Any ideas ?The following is one of my final tests for my encodings. Try and see if it somehow pleases you:
source = "test3.d2v"
MPEG2Source(d2v=source)
#deinterlaced = QTGMC( Preset="Slower", FPSDivisor=2 )
deinterlaced = nnedi3()
#deinterlaced = eedi3()
TFM(d2v=source, clip2=deinterlaced, mode=5) #, display=True)
tdecimate(mode=1) #, display=True)
Comments:
mpeg2source (d2v) remember the post I quoted form Myrsloik: "you have to use d2vsource to get proper seeking or you'll get lots of weird things happening"
eedi3 / nnedi3: post-processing by means of nnedi3 / eedi3 - look at "clip2" parameter in the TFM readme
TFM mode=5 more aggressive field matching (risk of jerkiness but more chances of getting good frames) look at "mode" parameter TFM readme
EDIT:
You can also try TFM(d2v=source, clip2=deinterlaced, mode=5, PP=4, display=True) To use the whole deinterlaced frame, not only the pixels in moving areas determined by the mask TFM creates using motion adaptation
KingLir
11th February 2017, 20:24
Thanks again VS_Fan and Sharc.
I tired all your recommendations but unfortunately nothing seems to change the artifacts in the output (the numerous dots texture on top of the frame - as seen in my screenshot above).
Here is the video (sample), which include the part I took the screenshot from.
https://mega.nz/#!4hwkjSSA!-DczgcLWdmEckFU64HH1XYcD8PU9J8d6qoJePoYmjqk
As said, only full 59.94 QTGMC result in a nice output (the second screenshot above).
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.