<p>The source is interlaced. To deinterlace it, you can use the <code>yadif</code> filter.</p>

<p>To use it with the default values:</p>

<pre><code>ffmpeg -i input.m2ts -vf yadif=parity=auto output.mkv
</code></pre>

CC BY-SA 3.0
2016-12-24T10:34:20.927Z
But when watching the input file in VLC, the interlacing is not visible, when watching the output, it looks terrible. Could VLC be automatically deinterlacing the m2ts file but not the mkv produced by ffmpeg? Or why else would the results look like that?
Jan Christian Grünhage
CC BY-SA 3.0
2016-12-24T10:39:19.460Z
Since source contains interlaced field order, VLC can display it with  correct deinterlacing. When converting without a filter, ffmpeg will mark the output as progressive, but it won't actually have been deinterlaced.
Gyan
CC BY-SA 4.0
2018-08-28T03:54:32.927Z
@Gyan, that comment should be in the answer, it provides a good explanation of what's going on
stib
CC BY-SA 4.0
2019-11-09T11:41:26.020Z
I get Unable to find a suitable output format for 'yadif=parity=auto' when trying this.
landed
CC BY-SA 4.0
2019-11-09T12:07:58.757Z
That's a syntax error - double check all arguments and `-` in front of option names.
Gyan
CC BY-SA 3.0
2016-12-24T10:28:40.507Z
2016-12-24T10:28:40.507Z
Gyan
<p>You can try deinterlacing it at the decoding step with the following command, via the <code>CUVID</code> deinterlacer:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -hwaccel cuvid -c:v h264_cuvid -deint 2 -drop_second_field 1 \
-i input.m2ts -c:v hevc_nvenc -qp:v 19 -rc:v constqp \
-tune:v hq -preset:v p7 output.mkv
</code></pre>
<p>Or better still, the <code>yadif_cuda</code> filter, with <code>NVDEC</code> in use:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -threads 1 -hwaccel nvdec -hwaccel_output_format cuda -i input.m2ts \
-vf 'yadif_cuda=0:-1:0' -c:v hevc_nvenc \
-qp:v 19 -rc:v constqp -tune:v hq -preset:v p7 \
-b:v 0 output.mkv
</code></pre>
<p>Note that NVDEC is a true HWAccel, unlike CUVID.
Where possible, migrate from CUVID to NVDEC.</p>
<p>Or keep interlacing with the next command:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -i input.m2ts -flags +ildct -c:v hevc_nvenc -preset:v p7 \
-tune:v hq -rc:v constqp -b:v 0 -qp:v 19 output.mkv
</code></pre>
<p><strong>Note:</strong></p>
<ol>
<li><p>The changes above to the encoder, regarding presets, the tune value and selected rate control mode are required as the <code>ffnvcodec</code> package  and FFmpeg's NVENC wrapper implementations require valid values to be set. Failure to do so will result in an error: &quot;The specified rc mode is deprecated. Use <code>-rc constqp/cbr/vbr</code>, <code>-tune</code> and <code>-multipass</code> instead&quot; and your transcode will  fail.</p>
</li>
<li><p>Interlaced encoding for NVENC is <a href="https://devtalk.nvidia.com/default/topic/1038493/video-codec-and-optical-flow-sdk/details-about-nvenc-in-turing-/post/5294777/#5294777" rel="nofollow noreferrer">not supported on Turing and above</a>. To encode interlaced content as-is, use a Pascal GPU or lower.</p>
</li>
</ol>

CC BY-SA 4.0
2017-05-03T12:26:03.623Z
2021-06-07T12:42:13.150Z
2021-06-07T12:42:13.150Z
Ivan Kolesnikov
<p>I have a m2ts video file that contains a h264 video stream and an ac3 audio stream. The quality is not the best, but it is okay, but converting it with ffmpeg without any additional options makes the video interlaced and very ugly with that:</p>

<pre><code>ffmpeg -i input.m2ts output.mkv
</code></pre>

<p>Output:</p>

<pre><code>ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.2.1 (GCC) 20160916 (Red Hat 6.2.1-2)
  configuration: --arch=x86_64 --bindir=/usr/bin --datadir=/usr/share/ffmpeg --disable-debug --disable-static --disable-stripping --enable-avfilter --enable-avresample --enable-bzlib --enable-cuda --enable-cuvid --enable-libnpp --enable-doc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gpl --enable-iconv --enable-libass --enable-libbluray --enable-libcdio --enable-libdc1394 --enable-libebur128 --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libkvazaar --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape --enable-libxvid --enable-libzvbi --enable-lzma --enable-nonfree --enable-openal --enable-opencl --enable-nvenc --enable-opengl --enable-postproc --enable-pthreads --enable-sdl2 --enable-shared --enable-version3 --enable-x11grab --enable-xlib --enable-zlib --extra-cflags='-I/usr/include/nvenc -I/usr/include/cuda' --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --prefix=/usr --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mpegts, from 'input.m2ts':
  Duration: 01:15:49.44, start: 0.984822, bitrate: 19636 kb/s
  Program 1 
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 384 kb/s
File 'output.mkv' already exists. Overwrite ? [y/N] y
[libx264 @ 0xf21240] using SAR=1/1
[libx264 @ 0xf21240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xf21240] profile High, level 4.0
[libx264 @ 0xf21240] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'output.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, stereo, fltp
    Metadata:
      encoder         : Lavc57.64.101 libvorbis
Stream mapping:
  Stream #0:0 -&gt; #0:0 (h264 (native) -&gt; h264 (libx264))
  Stream #0:1 -&gt; #0:1 (ac3 (native) -&gt; vorbis (libvorbis))
Press [q] to stop, [?] for help
</code></pre>

<p>Additional options, like presets and crf did not change that and I could not find anything on the Internet except that ffmpeg is supposed to always use progressive unless told otherwise. I also tried hardware transcoding on my GPU, which made the transcode much much faster, but the result was about the same, still heavily interlaced video.</p>

<pre><code>ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input.m2ts -c:v hevc_nvenc -preset slow output.mkv
</code></pre>

<p>Any idea what might be causing this and how to fix it? Adding <code>-deinterlace</code> helps with the interlacing, but makes the quality worse.</p>

CC BY-SA 3.0
2016-12-24T04:53:34.547Z
FFmpeg will not **create** interlacing unless told to do so. Show the full console output of your first command.
Gyan
CC BY-SA 3.0
2016-12-24T10:26:03.077Z
I added the output to the question.
Jan Christian Grünhage
<ffmpeg><encoding><mkv><nvenc>
How to stop ffmpeg from interlacing when converting from m2ts to mkv
Jan Christian Grünhage
# How to stop ffmpeg from interlacing when converting from m2ts to mkv

(Asked by: username_0 on 2016-12-23)

I have a m2ts video file that contains a h264 video stream and an ac3 audio stream. The quality is not the best, but it is okay, but converting it with ffmpeg without any additional options makes the video interlaced and very ugly with that:
ffmpeg -i input.m2ts output.mkv

Output:
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.2.1 (GCC) 20160916 (Red Hat 6.2.1-2)
  configuration: --arch=x86_64 --bindir=/usr/bin --datadir=/usr/share/ffmpeg --disable-debug --disable-static --disable-stripping --enable-avfilter --enable-avresample --enable-bzlib --enable-cuda --enable-cuvid --enable-libnpp --enable-doc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gpl --enable-iconv --enable-libass --enable-libbluray --enable-libcdio --enable-libdc1394 --enable-libebur128 --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libkvazaar --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape --enable-libxvid --enable-libzvbi --enable-lzma --enable-nonfree --enable-openal --enable-opencl --enable-nvenc --enable-opengl --enable-postproc --enable-pthreads --enable-sdl2 --enable-shared --enable-version3 --enable-x11grab --enable-xlib --enable-zlib --extra-cflags='-I/usr/include/nvenc -I/usr/include/cuda' --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --prefix=/usr --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mpegts, from 'input.m2ts':
  Duration: 01:15:49.44, start: 0.984822, bitrate: 19636 kb/s
  Program 1 
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 384 kb/s
File 'output.mkv' already exists. Overwrite ? [y/N] y
[libx264 @ 0xf21240] using SAR=1/1
[libx264 @ 0xf21240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xf21240] profile High, level 4.0
[libx264 @ 0xf21240] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'output.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, stereo, fltp
    Metadata:
      encoder         : Lavc57.64.101 libvorbis
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (ac3 (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help

Additional options, like presets and crf did not change that and I could not find anything on the Internet except that ffmpeg is supposed to always use progressive unless told otherwise. I also tried hardware transcoding on my GPU, which made the transcode much much faster, but the result was about the same, still heavily interlaced video.
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input.m2ts -c:v hevc_nvenc -preset slow output.mkv

Any idea what might be causing this and how to fix it? Adding -deinterlace helps with the interlacing, but makes the quality worse.

**Tags:** ffmpeg, encoding, mkv, nvenc

> **Comments:**
> **username_1**: FFmpeg will not **create** interlacing unless told to do so. Show the full console output of your first command.  
> **username_0**: I added the output to the question.  

---

## 2 answers

### Answer by username_1 on 2016-12-24. Score: 2 | Accepted answer

The source is interlaced. To deinterlace it, you can use the yadif filter.
To use it with the default values:
ffmpeg -i input.m2ts -vf yadif=parity=auto output.mkv

> **Comments:**
> **username_0**: But when watching the input file in VLC, the interlacing is not visible, when watching the output, it looks terrible. Could VLC be automatically deinterlacing the m2ts file but not the mkv produced by ffmpeg? Or why else would the results look like that?  
> **username_1**: Since source contains interlaced field order, VLC can display it with  correct deinterlacing. When converting without a filter, ffmpeg will mark the output as progressive, but it won't actually have been deinterlaced.  
> **username_2**: @username_1, that comment should be in the answer, it provides a good explanation of what's going on  
> **username_3**: I get Unable to find a suitable output format for 'yadif=parity=auto' when trying this.  
> **username_1**: That's a syntax error - double check all arguments and `-` in front of option names.  

---

### Answer by username_4 on 2017-05-03. Score: 1

You can try deinterlacing it at the decoding step with the following command, via the CUVID deinterlacer:
ffmpeg -hwaccel cuvid -c:v h264_cuvid -deint 2 -drop_second_field 1 \
-i input.m2ts -c:v hevc_nvenc -qp:v 19 -rc:v constqp \
-tune:v hq -preset:v p7 output.mkv

Or better still, the yadif_cuda filter, with NVDEC in use:
ffmpeg -threads 1 -hwaccel nvdec -hwaccel_output_format cuda -i input.m2ts \
-vf 'yadif_cuda=0:-1:0' -c:v hevc_nvenc \
-qp:v 19 -rc:v constqp -tune:v hq -preset:v p7 \
-b:v 0 output.mkv

Note that NVDEC is a true HWAccel, unlike CUVID.
Where possible, migrate from CUVID to NVDEC.
Or keep interlacing with the next command:
ffmpeg -i input.m2ts -flags +ildct -c:v hevc_nvenc -preset:v p7 \
-tune:v hq -rc:v constqp -b:v 0 -qp:v 19 output.mkv

Note:

The changes above to the encoder, regarding presets, the tune value and selected rate control mode are required as the ffnvcodec package  and FFmpeg's NVENC wrapper implementations require valid values to be set. Failure to do so will result in an error: "The specified rc mode is deprecated. Use -rc constqp/cbr/vbr, -tune and -multipass instead" and your transcode will  fail.

Interlaced encoding for NVENC is not supported on Turing and above. To encode interlaced content as-is, use a Pascal GPU or lower.


---

