lisamelton / other_video_transcoding

Other tools to transcode videos.
MIT License
544 stars 25 forks source link

Add extra options for deinterlacing #74

Open samhutchins opened 3 years ago

samhutchins commented 3 years ago

Interlacing is a tricky and complex subject. I think there are 2 main things we need to worry about when de-interlacing an input:

  1. How was the content captured?
  2. How was the content stored?

It's possible to capture content in an interlaced way, which means that every field represents a distinct point in time. This type of content exhibits very obvious combing artefacts. I'll refer to this as "true interlacing".

It's also possible to capture content as progressive frames, and then convert those frames to interlaced fields. In this case, each pair of fields is a unique point in time. This doesn't exhibit combing artefacts, but care should be taken to ensure that 2 fields are re-combined into a single frame. I'll refer to this as "fake interlacing".

In the current version of other-transcode, both "true" and "fake" interlacing are treated the same: the yadif filter is applied, and it will combine 2 fields into a single frame. This means that the frame rate of the output is always one half the field rate of the input. This is exactly the correct thing to do for "fake interlacing". It's also acceptable for "true interlacing", but there is another option: setting the output framerate to match the input field rate. This will retain all the extra temporal resolution that "true interlacing" has.

My 2 requests:

Add an option along the lines of --preserve-field-rate. This option will change the deinterlacing filter to yadif=mode=send_frame, thus ensuring the output frame rate is the same as the input field rate. yadif will interpolate between fields, both spatially and temporally, to fill in the missing lines. From my testing, it does a good job of this.

Add a new --print-interlacing option. This option would be similar to --print-crop, in that it would scan the input and print out some information. I think this new option should print 2 things:

  1. Is the input stored interlaced. This information can be derived from the ffprobe scan you already do.
  2. Does the input appear to have combing artefacts. This can be derived by looping through the input with the idet filter in ffmpeg, and tallying up the results.

Between those 2 bits of information, a user should be able to make a good educated guess about the answers to the first 2 questions

  1. How was the content captured? If the idet filter detects combing artifacts, it was probably captured in an interlaced way. AKA: "true interlacing". If it doesn't, it was probably filmed as progressive frames.
  2. How was the content stored? If ffprobe says it's interlaced, it's stored interlaced

With those questions answered, it's up to the user to apply the --preserve-field-rate option to their taste.

lisamelton commented 3 years ago

@samhutchins Thanks for filing this!