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

18,729

Solution 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

Solution 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}"
Share:
18,729

Related videos on Youtube

Thomas R.
Author by

Thomas R.

Updated on September 18, 2022

Comments

  • Thomas R.
    Thomas R. over 1 year

    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.

    • Attie
      Attie almost 6 years
      "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.
    • Thomas R.
      Thomas R. almost 6 years
      Generally you are right... I recommend progressive in the digital world to everyone... But take this special case as a challenge... ;-)
    • slhck
      slhck almost 6 years
      So why is interlacing needed in your case? Just curious…
    • Thomas R.
      Thomas R. almost 6 years
      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...
    • Mikhail V
      Mikhail V almost 6 years
      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.
    • jarno
      jarno about 4 years
      @Attie One case is that your input video is interlaced and you want to compress it further.
  • Thomas R.
    Thomas R. almost 6 years
    So 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?
  • Gyan
    Gyan almost 6 years
    That looks right.
  • Thomas R.
    Thomas R. almost 6 years
    Thank you very much. Because of I am a newbie, my vote is not public... ;-(