View Full Version : Interlaced video incorrectly flagged as progressive -fix without re-encoding?
DragonQ
2nd January 2025, 11:55
I have a 1080i/25 H.264 video that is incorrectly marked as 1080p/25 so no media players deinterlace it properly and it has combing artifacts all over the place. I have tried using MKVToolnix to edit the "video field order" and "video interlaced flag" headers but it makes no difference, it still plays back at 25 fps without any deinterlacing (as if the frames are still being "read" as progressive).
I have edited MPEG2 interlaced flags using Restream in the past with great success, but cannot find an equivalent for editing H.264 flags without re-encoding. Does such a tool exist?
EDIT: After playing with the file a lot I get the impression the original encode is just fubar. Sample is here (https://dragonq.uk/files/video/broken.mkv).
I'd like to try to force-deinterlace it during a re-encode but I can't even figure out how to get that working properly for a file with incorrect flags etc. I've tried a few things like these but it doesn't look deinterlaced at all:
ffmpeg.exe -i G:\sample.mkv -c:a copy -vf "yadif=1" -r 50 -c:v libx264 -preset slow -crf 23 -x264opts tff=1 G:\ffmpeg_tff.mkv
ffmpeg.exe -i G:\sample.mkv -c:a copy -vf "yadif=1, setfield=tff" -r 50 -c:v libx264 -preset slow -crf 23 G:\ffmpeg_tff_noopts.mkv
Z2697
2nd January 2025, 13:14
It's more (much more) than just incorrect flag
DragonQ
2nd January 2025, 13:57
Yeah I get that impression the more I play with it. Doesn't seem fixable, sadly.
Z2697
2nd January 2025, 21:40
It's low-res interlaced video scaled without "interlacing awareness" and while this kind of process can be somewhat reversible, I'm not sure how this one does.
FranceBB
4th January 2025, 21:57
Yeah, this is a 1440x1080 upscale of the original 720x576 25i PAL version but whoever did that screwed up the fields spectacularly as it resized it without deinterlacing the source first.
I tried to use DeBilinearResizeMT() to go back to the original version and deinterlace, but I can't seem to be able to make the fields match unfortunately.
The only thing you could do at this point is blur vertically to blend the upscaled fields together before downscaling back to SD.
Unfortunately this means that you'll have to live with the worst of the two evils of interlacing: basically you're gonna stick with 25fps (half temporal resolution) and you won't get the benefit of using the other fields so you'll also have half the vertical resolution, but hey, at least you won't see the interlacing artifacts in between which are far more annoying.
This is not the only issue that this file has, in fact as you can see in the following succession of frames, there are also artifacts before a scene change:
https://i.imgur.com/N3xwxlq.png
https://i.imgur.com/SWDOHae.png
https://i.imgur.com/mVkp0vs.png
to top it all up, luma is out of range as the various lights across the studio exceed 0.7V (i.e they go above 235 in the 8bit limited tv range) and there are also black elements that go below 16 in the non valid territory:
https://i.imgur.com/MrhZh7a.png
Given that we're dealing with a screw up and that there aren't many details anyway, we might as well just go big on this one and take out all the artifacts (including the grain) at the expense of nuking the few high frequency details we had left. The final script would therefore look like this:
#Indexing
FFMpegSource2("D:\broken.mkv", atrack=-1)
#Blur vertically to blend fields together
Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58)
Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58)
Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58)
Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58).Blur(0.0, 1.58)
#Fixing out of range values
Levels(0, 1, 255, 16, 235, coring=false)
Limiter(min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
#Crop inactive lines
Crop(14, 14, -14, -14)
#Downscale to original resolution
SinPowerResize(720, 576)
#Antialiasing
maa2(mask=1, chroma=true, ss=2.0, aa=70, show=0)
#Temporal Degrain
super = MSuper(pel=2, sharp=1)
bv1 = MAnalyse(super, isb = true, delta = 1, overlap=4)
fv1 = MAnalyse(super, isb = false, delta = 1, overlap=4)
bv2 = MAnalyse(super, isb = true, delta = 2, overlap=4)
fv2 = MAnalyse(super, isb = false, delta = 2, overlap=4)
MDegrain2(super,bv1,fv1,bv2,fv2,thSADC=800, thSAD=800)
#Spatial Denoise
dfttest(sigma=64, tbsize=1, lsb_in=false, lsb=false, Y=true, U=true, V=true, opt=0, dither=0)
Yes, granted, the result doesn't look great, but then again considering what we started from I'd say that it's an acceptable compromise and at least it's artifacts free.
https://i.imgur.com/5lpdlFx.png
https://i.imgur.com/fQJOUdP.png
https://i.imgur.com/JqFDnBz.png
Here's a link to the final encode: https://we.tl/t-fUaOXIWTUW
(link valid for 3 days)
it was produced using:
x264.exe "D:\broken.mkv.avs" --crf 18 --preset medium --profile High --level 4.1 --deblock -1:-1 --overscan show --sar 16:15 --colormatrix bt470bg --range tv --log-level info --thread-input --opencl --transfer bt470bg --colorprim bt470bg --videoformat component --nal-hrd vbr --vbv-maxrate 25000 --vbv-bufsize 25000 --output "I:\temp\raw_video.h264"
ffmpeg.exe -i "D:\broken.mkv.avs" -vn -sn -af loudnorm=I=-24:LRA=12:tp=-2 -c:a aac -b:a 550k -ar 48000 -y "I:\temp\audio.aac"
MP4Box.exe -add "I:\temp\raw_video.h264" -add "I:\temp\audio.aac" "I:\temp\final_output.mp4"
pause
DragonQ
4th January 2025, 22:23
Here's a link to the final encode: https://we.tl/t-fUaOXIWTUW
(link valid for 3 days)
it was produced using:
Thanks so much for the effort. I suspect sticking with the DVD version (576i/25) is just a better overall solution for now, at least we get a full 50 fps from it after deinterlacing properly. Here's the same 20s sample from the DVD. (https://dragonq.uk/files/video/sd.mkv)
The source is supposedly Amazon Prime - it's a joke that they upscaled it without actually deinterlacing it first and also at 25 fps. Amateurish! Especially given the Christmas special episode of this show was upscaled to 1080p/50 last week by the BBC who did a fantastic job!
FranceBB
5th January 2025, 00:12
sticking with the DVD version (576i/25) is just a better overall solution for now
Yeah, the DVD is definitely better.
The source is supposedly Amazon Prime
Ouch. If the source was delivered correctly and it was a supply chain error (i.e Amazon screwed up), then I'm sure someone at Amazon will probably get scolded by Ben (he reads this forum frequently).
it's a joke that they upscaled it without actually deinterlacing it first and also at 25 fps. Amateurish!
I think that nowadays most of the contents received are encoded automatically, packaged and published to the CDN without anyone looking at them, but I might be wrong. I don't work for them, so I can't tell this for sure, but this is kinda the feeling I get from Prime.
the Christmas special episode of this show was upscaled to 1080p/50 last week by the BBC who did a fantastic job!
Of course they did, I know people like Andrew Dunne and Philip de Nier who work there and they 100% care. Most contents get a full manual qc as well, while less important titles are either QCed at random timecodes or by exception if some issue is detected by the automatic checks (black frames, freeze, silence etc).
Z2697
5th January 2025, 21:08
Is the "broken.mkv" source deinterlaced (at this fake 1080p resolution)?
There're some very subtle artifacts that feel like "1 pixel high" (in fake 1080p).
I suspect it was deinterlaced, or scaled again with interlacing aware filter, after being incorrectly upscaled to 1080p or something.
Given the encoding settings that "feels industrial" (what am I saying LOL) this is most likely "authentic", directly out of streaming service, no process is done after.
DragonQ
5th January 2025, 23:43
Is the "broken.mkv" source deinterlaced (at this fake 1080p resolution)?
There're some very subtle artifacts that feel like "1 pixel high" (in fake 1080p).
I suspect it was deinterlaced, or scaled again with interlacing aware filter, after being incorrectly upscaled to 1080p or something.
Given the encoding settings that "feels industrial" (what am I saying LOL) this is most likely "authentic", directly out of streaming service, no process is done after.
As far as I'm aware it's unaltered from the streaming source. The video has a fixed bitrate of 10 Mb/s.
benwaggoner
16th January 2025, 00:22
Ouch. If the source was delivered correctly and it was a supply chain error (i.e Amazon screwed up), then I'm sure someone at Amazon will probably get scolded by Ben (he reads this forum frequently).
Do we have a link to this on Amazon so I can take a look?
This is a catastrophic example of bad preprocessing! It's almost like a comic example of how to do everything wrong.
I can't think of a way our systems could do this by accident. Of course if we get provided a messed up source file, there's only so much we can do about it. If the vendor doesn't send a fixed source, it's either let people watch it in bad quality or not be able to watch it at all.
If it is something we've messed up, I want to ensure that we don't do that again!
DragonQ
16th January 2025, 00:42
Do we have a link to this on Amazon so I can take a look?
This is a catastrophic example of bad preprocessing! It's almost like a comic example of how to do everything wrong.
I can't think of a way our systems could do this by accident. Of course if we get provided a messed up source file, there's only so much we can do about it. If the vendor doesn't send a fixed source, it's either let people watch it in bad quality or not be able to watch it at all.
If it is something we've messed up, I want to ensure that we don't do that again!
https://www.amazon.co.uk/Knowing-Me-You-Season/dp/B00ET128ME
Only seems to be available in SD. I'm sure there was an HD option when I checked it a few weeks back but either it's been pulled or I'm misremembering. The file definitely says Prime was the source though, unless that's a lie. The only streaming service that supposedly has it in HD currently is ITVX (can't verify without a premium account).
benwaggoner
16th January 2025, 17:57
https://www.amazon.co.uk/Knowing-Me-You-Season/dp/B00ET128ME
Only seems to be available in SD. I'm sure there was an HD option when I checked it a few weeks back but either it's been pulled or I'm misremembering. The file definitely says Prime was the source though, unless that's a lie. The only streaming service that supposedly has it in HD currently is ITVX (can't verify without a premium account).
Oh, this is actual content I've heard of! I can't easily watch UK content from the USA, but I'll have someone take a look.
1995 BBC production would presumably be 4:3 720x576i25. Or maybe 704?
Where do you see it saying Prime Video is the source? I see Studio listed as "BBC Worldwide."
That another vendor had it in HD suggests BBC may have provided a remaster.
Emulgator
16th January 2025, 19:06
There is good detail in broken.mkv, I was tempted too to guess at "worth a HD master"
DragonQ
16th January 2025, 22:31
Oh, this is actual content I've heard of! I can't easily watch UK content from the USA, but I'll have someone take a look.
1995 BBC production would presumably be 4:3 720x576i25. Or maybe 704?
Where do you see it saying Prime Video is the source? I see Studio listed as "BBC Worldwide."
That another vendor had it in HD suggests BBC may have provided a remaster.
The filename but as I said that could just be wrong. Maybe it's from ITVX. BBC may have upscaled it themselves before handing it over to whoever provided the stream but given their remaster of the Christmas special episode was excellent, I highly doubt their part of the processing chain caused the issues.
Anyway, I hope they show the main series again at some point because then it'll be available on iPlayer in upscaled glory.
ReinerSchweinlin
19th January 2025, 16:41
A few years ago, I also had the issue of backed in interlace-artefacts that have been scaled up and totally messed everyhting up...
back then, after hours of searching the internet, I found a blogpost of a video-editor who had a solution for this (not perfect, but pretty good)... Sadly, i lost the link and was never able to find it again...
I remember he tried to reverse the upscaling in order to get to the "original" resolution and then went into seperating the fields, doing some clever motion based edge cleaning, threw the fields back together, flagged them as interlaced and then used QTGMC on it... At least thats what I remember, it was much more fine tuned probably....
anybody happen to remember this blogpost ?
FranceBB
20th January 2025, 23:55
anybody happen to remember this blogpost ?
I don't, but I know what you're talking about and as a matter of fact that's exactly what I've been trying to do, basically find the kernel used to upscale (generally a simple Bilinear or Bicubic), reverse it (i.e DeBilinearResize(), DeBicubicResize() etc) and then, once you got back to the original you can bob-deinterlace it. I tried to go back to 720x576 and play around with similar resolutions, but I couldn't really get anything sensible out of it, which is why I reverted to the brute-force approach of blurring vertically to make the fields go away. I gotta say, though, that I've come across many screw ups in my life and I've only really managed to invert the kernel and deinterlace twice as all the other times that approach failed (but the two times in which it worked it definitely saved the content).
ReinerSchweinlin
21st January 2025, 10:45
I don't, but I know what you're talking about and as a matter of fact that's exactly what I've been trying to do, basically find the kernel used to upscale (generally a simple Bilinear or Bicubic), reverse it (i.e DeBilinearResize(), DeBicubicResize() etc) and then, once you got back to the original you can bob-deinterlace it. I tried to go back to 720x576 and play around with similar resolutions, but I couldn't really get anything sensible out of it, which is why I reverted to the brute-force approach of blurring vertically to make the fields go away. I gotta say, though, that I've come across many screw ups in my life and I've only really managed to invert the kernel and deinterlace twice as all the other times that approach failed (but the two times in which it worked it definitely saved the content).
Interesting :)
When I tried to recreate the process, the hardesrt thing to do is finding the exact downsize method in order to get the original interlace lines as uniform as possible. When originally they were clear distinged lines from the seperate fields, they got smoodged together obviously through the upscaling and then downscaling again. Sometimes some sharpening did improve it...
Too bad I can´t find the blogpost anymore, he had some clever tricks which produced quite good results.
ReinerSchweinlin
21st January 2025, 11:41
I just took a quick look at the first linked file broken.mkv.
Assuming it was originally PAL, I failed to resize it without moirée artefacts in the interlaced lines ... So I just went for 50% downscale, resulting in 540 lines with point resize :) seperated the fields - and this gave me a not so bad result... Maybe someone had an NTSC intermediate (screwing up even more...) ?
Here is a zoom of one field in a motion szene... The interlaced lines seme to be gone - blurring is from the motion...
https://forum.doom9.org/attachment.php?attachmentid=18815&stc=1&d=1737453899
Thrown into QTGMC (used hybrid), looks like this
https://forum.doom9.org/attachment.php?attachmentid=18816&stc=1&d=1737454289
The same frame as in FranceBBs example above:
https://forum.doom9.org/attachment.php?attachmentid=18818&stc=1&d=1737454576
by no means perfect.....
benwaggoner
22nd January 2025, 17:23
As for the source of the video, I don’t think it came from Amazon. If someone can demonstrate that it did, I’ll investigate further, but it doesn’t seem to match anything of ours.
FranceBB
22nd January 2025, 18:02
As for the source of the video, I don’t think it came from Amazon. If someone can demonstrate that it did, I’ll investigate further, but it doesn’t seem to match anything of ours.
The only other official source that seems to be offering it is ITV via Britbox (i.e ITXV) (https://www.itv.com/watch/knowing-me-knowing-you-with-alan-partridge/10a2007/10a2007a0005) but I don't have a premium so I can't actually see whether it's them who screwed it up.
On Amazon Prime it seems to be available only in SD (https://www.amazon.co.uk/Knowing-Me-You-Season/dp/B00ET128ME) and everything looks fine.
On the BBC iPlayer there's only 1 episode (https://www.bbc.co.uk/iplayer/episodes/b006t8bp/knowing-me-knowing-you-with-alan-partridge) (the Christmas special DragonQ was talking about), it's bob-deinterlaced to 50p and upscaled to FULL HD in 1.33 PB with the black borders on the left and right (albeit iPlayer only offers up to HD if you're on a PC using a browser) and it looks fine, considering that it's something that aired in December 1995.
(screenshot cropped and resized)
https://i.imgur.com/JHKdaoF.png
https://i.imgur.com/zHuB2Hk.png
https://i.imgur.com/K8rQgC7.png
https://i.imgur.com/YPJqwpe.png
Filtering looks good and they got rid of pretty much all artifacts. You can still see a bit of aliasing and sometimes ringing on the edges when the presenter moves rapidly, probably because they used mostly temporal filters which tend to lose the references when there's motion blur in the movement. Overall, the quality is great and they showed much more care than many other companies would have put on such an old show, especially considering that it probably comes from old BetaCAM tapes. One can say many things about the BBC, but I personally know some of the folks who work there (and contribute to open source stuff like the BBC BMX mxf muxer) and I can tell you that they do genuinely care.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.