Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th December 2022, 16:43   #1  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Is there any good way to IVTC h.264 video in FFmpeg?

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.
MaximRecoil is offline   Reply With Quote
Old 24th December 2022, 17:20   #2  |  Link
microchip8
ffx264/ffhevc author
 
microchip8's Avatar
 
Join Date: May 2007
Location: /dev/video0
Posts: 1,844
https://ffmpeg.org/ffmpeg-all.html#fieldmatch
__________________
ffx264 || ffhevc || ffxvid || microenc
microchip8 is offline   Reply With Quote
Old 25th December 2022, 02:07   #3  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Quote:
Originally Posted by microchip8 View Post
That's what I tried from that post I linked to. The first one I tried was:

Code:
-vf fieldmatch,yadif=deint=interlaced,decimate
The results were bad. Then I tried:

Code:
-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:



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.
MaximRecoil is offline   Reply With Quote
Old 25th December 2022, 03:01   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,374
Quote:
Originally Posted by MaximRecoil View Post
That's what I tried from that post I linked to. The first one I tried was:

Code:
-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

Code:
-vf fps=30000/1001 ,fieldmatch,yadif=deint=interlaced,decimate
poisondeathray is offline   Reply With Quote
Old 25th December 2022, 05:05   #5  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Quote:
Originally Posted by poisondeathray View Post
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.

Quote:
Sometimes the source timestamps are not perfect and it can mess with various ffmpeg operations

Try adding -vf fps=30000/1001

Code:
-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:



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.

Last edited by MaximRecoil; 25th December 2022 at 05:10.
MaximRecoil is offline   Reply With Quote
Old 25th December 2022, 12:53   #6  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
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.
Sharc is offline   Reply With Quote
Old 25th December 2022, 13:33   #7  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Quote:
Originally Posted by Sharc View Post
The suggested ffmpeg commandline works perfectly here for IVTC.
Is your source hard- or soft telecined?
Hard telecined.

Quote:
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:

Code:
-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:

Quote:
-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.

Last edited by MaximRecoil; 25th December 2022 at 13:40.
MaximRecoil is offline   Reply With Quote
Old 25th December 2022, 13:42   #8  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
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.

Last edited by Sharc; 25th December 2022 at 13:45.
Sharc is offline   Reply With Quote
Old 26th December 2022, 18:24   #9  |  Link
Asmodian
Registered User
 
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
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.
__________________
madVR options explained
Asmodian is offline   Reply With Quote
Old 27th December 2022, 08:55   #10  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Quote:
Originally Posted by Asmodian View Post
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-...ch/141105.html

... and it says:

Quote:
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.
MaximRecoil is offline   Reply With Quote
Old 27th December 2022, 17:07   #11  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,374
Quote:
Originally Posted by MaximRecoil View Post

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.
poisondeathray is offline   Reply With Quote
Old 27th December 2022, 19:12   #12  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
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.

Last edited by MaximRecoil; 27th December 2022 at 19:20.
MaximRecoil is offline   Reply With Quote
Old 28th December 2022, 02:25   #13  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
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:



So I did a binary file comparison:



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.
MaximRecoil is offline   Reply With Quote
Old 28th December 2022, 09:20   #14  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,277
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
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 28th December 2022, 10:45   #15  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Quote:
Originally Posted by Selur View Post
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
MaximRecoil is offline   Reply With Quote
Old 28th December 2022, 13:49   #16  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
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.
Sharc is offline   Reply With Quote
Old 30th December 2022, 18:30   #17  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,277
@MaxinRecoil: thanks
@Shar: good to know
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 15th January 2023, 04:44   #18  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
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)?

Code:
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

Last edited by MaximRecoil; 15th January 2023 at 04:46.
MaximRecoil is offline   Reply With Quote
Old 15th January 2023, 09:40   #19  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
Quote:
Would it be possible to inverse telecine, crop and resize, and then re-telecine in the same script?
Add telecine to your filter, like:
Code:
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:
Code:
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

Last edited by Sharc; 15th January 2023 at 10:13.
Sharc is offline   Reply With Quote
Old 15th January 2023, 15:52   #20  |  Link
MaximRecoil
Registered User
 
Join Date: Feb 2004
Posts: 192
Quote:
Originally Posted by Sharc View Post
Add telecine to your filter, like:
Thanks. I don't need to specify any parameters for the telecine filter?

Quote:
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.

Quote:
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.

Last edited by MaximRecoil; 15th January 2023 at 16:11.
MaximRecoil is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:20.


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