[FFmpeg-user] Best way to scale interlaced video

Mark Himsley mark at mdsh.com
Thu Mar 6 20:23:51 CET 2014


Hi Massimo,

Sorry to be very late in replying:

On 25/02/2014 15:19, Massimo Battistel wrote:
> hello,
> I have to scale 16:9 interlaced 1080i video down to PAL 576i 4:3 with black
> bars.
> 
> This was attempt #1:
> 
> ffmpeg -i interlaced1080i.mp4 -vcodec rawvideo -vf
> scale=w=720:h=432:interl=1,pad=720:576:0:72 -acodec copy out.mp4
> 
> Easy and fast. But horizontal resolution was halved. It looks like every
> row was repeated 2 times. This is well noticeable especially on static
> areas of video. When image is moving it looks better.
> 
> Is this the normal behavior? How does interlaced aware scaling works?

Unfortunately it is what happens when you scale "effectively
progressive" video in an interlaced way.

When I say "effectively progressive", I mean any static parts of an
interlaced frame: If you have an interlaced recording of a completely
static image then you effectively have progressive video. If you scale
it down from HD to SD, as you're doing, in an interlaced way then the
scale has to interpret each field independently and you usually end up
with a much lower resolution than you expect.

What the BBC does, when possible (i.e. not when we're doing real-time
scaling in CPUs) is to de-interlace from 50 interlaced fields per second
to 50 progressive frames per second using the BBC designed w3fdif
de-interlacing filter, we scale the frames down in progressive mode,
then we re-interlace the 50 frames per second back to 50 fields per
second remembering to include the BBC designed low-pass filter.

So, using your scaling numbers, we'd effectively do:

-vf
w3fdif,scale=w=720:h=432:interl=0,pad=720:576:0:72,tinterlace=4:flags=vlpf


Now, I need to tell you that your scale from 1920x1080 down to 720x432
will leave your video about 2.5% wrong in aspect-ratio. That's because
you've fallen in to the usual trap of thinking that the 720 pixels
across an SD frame are all the "active" pixels. You should actually be
scaling the video down to 702x432 and padding that all back up to
720x576 to preserve the aspect ratio correctly. Unfortunately, padding 9
pixels each side of the 702 up to 720 is not possible with sub-sampled
chroma, so in the BBC we have calculated that we get much more accurate
scaling if we pad the source video up and then scale down rather than
scaling down and padding up. Therefore I suggest this is the correct
scale (within 0.06%) for HD down to 4:3 SD.

-vf
w3fdif,pad=1968:1440:24:180,scale=720:576:interl=0,tinterlace=4:flags=vlpf


Also, don't forget that HD will be in BT.709 colour space and you want
your SD to be in BT.601 colour space - so you'll need to change the
colour space too. This is the sort of command I'd be tending towards...


ffmpeg -i 1920x1080i25/1080i50\ Bars\ and\ Tone\ XDCAM.mov -vf
"w3fdif,pad=1968:1440:24:180,scale=720:576:interl=0:in_color_matrix=bt709:out_color_matrix=bt601,tinterlace=4:flags=vlpf"
-aspect 4:3 -r 25 -acodec copy -y ~/out.mov


Hope that helps.


> Attempt #2
> 
> ffmpeg -i interlaced1080i.mp4 -vcodec rawvideo -vf
> yadif=1:0,scale=w=720:h=432:interl=0,pad=720:576:0:72,tinterlace=4 -acodec
> copy out.mp4
> 
> Higher cpu/memory usage. Image quality is much better on static areas of
> video (I have the full resolution), while moving parts are a bit worse.
> 
> 
> Is it possbile to do a better scaling?
> Any help of link to doc is welcome.
> 
> 
> thanks,
> MB
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 


-- 
Mark Himsley


More information about the ffmpeg-user mailing list