This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

[HELP] Deinterlacing + Detelecining VFR (Star Trek: Voyager DVD Rips)
#6
Posting late as this is one of the top results and I've been trying to figure this out myself. I'm not trying to upscale but hopefully you can learn something from this. I have a flawless looking straight up encode.


 Problems

There are two main issues with encoding these DVDs:

1. The content is VFR,

A. encoding to CFR involves dropping or duplicating frames. Dropping down to 23.970 looks terrible and stuttery because you lose frames.
B. Because it's VFR, trying to apply CFR at all (Even adding too many frames) looks bad because the frame times are wrong. Where in the middle of the footage some frames are displayed for 41ms (23.976fps) and some are displayed for 33ms (29.97fps). To increase frames in CFR you'd need to encode into a framerate that divides exactly into both 29.97 and 23.976, even then you'll likely end up with some merged frames (blurry!). If you apply CFR the frame times are stretched to a consistent number for all frames which is why it looks jerky
C. Either way you go, CFR looks bad.

Do not reencode CFR! Keep the variable framerate or it looks awful.

2. The content is telecined

I played around with all kind of inverse telecine filters, almost all the examples online ultimately rely on a `decimate` filter, which drops frames and causes motion issues. However you do it, it will mess with the frame times.

While there may be a way to do this with decimate, ultimately it's not necessary.


Goals

It's worth considering what we want to achieve here. If you do a straight up 1:1 VFR encode without any detelecine filters the motion looks perfect but the telecined frames are jarring.

1. Remove telecine artifacts (deinterlacing the correct frames)
2. We can't deinterlace the progressive frames as that causes new artifacts
3. Keep VFR for the best looking motion

Solution

The solution is the following:

- Detect interlaced frames
- Deinterlace only those frames
- Keep VFR

While I'd played around with VapourSynth a lot, I actually had the best luck with straight up ffmpeg as it doesn't decouple the timecodes from the video making the process a lot tidier.

The follow filter chain in ffmpeg can solve this:

fieldmatch=mode=pc_n_ub:combmatch=full:combpel=70,nnedi=weights=/usr/lib/vapoursynth/nnedi3_weights.bin:deint=interlaced


`fieldmatch` identifies any deinterlaced frames and tags them as iterlaced for the deinterlace filter, the settings above worked for all my samples, I haven't noticed any jarring interlaced frames in playback.

`nnedi` is the deinterlace filter I'm using, specify the path to the weights.bin file. You can use `yadif` or another alternative, nnedi looks better but since it's only on certain frames you're unlikely to tell the difference here. `:deint=interlaced` is important so that only the frames identified by `fieldmatch` are deinterlaced.

I have also verified that this approach doesn't insert any extra frames, extracting a frame before/after a deinterlaced frame so all the frame times are perfect, only the interlaced frames are fixed

(You can extract a frame using
ffmpeg -i "file.mkv" -vf "select=eq(n\,60184)" -vframes 1 60184.png
where 60184 is the number of the frame given by fieldmatch in the output, try comparing the same frame from the source video and the result)

tl;dr here's a script that encodes every file in a directory using those filters, I'm encoding to AV1/Opus but choose your codecs.

#!/bin/sh
for FILE in *; do
  INFILE=$FILE
  OUTFILE="${FILE//mkv/av1\.mkv}"

  if [ ! -f "$OUTFILE" ]; then
        if [[ ${INFILE} != *".av1.mkv"* ]]; then
        ffmpeg  -i "$INFILE" \
            -vf "fieldmatch=mode=pc_n_ub:combmatch=full:combpel=70,nnedi=weights=/usr/lib/vapoursynth/nnedi3_weights.bin:deint=interlaced" \
            -ac 6 \
            -map_metadata 0 \
            -pix_fmt yuv420p10le \
            -c:v libsvtav1 -crf 24 -preset 3 -c:a libopus -b:a 384k -c:s copy \
            -map "0:v"  -map "0:a" -map "0:s"  \
            "$OUTFILE"
        fi
    fi
done



edit: If you want the output to be lossless so you can work on it, use `-c:a copy` to use the existing audio and `-c:v ffv1` be warned though that the file sizes will be huge.
Reply


Messages In This Thread
RE: Deinterlacing + Detelecining VFR (Star Trek: Voyager DVD Rips) - by TomB - 27.07.2023, 23:14

Forum Jump:


Users browsing this thread: 2 Guest(s)