View Full Version : Is there any good way to IVTC h.264 video in FFmpeg?
MaximRecoil
24th December 2022, 16:43
There doesn't seem to be a subforum for FFmpeg here, so I don't know exactly where this question belongs.
Previously I've only ever encountered telecined video in the form of DVD MPEG-2 streams, and I've always used "forced film" in DGIndex on those with good results.
Today I encountered telecined h.264 video, and DGIndex doesn't work with h.264 video files, so I tried DGAVCIndex, but "forced film" did nothing at all. I couldn't try DGIndexNV because I guess you need an Nvidia video card just to use it.
Then I tried the suggestions from this thread...
https://forum.doom9.org/showthread.php?t=172289
... but the results were bad. The original interlaced frames were turned into frames that looked like a blend of two frames, giving it a sort of ghost image effect on those frames.
Then I tried VirtualDub's built-in IVTC filter, and that worked good; it looked just as good to me as DGIndex's "forced film" does on telecined MPEG-2 videos. By using VirtualDub2 I can use that same IVTC filter and also be able to encode with h.264, unlike with the standard VirtualDub. That would be okay if I only had one file to encode, but I need to encode a bunch of them, and it will take a lot longer with VirtualDub. With FFmpeg I can use a batch file to encode them all unattended.
microchip8
24th December 2022, 17:20
https://ffmpeg.org/ffmpeg-all.html#fieldmatch
MaximRecoil
25th December 2022, 02:07
https://ffmpeg.org/ffmpeg-all.html#fieldmatch
That's what I tried from that post I linked to. The first one I tried was:
-vf fieldmatch,yadif=deint=interlaced,decimate
The results were bad. Then I tried:
-vf fieldmatch,yadif=deint=interlaced,mpdecimate=max=-4:hi=1000:frac=1 -r 23.976
I didn't see any difference with that. In both cases I got three good frames followed by two bad frames, and so on, that looked like blended frames, like this:
https://i.imgur.com/ZYgbPxD.png
That's worse than just leaving it in its original telecined state.
Like I said, VirtualDub's built-in IVTC filter worked great; every frame is a good frame, just like when you use DGIndex's "forced film" on a telecined MPEG-2 video.
poisondeathray
25th December 2022, 03:01
That's what I tried from that post I linked to. The first one I tried was:
-vf fieldmatch,yadif=deint=interlaced,decimate
The results were bad.
In what way were they "bad" ? - Wrong matches, wrong decimation, something else ?
Sometimes the source timestamps are not perfect and it can mess with various ffmpeg operations
Try adding -vf fps=30000/1001
-vf fps=30000/1001 ,fieldmatch,yadif=deint=interlaced,decimate
MaximRecoil
25th December 2022, 05:05
In what way were they "bad" ? - Wrong matches, wrong decimation, something else ?
"Bad" like in the screenshot I posted in my previous post. I don't know what specifically it did wrong which resulted in all those blended frames.
Sometimes the source timestamps are not perfect and it can mess with various ffmpeg operations
Try adding -vf fps=30000/1001
-vf fps=30000/1001 ,fieldmatch,yadif=deint=interlaced,decimate
I went ahead and tried that and I got the same bad results as before. I know it's possible to IVTC this file correctly because VirtualDub's IVTC filter does it with just its default settings; well, default except I changed the "field assembly mode" from "decomb frames only" to "reduce frame rate," which results in 23.976 FPS, the same as "decimate" does in FFmpeg:
https://i.imgur.com/GHvynxR.png
It's strange that FFmpeg doesn't seem to have a function to do it correctly while VirtualDub's IVTC filter, which is at the very least, 10 years old, has no problem with it.
Sharc
25th December 2022, 12:53
The suggested ffmpeg commandline works perfectly here for IVTC.
Is your source hard- or soft telecined? Upload a few seconds of your source, so someone may try.
MaximRecoil
25th December 2022, 13:33
The suggested ffmpeg commandline works perfectly here for IVTC.
Is your source hard- or soft telecined?
Hard telecined.
Upload a few seconds of your source, so someone may try.
Well this is weird. I cut out a 5-second clip and was about to upload it, but before I did I decided to try to IVTC it using just the "fieldmatch,yadif=deint=interlaced,decimate" command, and deleted the rest of the commands I had in there for cropping, resizing, etc., and it worked perfectly. So I tried it again with the rest of my commands in there and I got the bad results again. So I tried switching them around, i.e., made it so the IVTC command came first in the script, followed by the resizing commands, and that worked perfectly.
This is how I originally had it, which gave bad results:
-vf "crop=1440:1080,scale=704x480:flags=lanczos,pad=720:480:8:0,setsar=sar=10/11,fieldmatch,yadif=deint=interlaced,decimate"
But this gives perfect results:
-vf "fieldmatch,yadif=deint=interlaced,decimate,crop=1440:1080,scale=704x480:flags=lanczos,pad=720:480:8:0,setsar=sar=10/11"
I don't know why it gives screwy results if you tell it to IVTC after cropping/resizing/etc., but it does.
So this is solved, thanks. I guess I should have posted my script in the first place, but it never occurred to me that seemingly unrelated things like cropping and resizing could possibly make a difference.
Sharc
25th December 2022, 13:42
What crosses my mind:
In the first case you cropped and resized the combed ("interlaced") frames before restoring these to progressive frames by fieldmatching, which is no good as I understand because it screws the field structure up.
Asmodian
26th December 2022, 18:24
Yes, as you discovered, never scale interlaced video as if it was progressive!
You mix the lines together, generating those nasty blended frames and nothing is going to be able to help after that.
MaximRecoil
27th December 2022, 08:55
Yes, as you discovered, never scale interlaced video as if it was progressive!
You mix the lines together, generating those nasty blended frames and nothing is going to be able to help after that.
Yeah, that probably would have happened in VirtualDub too except that I happened to add the IVTC filter first, and then added the resizing, cropping, and padding filters.
By the way, I was reading this site...
https://ffmpeg.org/pipermail/ffmpeg-devel/2013-March/141105.html
... and it says:
Here is the most basic usage of the filters:
-vf fieldmatch,decimate
So I tried encoding one of the videos that way and the results look just as good to me as with the "yadif=deint=interlaced" in between "fieldmatch" and "decimate," so I'm going to do it that way. One less operation for it to do makes it encode a little faster.
I'm not even sure what the purpose of "yadif=deint=interlaced" is if you're encoding purely telecined material. Is it for when you have a mix of film-source and video-source material in the same video file? Either way, if it accomplishes anything with purely telecined material it isn't anything I can notice with these particular video files, so I can do without it.
poisondeathray
27th December 2022, 17:07
I'm not even sure what the purpose of "yadif=deint=interlaced" is if you're encoding purely telecined material. Is it for when you have a mix of film-source and video-source material in the same video file? Either way, if it accomplishes anything with purely telecined material it isn't anything I can notice with these particular video files, so I can do without it.
It's for residual combing
You can have a 100% film source, but you can still have cadence breaks (e.g. post telecine edits, common with 90's and early 2000's North American TV series on DVD), which leave you with combed frames
If you have 100%, 3:2 pure, 100% no cadence breaks, then you wouldn't need it IVTC post processing . e.g most modern Hollywood movies on DVD are actually 100% soft telecine, perfect cadence. But you mentioned hard telecine... and that can sometimes be "iffy" . Sometimes just knowing what the title, what content, and what era it was produced in can provide clues as to what it is.
MaximRecoil
27th December 2022, 19:12
I have several different old TV series on Blu-ray. Sometimes I watch them directly from the Blu-ray on my PC, just to see how they look in HD, but more often than not I want to watch them the way they were seen when they originally aired, i.e., on a standard-resolution 4:3 CRT TV. That's a problem with Blu-ray though, because it's inherently 16:9, so 4:3 content is inevitably pillar-boxed. If you watch it as-is on a 4:3 TV, you end up with both the pillar-boxing that's hard encoded into the video stream and letter-boxing from the TV, i.e., window-boxing. So I rip them with MakeMKV and re-encode them to DVD resolution, since that's enough resolution to max out the quality potential of an SD TV. Going higher (e.g., 960 x 720 or 1440 x 1080) would just be a waste of drive space.
In any case, this is a 1970s shot-on-film TV series, and it's the first one I've encountered on Blu-ray that was hard telecined. In every other case, the ripped files were 23.976 FPS progressive as-is.
Like I mentioned before, I've never had to IVTC anything except for when re-encoding DVD rips, and I haven't done that in years, because I don't re-encode DVD rips anymore. I rip them with MakeMKV and remux them into an MPG (Mpeg-PS) container and my Blu-ray player can play them from a USB drive (which is nice for watching a TV series because you don't have to keep changing discs), and there's no difference in the way the telecining is handled compared to playing them directly from the DVD.
I've encoded and watched several episodes now without Yadif in the script and they all look perfectly fine.
MaximRecoil
28th December 2022, 02:25
I noticed that one of the episodes that I encoded both ways (with and without Yadif in the script) have the same file size, right down to the byte:
https://i.imgur.com/duMRfSq.png
So I did a binary file comparison:
https://i.imgur.com/o32fcLW.png
Then I did the same binary file comparison for several other episodes that I encoded both ways and they were also bit-for-bit identical in every case, so Yadif hasn't done anything to these files at all.
Even though Yadif isn't doing anything so far, I wonder if having it in the script slows down the encoding speed. They seemed to encode faster when I removed Yadif from the script, but that could have been a coincidence because there are a lot of constantly changing variables with an in-use PC that can affect encoding speed. If it doesn't affect encoding speed when there are no stray combed frames for it to deal with, then I wouldn't mind leaving it in the script just in case it happens to be needed in one or more of the several dozen episodes I still have to encode.
Selur
28th December 2022, 09:20
out of curiosity: can you share a short sample (a few seconds of horizontal movement would be enough) of your source?
I would like to see some telecined avc content.
Cu
Selur
MaximRecoil
28th December 2022, 10:45
out of curiosity: can you share a short sample (a few seconds of horizontal movement would be enough) of your source?
I would like to see some telecined avc content.
https://app.box.com/s/pxpj1tpbk24v13lbhosdmtmjuxyvpjej
Sharc
28th December 2022, 13:49
One finds hard-telecined AVC stuff often in Extras and Trailers on Blu-ray discs, sometimes in hybrid form like interviews=interlaced and movie= hard-telecined.
Selur
30th December 2022, 18:30
@MaxinRecoil: thanks :)
@Shar: good to know
MaximRecoil
15th January 2023, 04:44
Would it be possible to inverse telecine, crop and resize, and then re-telecine in the same script? I know I can't just leave the original telecining in there and resize it because I'll get those ugly blended frames.
I watch these old TV shows on a Blu-ray player from a USB drive, connected to a standard resolution (15 kHz / 480i) CRT TV, so when I play a progressive (23.976 FPS) video, the Blu-ray player has to convert it to 480i on the fly. It produces prominent interlacing artifacts when doing that, particularly noticeable on straight edges that are slanted, and also there are frequent moire and strobing effects that you can see in certain clothing, window blinds, etc.
On the other hand, when I play video that's already telecined, such as an untouched DVD rip of a film-source TV show, interlacing artifacts are barely noticeable.
I can't find much information about it online (probably because most people are only trying to get rid of telecining, not add it), other than this:
https://ffmpeg.org/ffmpeg-filters.html#telecine
If it's possible to do what I want, how would I incorporate it into the following script (I just want it to end up properly telecined like it started out as, but at 640x480 instead of pillar-boxed 1920x1080)?
ffmpeg -i input.mkv -vf "fieldmatch,yadif=deint=interlaced,decimate,crop=1440:1080,scale=640x480:flags=lanczos" -c:v libx264 -crf 18 -c:a copy output.mp4
Sharc
15th January 2023, 09:40
Would it be possible to inverse telecine, crop and resize, and then re-telecine in the same script?
Add telecine to your filter, like:
ffmpeg -i input.mkv -vf "fieldmatch,yadif=deint=interlaced,decimate,crop=1440:1080,scale=640x480:flags=lanczos,telecine" -c:v libx264 -crf 18 -c:a copy output.mp4
Do you really want a small 640x480, re-telecined? If it's only for removing the side pillars you could probably do without vertical resizing, but just crop to 1440x1080 instead and encode it interlaced with DAR 4:3. No need to IVTC. Something like:
ffmpeg -i input mkv -vf crop=1440:1080,setfield=tff,setdar=4/3 -c:v libx264 -flags +ilme+ildct -crf 18 -c:a copy output.mp4
MaximRecoil
15th January 2023, 15:52
Add telecine to your filter, like:
Thanks. I don't need to specify any parameters for the telecine filter?
Do you really want a small 640x480, re-telecined?
Why not? DVDs are effectively the same resolution (the player resizes a DVD video from 720x480 to 640x480 due to the 4:3 DAR) and they are all telecined when they are film-source. Like I said in my previous post, DVDs and untouched DVD rips look great on my setup, hardly any noticeable interlacing artifacts.
If it's only for removing the side pillars you could probably do without vertical resizing, but just crop to 1440x1080 instead and encode it interlaced with DAR 4:3. No need to IVTC. Something like:
Yeah, but then each video would be huge, probably around 8 or 10 GB after encoding with a CRF of 18, and that additional file size and resolution would be of no benefit at all because a 15 kHz TV can only display up to ~480 lines (or up to ~240 lines if progressive), at ~60 Hz. DVD resolution maxes out the picture quality potential of a 15 kHz TV.
Sharc
15th January 2023, 17:44
Thanks. I don't need to specify any parameters for the telecine filter?
Not for standard 2:3 telecine. The defaults should be fine.
Why not? DVDs are effectively the same resolution (the player resizes a DVD video from 720x480 to 640x480 due to the 4:3 DAR) and they are all telecined when they are film-source.
It's up to you of course. I thought the original resolution of your source was 1920x1080 (as stored) from a Blu-ray, and you might want to preserve as many details as possible, e.g. for playback with a future better TV with a bigger monitor. Whatever.
MaximRecoil
15th January 2023, 18:58
Not for standard 2:3 telecine. The defaults should be fine.
Okay. I tried it and looking at individual frames in VirtualDub, it looks like it was successful. I haven't watched it on my TV yet though. One thing that's weird is that MediaInfo identifies it as progressive, while it identifies the original video as interleaved fields, top field first:
https://i.imgur.com/i44WAVq.png
It's up to you of course. I thought the original resolution of your source was 1920x1080 (as stored) from a Blu-ray, and you might want to preserve as many details as possible, e.g. for playback with a future better TV with a bigger monitor. Whatever.
No, this is exactly the type of TV that I want to watch old TV shows on, and it always will be. I watch movies on my HD projector on a 100" screen, because theatrical movies were intended to be seen projected onto a screen, but old TV shows were intended to be seen on a 15 kHz TV, which is how I and everyone else saw them when they originally aired. I have the Blu-rays themselves if I ever want to watch them in HD.
Edit: What exactly do you mean by a 15kHz TV?
Standard definition TVs, the kind that everyone had from the beginning of the TV era until about the 2000s, can only sync to a horizontal scan rate of ~15 kHz (it's about 15.7 kHz, but it's commonly stated as 15 kHz). An NTSC signal has 480 visible lines, interlaced, and has a ~60 Hz refresh rate, which works out to a ~15 kHz horizontal scan rate. A PAL signal has 576 visible lines, interlaced, and a 50 Hz refresh rate, which also works out to ~15 kHz. A signal from an old video game console, such as SNES, NES, Atari 2600, etc., has ~240 visible lines, progressive, and a ~60 Hz refresh rate, which also works out to ~15 kHz. So a standard resolution TV can sync to either a ~480i or ~240p signal at ~60 Hz.
For 480p at 60 Hz you need a ~31 kHz TV/monitor, which is commonly commonly called "VGA" (though that's not an entirely accurate usage of the term VGA). Prior to DVD, there was no mainstream home video format that could even generate a 480p signal, and TV broadcasts were all 480i (in NTSC territory), so there was no need for TVs to be anything higher than 15 kHz. However, with film-source DVDs that are soft-telecined, combined with a DVD player capable of "progressive scan," you can get a 31 kHz signal out of them, so starting in the late 1990s some ~31 kHz CRT TVs (all of which had component [YPbPr] inputs, because composite and S-video are ~15 kHz standards) started appearing in stores, and eventually there were even some 16:9 CRT TVs that could sync to 720p / 1080i.
There's an article about it here, though it's not very detailed:
https://en.wikipedia.org/wiki/Horizontal_scan_rate
poisondeathray
15th January 2023, 19:10
Why not? DVDs are effectively the same resolution (the player resizes a DVD video from 720x480 to 640x480 due to the 4:3 DAR) and they are all telecined when they are film-source. Like I said in my previous post, DVDs and untouched DVD rips look great on my setup, hardly any noticeable interlacing artifacts.
But why would you want to add hard telecine after inversing the telecine ? You're adding 25% more field repeats for nothing. It's less efficient. You're encoding MBAFF instead of native progressive. Again less efficient. You risk playback problems on devices that cannont IVTC properly (get deinterlaced instead, reducing the effective resolution in 1/2) . It's all negatives, zero positives
One thing that's weird is that MediaInfo identifies it as progressive, while it identifies the original video as interleaved fields, top field first:
You didn't include the MBAFF encoding or field order . Try -x264opts tff=1 for top field first
Another more efficient option is soft telecine flags (analogous to mpeg2 DVD soft telecine, progressive encoding @23.976p , 25% fewer fields encoded, repeat field flags output 29.97i signal ), but not all players will handle AVC soft telecine correctly. I do not think it's implemented in ffmpeg libx264. For x264cli it's --pulldown 32 --fake-interlaced
MaximRecoil
15th January 2023, 19:41
But why would you want to add hard telecine after inversing the telecine ? You're adding 25% more field repeats for nothing. It's less efficient. You're encoding MBAFF instead of native progressive. Again less efficient. You risk playback problems on devices that cannont IVTC properly (get deinterlaced instead, reducing the effective resolution in 1/2) . It's all negatives, zero positives
I said why I want to do it in my post, i.e., film-source DVDs and untouched DVD rips look better (barely noticeable interlacing artifacts) on my setup than IVTC'd film-source AVC files do (prominent interlacing artifacts from the player interlacing it on the fly, which it has to do in order to generate a valid 480i video signal from 23.976 FPS progressive video). Here's the MediaInfo for one of many untouched film-source DVD rips that look great on my setup:
https://i.imgur.com/mtgdQW8.png
However, the test was a failure, because it resulted in blatant juddery motion when the camera was panning. So either FFmpeg's telecine filter doesn't work properly, at least not with the defaults, or my Blu-ray player doesn't handle telecined AVC content properly like it does telecined MPEG-2 content. Maybe the only way to get them to look as good as a DVD is to encode them as DVD compliant files, but that would make them quite a bit bigger than AVC for comparable quality, and I know virtually nothing about MPEG-2 encoding. From what little I do know, it seems that getting good results is a lot more cryptic than with more modern codecs.
You didn't include the MBAFF encoding or field order . Try -x264opts tff=1 for top field first
Another more efficient option is soft telecine flags (analogous to mpeg2 DVD soft telecine, progressive encoding @23.976p , 25% fewer fields encoded, repeat field flags output 29.97i signal ), but not all players will handle AVC soft telecine correctly. I do not think it's implemented in ffmpeg libx264. For x264cli it's --pulldown 32 --fake-interlaced
I could give that a try but I'd be surprised if my Blu-ray player would pay any attention to telecine flags in an AVC stream.
Sharc
15th January 2023, 19:48
One thing that's weird is that MediaInfo identifies it as progressive, while it identifies the original video as interleaved fields, top field first
Yes, my bad. Here the modified commandline:
ffmpeg -i input.mkv -vf "fieldmatch,yadif=deint=interlaced,decimate,crop=1440:1080,scale=640x480:flags=lanczos,telecine" -c:v libx264 -x264opts crf=18:tff=1 -c:a copy output.mp4
poisondeathray
15th January 2023, 19:55
BD players should accept SD AVC soft telecine, if they are authored with a compliant tool. But the same player might fail if file is played back as a non authored in MP4 or MKV. 640x480 is not BD compliant either - you'd have to go strict 720x480 and use BD compliant settings
MaximRecoil
15th January 2023, 20:48
Yes, my bad. Here the modified commandline:
Thanks.
BD players should accept SD AVC soft telecine, if they are authored with a compliant tool. But the same player might fail if file is played back as a non authored in MP4 or MKV. 640x480 is not BD compliant either - you'd have to go strict 720x480 and use BD compliant settings
I just tried one of the original hard-telecined BDs in my player, and it has slightly juddery motion when panning; not nearly as juddery as the hard-telecined test file I just encoded, but not judder-free like my IVTC'd encodes. I guess my player just doesn't care much for hard-telecined AVC streams.
As for using x264cli to soft-telecine, is it even possible to IVTC with it? According to its --help readout, the only available filters are crop, resize, and select_every. If it can't IVTC, can it soft-telecine already-IVTC'd video without re-encoding?
poisondeathray
15th January 2023, 21:00
You can pipe ffmpeg to x264, or use avisynth to x264 , or vapoursynth to x264 . The x264 part is just for encoding and soft telecine
x264 does not have an ivtc filtering patch (at least I'm not aware of any, there might be some custom builds somewhere), and x264 cannot add soft telecine flags to an existing stream without re-encoding. There is DGAVCPulldown for an existing progressive stream (similar to DGPulldown for MPEG2) , but there some limitations
DGAVCPulldown adds 3:2 field pulldown to AVC elementary streams. Due to the insane
idea of negative POCs in AVC, a two-pass algorithm is used to avoid having to do
lookahead. On the first pass through the source elementary stream, analysis is
performed. On the second pass, the pulled-down output stream is written.
Source code is provided under GPL. It's quite messy but is provided as is in case it
may help others trying to parse AVC video. Portions of the code are derived from the
public domain JM reference software, and the JM licensing continues to apply to those
portions.
DGAVCPulldown currently works
with the output from the stock x264.exe encoder as well as the NAL-HRD patched version
of x264.exe. It will work with any AVC elementary stream with the following limitations:
1. The stream must have VUI timing info specifying 23.976 fps.
2. The stream must not already be specifying picture_structure.
3. If HRD info is present, picture timing SEIs (without picture_structure) must also
be present.
Limitations 2 and 3 can potentially be removed, but I will need stream samples to
implement those changes, so if you run into limitation 2 or 3, please contact me.
You can find my email address here:
MaximRecoil
15th January 2023, 21:48
You can pipe ffmpeg to x264
I'd like to try that but I don't know how it's done, i.e., I don't know how to tell FFmpeg to pipe to x264, nor how to tell it where to find the x264.exe file.
Can you give me an example script, assuming I have x264.exe in the same folder as FFmpeg.exe?
poisondeathray
15th January 2023, 22:09
I'd like to try that but I don't know how it's done, i.e., I don't know how to tell FFmpeg to pipe to x264, nor how to tell it where to find the x264.exe file.
Can you give me an example script, assuming I have x264.exe in the same folder as FFmpeg.exe?
It would look like this
ffmpeg -i input.ext <options> -an -f yuv4mpegpipe - | x264 --demuxer y4m - <options> -o output.264
The only way AVC soft pulldown worked properly for my panasonic and sony BD players, was using BD compliant settings, and proper muxing/authoring in a transport stream. The exact same file in muxed to a MKV container did not play properly. The exact same file muxed with tsmuxer did not player properly. Some people have players that are robust and play everything properly. YMMV
https://sites.google.com/site/x264bluray/home/480p-ntsc
I just tried one of the original hard-telecined BDs in my player, and it has slightly juddery motion when panning; not nearly as juddery as the hard-telecined test file I just encoded, but not judder-free like my IVTC'd encodes. I guess my player just doesn't care much for hard-telecined AVC streams.
If you're watching on a 60Hz display, you're always going to get some judder, even your IVTC'ed encodes. It's impossible not to.
There can be other reasons for more than normal motion problems. Certain BD players can be finicky, and certain encoding settings can affect playback. If you encode with BD compliant settings, proper VBV buffer settings, you can at least eliminate those other reasons
Sharc
15th January 2023, 23:16
I just tried one of the original hard-telecined BDs in my player, and it has slightly juddery motion when panning; not nearly as juddery as the hard-telecined test file I just encoded, but not judder-free like my IVTC'd encodes. I guess my player just doesn't care much for hard-telecined AVC streams.
I understand that your original hard-telecined BD was 1920x1080 in an .m2ts container, right?
How does your re-encoded and re-telecined file play in an .m2ts container? Same judder? Maybe your player just bobs the re-telecined .mkv.
MaximRecoil
15th January 2023, 23:25
It would look like this
Thanks.
The only way AVC soft pulldown worked properly for my panasonic and sony BD players, was using BD compliant settings, and proper muxing/authoring in a transport stream. The exact same file in muxed to a MKV container did not play properly. The exact same file muxed with tsmuxer did not player properly. Some people have players that are robust and play everything properly. YMMV
https://sites.google.com/site/x264bluray/home/480p-ntsc
If tsMuxer doesn't work, then I don't know what else to use.
And why does that site you linked to say to use SAR 10/11 for 4:3? 10/11 is for 704x480 picture content pillar-boxed to 720x480. It results in a 1.363:1 DAR, with the 704x480 picture content ending up as 1.33:1 (4:3). I was already doing that before, which you can see in the script I posted in post #7, because it compensates a little bit for overscan (I later decided to just do 640x480 because 720x480 gets automatically resized to that by the player anyway but it ends up being a bigger file size for no picture quality benefit), but if your picture content is the full 720x480 then you want SAR 8:9, because 720x480 = 1.5:1, and 1.5 × 8/9 = 1.33.
If I remember right, DVDs are commonly encoded both ways. Does BD only allow 10/11 for 4:3 720x480 video?
If you're watching on a 60Hz display, you're always going to get some judder, even your IVTC'ed encodes. It's impossible not to.
There's no judder with the IVTC'd files, nor with film-source DVDs, beyond what's inherent to telecined video on a normal TV (which everyone who grew up in NTSC land watching analog broadcast TV and VHS tapes is used to anyway). The judder I'm talking about goes way beyond that. On a scale of 1 to 10, with 1 being the normal inherent (and very minor) judder, the original hard-telecined BD was about a 3, and the test file that I telecined with FFmpeg's telecine filter was a 10.
Sharc
15th January 2023, 23:36
....Does BD only allow 10/11 for 4:3 720x480 video?
Yes, as per BD specs.
poisondeathray
15th January 2023, 23:42
Yes, for SD BD, only those values are allowed according to the BD spec . Strict authoring tools will reject it otherwise , strict BD players will not play it
I used scenarist BD . The only free tool that worked was DVD Logic Easy BD Lite; not sure if it's available anymore. There should be some old versions archived on the videohelp site if it's not available anymore. I haven't done this for 5-6 years, it might be that newer BD players are less strict - they might accept tsmuxer muxed files (tsmuxer has been opensourced with some new development, so it might work now - it's worth a try)
MaximRecoil
15th January 2023, 23:53
I understand that your original hard-telecined BD was 1920x1080 in an .m2ts container, right?
I tried it in both an .m2ts container (I used tsMuxerGUI to do that) and the MKV container that MakeMKV originally put them in. It looked exactly the same both ways, including the same amount of judder. I can't try the actual discs in that BD player because its disc drive is screwed up, so I can only play files from a USB drive on it. The only working BD drive I have is the one in my PC.
How does your re-encoded and re-telecined file play in an .m2ts container? Same judder? Maybe your player just bobs the re-telecined .mkv.
For some reason, tsMuxerGUI won't open it. It just gives me this very informative error message:
https://i.imgur.com/JPOaA1w.png
So I used FFmpeg to put it into an .m2ts container, and there's no judder, which is very surprising because even the original 1080i hard-telecined file has some judder, though I haven't tried it with an FFmpeg-produced .m2ts container yet, just a tsMuxer-produced one.
I'm watching it now; I have to wait until some of the interlacing artifact scenes come along to see whether or not it's an improvement over my IVTC'd encodes. I'm already seeing the same prominent moire effect on one of the actors' pinstriped shirt collar, so there's no improvement in that area.
Sharc
16th January 2023, 00:23
For some reason, tsMuxerGUI won't open it. It just gives me this very informative error message:
https://i.imgur.com/JPOaA1w.png
So I used FFmpeg to put it into an .m2ts container, and there's no judder, which is very surprising because even the original 1080i hard-telecined file has some judder, ....
Strange. I have no problem in opening re-telecined 640x480 .mkv or .mp4 test clips (produced with the ffmpeg commandline) in tsMuxerGUI.
Maybe you upload a few seconds of your re-encoded and re-telecined juddery clip so someone might take a look just to check if there is something suspicious with the file .....
Edit:
There is also the faint possibility that there is an issue with the ffmpeg source filter for your telecined source. Maybe you try the same process in avisynth using LWLibavVideoSource as source filter, and compare the results.
MaximRecoil
16th January 2023, 01:18
Strange. I have no problem in opening re-telecined 640x480 .mkv or .mp4 test clips (produced with the ffmpeg commandline) in tsMuxerGUI.
Maybe you upload a few seconds of your re-encoded and re-telecined juddery clip so someone might take a look just to check if there is something suspicious with the file .....
I just cut out a 10-second clip to upload, using Avidemux direct stream copy, into an MP4 container (the same as the original file is in), but the 10-second clip opens fine in tsMuxerGUI. Then I remuxed the entire original file into an MKV container using MKVToolNixGUI, and it opened fine in tsMuxerGUI too.
Then I tried the 10-second MP4 and the full MKV remux in my BD player, and the 10-second MP4 was juddery but the MKV was not. Then I tried the 10-second MP4 again, and no judder this time. I stopped and played it several more times; still no judder. So it seems that the container type doesn't actually matter, but rather, something is sometimes confusing the BD player; maybe it's because I didn't have "-x264opts crf=18:tff=1" in the script when I encoded it?
It doesn't really matter though because I'm not keeping it. I watched enough of it to see that it looks exactly the same as my plain IVTC'd encodes, including the prominent moire and slanted line interlacing artifacts in certain scenes, so hard telecining is pointless in this case, since it makes the file size bigger and doesn't improve anything.
I haven't tried soft-telecining yet, but I plan to.
Sharc
16th January 2023, 10:44
I just cut out a 10-second clip to upload, using Avidemux direct stream copy, into an MP4 container (the same as the original file is in), but the 10-second clip opens fine in tsMuxerGUI. Then I remuxed the entire original file into an MKV container using MKVToolNixGUI, and it opened fine in tsMuxerGUI too.
Then I tried the 10-second MP4 and the full MKV remux in my BD player, and the 10-second MP4 was juddery but the MKV was not. Then I tried the 10-second MP4 again, and no judder this time. I stopped and played it several more times; still no judder. So it seems that the container type doesn't actually matter, but rather, something is sometimes confusing the BD player; maybe it's because I didn't have "-x264opts crf=18:tff=1" in the script when I encoded it?
That's the longer the more mysterious. Try this commandline:
ffmpeg -r 29.97 -i "your telecined.mkv" -vf "fieldmatch,yadif=deint=interlaced,decimate,crop=1440:1080,scale=640x480:flags=lanczos,telecine=pattern=23:first_field=top" -c:v libx264 -flags +ilme+ildct -x264opts crf=18:tff=1 -c:a copy output.mkv
You may also want to try the so called "advanced" 2:3:3:2 telecine pattern which gives 4 progressive and 1 combed frame. Maybe it irritates your player less, although it has a slightly higher judder than standard 2:3
ffmpeg -r 29.97 -i "your telecined.mkv" -vf "fieldmatch,yadif=deint=interlaced,decimate,crop=1440:1080,scale=640x480:flags=lanczos,telecine=pattern=2332:first_field=top" -c:v libx264 -flags +ilme+ildct -x264opts crf=18:tff=1 -c:a copy output.mkv
It doesn't really matter though because I'm not keeping it. I watched enough of it to see that it looks exactly the same as my plain IVTC'd encodes, including the prominent moire and slanted line interlacing artifacts in certain scenes, so hard telecining is pointless in this case, since it makes the file size bigger and doesn't improve anything.
But you can't watch your IVTCed variant with your legacy "15kHz NTSC TV".
MaximRecoil
16th January 2023, 17:05
But you can't watch your IVTCed variant with your legacy "15kHz NTSC TV".
There seems to be a misunderstanding here. I can watch them on my TV because my BD player can convert any video that it's capable of playing into an analog 15 kHz / 480i video signal, which it can output via its composite (CVSB), S-video, or component (YPbPr) jacks.
If a player is playing a progressive video like my plain IVTC'd encodes, then it has to add its own interlacing on the fly in order to generate a 480i signal, but if it's playing video that's already interlaced, it doesn't have to add its own interlacing.
I noticed that untouched DVD rips, which are inherently interlaced (either with hard or soft telecining in the case of film-source ones), look almost like progressive video on my setup. There are visible interlacing artifacts, but they aren't very noticeable unless you're looking for them.
On the other hand, my IVTC'd encodes have more prominent interlacing artifacts on my setup (but not to the point of being unwatchable). So my theory was that if I telecined them, maybe it would make them look like a DVD (less prominent interlacing artifacts). But it didn't work, i.e., once I got my re-telecined test encode to play without judder, it looked exactly the same as my plain IVTC'd encodes do, rather than looking like a DVD like I'd hoped. So I'm out of ideas. I guess my BD player is just better at dealing with DVDs than with AVC files when it comes to interlacing.
Out of curiosity I just tried one of my plain IVTC'd encodes in a different hardware player, a WD TV Live that I used before I got the BD player. It did a great job in terms of generating the on-the-fly interlacing; hardly any moire effect on that actor's pinstriped shirt collar (as opposed to tons of moire there with my BD player) and very little noticeable interlacing artifacts in general, like with a DVD on my BD player.
It has its own problems though, which is why I ditched it in favor of the BD player: dull colors, a few seconds of lag whenever you press a button on the remote control, and it loves to corrupt USB drives that are formatted NTFS (it doesn't corrupt FAT32 drives, but FAT32 has a 4 GB file size limit). It works fine with NTFS drives, but when I plug them into my PC afterwards, Windows always has to repair them.
On the other hand, my Sony BD player produces vibrant colors, instantly responds to the remote control, and never corrupts USB drives, regardless of the file system. Its problems include janky interlacing when it comes to AVC files, supports fewer file types than the WD TV Live, has too much overscan, and unlike the WD TV Live, it has no option to adjust the raster size and position.
Before the WD TV Live I had a Philips DVD player, one of the first DVD players that could play Divx/Xvid files. It had vibrant colors, no problems with interlacing, and no remote control lag, but I don't want to go back to Xvid and burning files to a CD/DVD (it didn't have a USB port).
Sharc
16th January 2023, 18:18
Well yes, the fundamental differences as I see it are:
- The 4:3 NTSC DVD film content is hard- or soft telecined mpeg2, 29.97fps. The frame size is 720x480, non-square pixel. A standard format.
- Your IVTC'd, re-sized, re-encoded and re-telecined files are AVC (x264 encoded), hard telecined, 29.97fps. The frame size is 640x480, 4:3, square pixel. A custom format.
I don't know where the culprit is and how your players handle custom formats.
MaximRecoil
16th January 2023, 22:25
Well yes, the fundamental differences as I see it are:
- The 4:3 NTSC DVD film content is hard- or soft telecined mpeg2, 29.97fps. The frame size is 720x480, non-square pixel. A standard format.
- Your IVTC'd, re-sized, re-encoded and re-telecined files are AVC (x264 encoded), hard telecined, 29.97fps. The frame size is 640x480, 4:3, square pixel. A custom format.
I don't know where the culprit is and how your players handle custom formats.
I get the same results (same prominent interlacing artifacts) when encoding at 720x480, SAR=10/11, like in the script I posted in post #7.
I changed to 640x480, SAR=1/1, because it doesn't make any difference in how it looks, and it results in smaller files at a given CRF value (38,400 less pixels to encode).
I still haven't tried doing a fully BD-compliant encode like poisondeathray talked about. I need to figure out what can be excised from the script in the link he posted,
while still resulting in a BD-compliant encode, because I don't want to do 2-pass, nor use "preset veryslow," and I don't think "tune film" is necessary either.
I tried this...
ffmpeg -i input.mkv -vf "fieldmatch,yadif=deint=interlaced,decimate,scale=704x360:flags=lanczos,pad=720:480:8:60" -an -f yuv4mpegpipe - | x264 --crf 18 --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 24 --open-gop --slices 4 --pulldown 32 --fake-interlaced --colorprim "smpte170m" --transfer "smpte170m" --colormatrix "smpte170m" --sar 10:11 -o output.264
... but it didn't work. I got this error:
av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument00:00:00.04 bitrate=99452.2kbits/s speed=0.655x
frame= 1 fps=0.0 q=-0.0 Lsize= 506kB time=00:00:00.04 bitrate=99452.2kbits/s speed=0.366x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 109750.421875%
Error closing file pipe:: Invalid argument
Conversion failed!
poisondeathray
16th January 2023, 22:49
See post #30
for the x264 arguments you are missing --demuxer y4m -
MaximRecoil
16th January 2023, 23:12
See post #30
for the x264 arguments you are missing --demuxer y4m -
Thanks, that seems to be working. I had your example from post #30 in front of me when I made the script but somehow that part got lost in the shuffle. I must have accidentally deleted it during the various copy and pasting I was doing from the script at the site you linked to, and from my own previous scripts.
Sharc
17th January 2023, 00:05
When using --fake-interlaced you should also include --pic-struct for BD compliance.
I am not sure whether --pic-struct gets inserted by default, but adding it explicitly doesn't do any harm.
In the past (years ago) tsMuxer did not support any of the --pulldown options, but this may have changed with newer releases.
Edit:
The current tsMuxer seems to support pulldown 32, as far as I can tell.
MaximRecoil
17th January 2023, 00:54
It was worth a try but it didn't work well. I encoded the video stream using the script that I posted in post #41 (after adding the missing arguments to make it work) and then I compiled it along with the original AC3 audio as a BD using DVDLogic EasyBD Lite 1.1. Then I copied the 00000.m2ts file from the BDMV\STREAM folder to a USB drive and tried it in my BD player. The interlacing artifacts were even worse than with my plain IVTC'd encodes.
There's a scene I've been using for reference where a car pulls into a driveway. There are prominent interlacing artifacts visible on the car's chrome trim. With my plain IVTC'd encodes, once the car and camera stop moving the interlacing artifacts mostly go away, but with this soft-telecined encode I just tried, the interlacing artifacts remain just as prominent when the car and camera are stationary as when they are moving.
When using --fake-interlaced you should also include --pic-struct for BD compliance.
I am not sure whether --pic-struct gets inserted by default, but adding it explicitly doesn't do any harm.
Do you think that would make a difference regarding the interlacing artifacts being worse?
poisondeathray
17th January 2023, 01:00
It shouldn't make a difference because --pic-struct is enabled by the --bluray-compat switch for pulldown , but it doesn't hurt as Sharc wrote
bluray compat will enable pic-struct for interlaced, fake-interalced, pulldown, and not for progressive. Because that required by BD specs.
MaximRecoil
17th January 2023, 01:20
It shouldn't make a difference because --pic-struct is enabled by the --bluray-compat switch for pulldown , but it doesn't hurt as Sharc wrote
Thanks. I guess there's nothing else to try other than making DVD-compliant encodes, but I don't want to do that, not even if I knew the ins and outs of MPEG-2 encoding. If it were just a few files I might look into it, but for over 100 total hours of video, with each file ending up ~three times as big for the same quality, that's too much.
Sharc
17th January 2023, 08:08
Thanks. I guess there's nothing else to try other than making DVD-compliant encodes, but I don't want to do that, not even if I knew the ins and outs of MPEG-2 encoding. If it were just a few files I might look into it, but for over 100 total hours of video, with each file ending up ~three times as big for the same quality, that's too much.
You could try once more without --fake-interlaced in the x264 commandline. Does your player react differently then?
I seem not to be able to reproduce your reported judder and/or residual combing issues here, with any of the propsed re-telecining solutions. But of course I don't have your player. I tested on PC and streaming to (modern) TV only.
Are you familiar with Avisynth (or VirtualDub2)? Did you analyze your files (source, IVTC'd, re-telecined variants) by stepping through the fields? Does the fields sequence behave as expected?
MaximRecoil
17th January 2023, 16:46
You could try once more without --fake-interlaced in the x264 commandline. Does your player react differently then?
Remove --fake-interlaced and keep --pulldown 32 in there? What would that do? Hard-telecine it?
I seem not to be able to reproduce your reported judder and/or residual combing issues here, with any of the propsed re-telecining solutions. But of course I don't have your player. I tested on PC and streaming to (modern) TV only.
Well, like I mentioned in a previous post, the judder with my re-telecined file turned out to be my BD player sometimes playing it wrong, probably because the script I used to encode it resulted in it being identified as progressive video. Whenever the player randomly decided to play it correctly there was no judder, it looked exactly the same as my plain IVTC'd files.
The prominent interlacing artifacts that all of my encodes have had so far are player-dependent too, so I wouldn't expect anyone to be able to reproduce it unless they have the same BD player that I have (Sony BDP-S480) or one with the same hardware and firmware. As I mentioned, my WD TV Live hardware player doesn't produce the prominent interlacing artifacts when playing my encodes.
Furthermore, even if you had the same BD player that I do, you'd also need a 15 kHz CRT TV, because digital TVs operate completely differently. Even if you had a digital TV that can accept a 15 kHz analog video signal (i.e., one that has a composite input jack as many of them do), the results would still be totally different, because a digital TV has to buffer, process, scale a 480i signal into something it can not only display, but display full screen. On the other hand, an analog video signal directly drives the electron guns in a CRT in real-time, which is why they have no display lag, which is what makes them preferable for playing classic video games, particularly among "speed runners" who rely on a bunch of "frame perfect" tricks to get the fastest times.
Are you familiar with Avisynth (or VirtualDub2)? Did you analyze your files (source, IVTC'd, re-telecined variants) by stepping through the fields? Does the fields sequence behave as expected?
Yes to all three questions. The source and my re-telecined encodes have the same pattern: 3 progressive frames followed by 2 interlaced fields, followed by 3 progressive frames, followed by 2 interlaced fields, and so on. My IVTC'd encodes are all progressive frames, as you'd expect. As for my most recent encode, which I'll refer to as the "fake-interlaced" one, which is also the one that has the worst interlacing artifacts on my BD player / TV, I'm only seeing progressive frames in that one when stepping through it in VirtualDub.
By the way, you can also use the original VirtualDub for that (there's an FFmpeg-based plug-in that allows you to choose "FFmpeg Supported Files" in the "Files of type" drop-down menu in the "Open video file" dialog box). In my experience, it's very stable too, unlike VirtualDub2, which I've had crash on me several times, but VirtualDub2 still has the advantage of being able to encode with modern codecs and containers.
Sharc
17th January 2023, 17:22
Remove --fake-interlaced and keep --pulldown 32 in there? What would that do? Hard-telecine it?
It's a flag to fool the player and satisfy the BluRay standard AFAIK. x264 will encode the video as progressive, and MediaInfo will report the stream as progressive but report it in the encoding details as interlaced=fake. The video is still soft-telecined by --pulldown 32. I thought it may have an impact how your playback sceanrio deals with it.
Well, like I mentioned in a previous post, the judder with my re-telecined file turned out to be my BD player sometimes playing it wrong, probably because the script I used to encode it resulted in it being identified as progressive video. Whenever the player randomly decided to play it correctly there was no judder, it looked exactly the same as my plain IVTC'd files.
Strange behavior. Therefore my desperate proposal with enabling/disabling the --fake-interlace (and other interlace specific settings as per previous scripts).
The prominent interlacing artifacts that all of my encodes have had so far are player-dependent too, so I wouldn't expect anyone to be able to reproduce it unless they have the same BD player that I have (Sony BDP-S480) or one with the same hardware and firmware. As I mentioned, my WD TV Live hardware player doesn't produce the prominent interlacing artifacts when playing my encodes.
Furthermore, even if you had the same BD player that I do, you'd also need a 15 kHz CRT TV, ....
Agree.
Yes to all three questions. The source and my re-telecined encodes have the same pattern: 3 progressive frames followed by 2 interlaced fields, followed by 3 progressive frames, followed by 2 interlaced fields, and so on. My IVTC'd encodes are all progressive frames, as you'd expect.
ok, you probably mean ... 3 progressive frames followed by 2 interlaced (combed) frames ...
As for my most recent encode, which I'll refer to as the "fake-interlaced" one, which is also the one that has the worst interlacing artifacts on my BD player / TV, I'm only seeing progressive frames in that one when stepping through it in VirtualDub.
How do you watch or remux the output.264 video file which comes out of the piped commandline? Does the progressive video you see in VirtualDub play at 23.976fps, like the IVTC'd variant? When you watch the frames of the output.264 you will see the 2:3 pattern, similar as for hard-telecine. And the duration of the video remains always the same (which will keep audio and video in sync). So the soft-pulldown seems to work..... at least here.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.