Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interlace detection and deinterlace option #6447

Open
double-u-a opened this issue Jun 19, 2024 · 2 comments
Open

Interlace detection and deinterlace option #6447

double-u-a opened this issue Jun 19, 2024 · 2 comments

Comments

@double-u-a
Copy link

Describe the problem to be solved

A lot of source videos are interlaced, including older videos and 1080i broadcast footage. These will have interlace artifacts as Peertube's upload encoding assumes a progressive input. Having to deinterlace videos before uploading adds an unnecessary double encoding which reduces the quality of the video.

Describe the solution you would like

Add an option to detect interlacing (through ffmpeg idet tool) and then if an uploaded video is interlaced, add an option to deinterlace using yadif/bwdif as a filter for the peertube encoding stage.

@Chocobozzz
Copy link
Owner

Hi,

Can you provide ffmpeg commands to detect and deinterlace videos?

@Chocobozzz Chocobozzz added the Status: Waiting for answer Waiting issue author answer label Jun 20, 2024
@double-u-a
Copy link
Author

Sure here is what I do in Python at the moment before uploading to Peertube

This is the detection function I use using ffmpeg's idet filter:

def deinterlace_checker(filepath):
    cmd = f'ffmpeg -i "{filepath}" -filter:v idet -frames:v 2 -an -f null -'
    ffmpeg_output = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output_str = str(ffmpeg_output)

    if "Single frame detection: TFF" in output_str or "Single frame detection: BFF" in output_str:
        print('Interlaced: YES')
        return True
    else:
        print('Interlaced: NO')
        return False

Then the ffmpeg encoding logic using the function to detect (note I am using a yadif config which interpolates the frames and turns e.g. 1080i50 into 1080p50, a standard yadif=1 filter would turn 1080i50 into 1080p25.

if deinterlace_checker(file.filepath) == True:
        command = f'ffmpeg -y -i "{file.filepath}" -vf "yadif=mode=send_field:parity=auto:deint=all" -r "{2* file.fps_round}" -c:a aac "{outpath}"'
        print('Deinterlacing to temp:', command)
        response = subprocess.call(command, shell=True)
        print(response)
        uploadfile = outpath
    else:
        uploadfile = file.filepath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment