ffmpeg: how to create an interlaced h.264 video?

1

I would like to convert a high quality non interlaced input video into a less quality but wider distributable H.264/MP4 format. The output should have some constraints - in particular: it should be interlaced!

I tried the following command, where mandelbrot is a synonymous for the high quality input:

ffmpeg -hide_banner \
    -t 10 -y \
    -f lavfi \
    -i anullsrc=r=48k:cl=stereo \
    -f lavfi \
    -i mandelbrot=r=50:size=1920x1080 \
    -vf 'interlace=scan=tff:lowpass=complex,format=yuv420p' \
    -codec:a aac \
    -b:a 128k \
    -aac_coder twoloop \
    -codec:v libx264 \
    -preset veryfast \
    -tune animation \
    -profile:v high \
    -crf 35 \
    -level 5.2 \
    -x264opts interlaced=1 \
    -shortest \
    mandelbrot.mp4

My ffmpeg is ffmpeg version 3.4.2-2.

However, I am not sure that the command line is correct.

  • libx264 does not detect an interlaced input by itself. I have to insert -x264opts interlaced=1.
  • Other faq's tell something about -flags +ilme+ildct...

Can you confirm my parameters? Thank you very much.

Thomas R.

Posted 2018-07-30T10:15:08.690

Reputation: 31

1"it should be interlaced" ... why? Interlacing is a hangover from the days of CRTs, it has no place in the modern world and looks really bad. – Attie – 2018-07-30T13:19:18.370

Generally you are right... I recommend progressive in the digital world to everyone... But take this special case as a challenge... ;-) – Thomas R. – 2018-07-30T13:58:46.007

So why is interlacing needed in your case? Just curious… – slhck – 2018-07-30T14:36:37.837

Think of having a few hardware video players. Actually some of them have technical specification. Then you brew a video file exactly as described in those manuals. But the player refuse to play back. That is why I would like to generate both progressive and interlaced files... – Thomas R. – 2018-07-30T15:04:51.677

might be worth noting - I had some issues with generating interlaced mp4 files with ffmpeg and tried with many different parameters. Video worked correctly in a software player, but it appeared corrupt on air. I can't recall all specific details now, just saying - if that is for serious application you should test it on a real hardware, might happen you will need a proprietary encoder for ensuring compatibility. – Mikhail V – 2018-07-30T19:34:35.267

Answers

2

Finally I got excellent results with

ffmpeg \
 -y \
 -hide_banner \
 -i "${INPUT_FILE}" \
 \
 [... audio ...]\
 \
 -vf tinterlace=interleave_top,fieldorder=tff \
 -crf 28 \
 -preset placebo \
 [... more video ...]\
 -codec:v libx264 \
 \
 -f mp4 \
 -flags +ildct+ilme \
 [... more muxing ...]\
 \
 "${OUTPUT_FILE}"

Thomas R.

Posted 2018-07-30T10:15:08.690

Reputation: 31

1

x264 via ffmpeg can set interlaced mode in two ways:

1) via private param i.e. -x264opts (or -x264-params) interlaced=1

2) or via libavcodec generic flag, -flags +ildct

Gyan

Posted 2018-07-30T10:15:08.690

Reputation: 21 016

1So if I want to reduce encoder specific parameters, I should use ffmpeg -hide_banner -t 10 -y -f lavfi -i anullsrc=r=48k:cl=stereo -f lavfi -i mandelbrot=r=50:size=1920x1080 -vf 'interlace=scan=tff:lowpass=complex,format=yuv420p' -flags +ildct -codec:a aac -b:a 128k -aac_coder twoloop -codec:v libx264 -preset veryfast -tune animation -profile:v high -crf 35 -level 5.2 -shortest mandelbrot.mp4? – Thomas R. – 2018-07-30T14:21:41.233

1That looks right. – Gyan – 2018-07-30T14:52:33.387

1Thank you very much. Because of I am a newbie, my vote is not public... ;-( – Thomas R. – 2018-07-30T15:31:28.143