Search code examples
python-3.xffmpegffmpeg-python

Creating interlaced videos with ffmpeg-python


I'm probably doing something wrong and/or there is something I don't understand but ...

I have a progressive video (here failing1.mp4). Doing a mediainfo on that video confirms that "Scan type" is progressive.

If I use the following code to get the same video interlaced:

import ffmpeg

ffmpeg.input("/home/dbr/Videos/failing1.mp4") \
    .filter("interlace") \
    .output(
        "output_via_filter.mp4",
        vcodec="libx264",
        preset="ultrafast"
    ) \
    .run(overwrite_output=True)

using mpv, vlc or any decent video file player, I can see that the generated file (output_via_filter.mp4) is indeed interlaced (I see the interlacing "artifacts"). However, running mediainfo output_via_filter.mp4 tells me that the "Scan type" is progressive.

If I use that code instead for the same input file (another attempt to get an interlaced file, without using the "interlace" filter, based on my searches on the intarweb):

ffmpeg.input("/home/dbr/Videos/failing1.mp4") \
    .output(
        "output_via_interlace.mp4",
        vcodec="libx264",
        preset="ultrafast"
    ) \
    .global_args("-vf", "tinterlace=interleave_top,fieldorder=tff", "-flags", "+ilme+ildct") \
    .run(overwrite_output=True)

The generated file (output_via_interlace.mp4) is not interlaced and mediainfo output_via_interlace.mp4 confirms that "Scan type" is progressive.

Yet, using ffmpeg directly on the command line with the same arguments:

ffmpeg -i f/home/dbr/Videos/failing1.mp4 -vf tinterlace=interleave_top,fieldorder=tff -flags +ilme+ildct  output.mp4

gives me:

mediainfo output.mp4 | grep Scan
Scan type                                : MBAFF
Scan type, store method                  : Interleaved fields
Scan order                               : Top Field First

I guess my question really is: How can I generate an interlaced video file using ffmpeg-python? A small example would be nice.


Solution

  • Answering my own question. The following ffmpeg-python code works as expected:

    ffmpeg.input("/home/dbr/Videos/failing1.mp4") \
        .filter("tinterlace", "interleave_top") \
        .filter("fieldorder", "tff") \
        .output(
            "output_via_interlace.mp4",
            vcodec="libx264",
            preset="ultrafast",
            flags="+ilme+ildct"
        ) \
        .run(overwrite_output=True)