VideoHelp Forum




+ Reply to Thread
Results 1 to 3 of 3
  1. Member
    Join Date
    Aug 2023
    Location
    United Kingdom
    Search PM
    As described in my previous threads, I've been trying to get a working script to de-interlace a mix of broadcast content.

    I've used this script which achieves just about everything I'd like with the encodes:

    Code:
    Import("TemporalDegrain-v2.6.6.avsi")
    
    # Load both audio and video in sync, explicitly set original FPS
    video_audio = FFmpegSource2("1_New_Raw_Sample", atrack=-1, fpsnum=30000, fpsden=1001).ConvertToYUY2().AssumeTFF()
    
    # Crop
    crop_left = 4
    crop_top = 4
    crop_right = 12
    crop_bottom = 4
    video_crop = video_audio.crop(crop_left, crop_top, -crop_right, -crop_bottom)
    
    # QTGMC at 59.94 fps
    processed = video_crop.AssumeTFF()
    processed = QTGMC(processed, preset="Slower")
    
    # Denoising
    denoised = processed.ConvertToYV16().TemporalDegrain2(degrainTR=1).ConvertToYUY2()
    
    # Sharpening (fixed)
    sharpened_yv12 = denoised.ConvertToYV12().LSFmod(defaults="slow")
    sharpened = sharpened_yv12.ConvertToYUY2().MergeChroma(denoised)
    
    # Restore borders
    # Calculate total cropped width/height
    total_crop_w = crop_left + crop_right
    total_crop_h = crop_top + crop_bottom
    
    # Calculate symmetrical borders
    border_left   = total_crop_w / 2
    border_right  = total_crop_w - border_left
    border_top    = total_crop_h / 2
    border_bottom = total_crop_h - border_top
    
    # Round if needed (AviSynth expects integers)
    border_left   = Round(border_left)
    border_right  = Round(border_right)
    border_top    = Round(border_top)
    border_bottom = Round(border_bottom)
    
    video_final = sharpened.AddBorders(border_left, border_top, border_right, border_bottom)
    
    # Convert to YV12 and output (audio already present)
    final_output = video_final.ConvertToYV12()
    final_output = final_output.ConvertFPS(60000, 1001)  # Proper timing for 59.94 fps without desync
    
    final_output2 = final_output.Prefetch(20)
    return final_output2
    Code:
    ffmpeg -i script.avs -vf "setsar=10/11" -aspect 4:3 -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -profile:v high -level 4.1 -rc-lookahead 40 -refs 4 -c:a aac -b:a 192k -movflags +faststart 2_New_Encoded_Sample.mp4
    1. Frame rate doubled to 59.94fps for smooth playback (retaining both live action and animation clarity)
    2. Slight noise reduction
    3. Remove junk noise and empty space through cropping
    4. Replace the cropped pixels with black pixels, retaining original dimensions of 720 x 480
    5. Center the picture after cropping, for image symmetry
    6. Encode at a faster speed (prefetch)
    7. Encode at high-lossy with no visible difference to lossless
    8. Encode at correct aspect ratio of 4:3

    I'm hoping to move forward to this script for big batches (I have much of the same broadcast content), only modifying for variables such as field order and image cropping.

    Although I'm really happy with the results, I'd be keen to know what others think? Personally I don't think there should be any more noise removal as it may start losing too much detail. Are there any other aspects I should consider?
    Image Attached Files
    Quote Quote  
  2. Just looked at the script.
    Why the whole 4:2:2 <> 4:2:0 conversions, when you aim for 4:2:0 for the output?
    If you aim for 4:2:0 the restoring of the chroma after lsfmod and the YUY2<>YV16 conversions seem useless.
    The ConvertFPS seems useless. Source is returned by the source filter @30000/1001fps and then doubled by QTGMC to 60000/1001.
    Personally, I would crop after deinterlacing and not the other way around. (so even with 4:2:0 I can use mod2 cropping vertically)
    You might want to do some testing, I assume using a lower prefetch value might be faster with the filters you use.

    Cu Selur
    users currently on my ignore list: deadrats, Stears555, marcorocchini
    Quote Quote  
  3. Member
    Join Date
    Aug 2023
    Location
    United Kingdom
    Search PM
    Originally Posted by Selur View Post
    Just looked at the script.
    Why the whole 4:2:2 <> 4:2:0 conversions, when you aim for 4:2:0 for the output?
    If you aim for 4:2:0 the restoring of the chroma after lsfmod and the YUY2<>YV16 conversions seem useless.
    The ConvertFPS seems useless. Source is returned by the source filter @30000/1001fps and then doubled by QTGMC to 60000/1001.
    Personally, I would crop after deinterlacing and not the other way around. (so even with 4:2:0 I can use mod2 cropping vertically)
    You might want to do some testing, I assume using a lower prefetch value might be faster with the filters you use.

    Cu Selur
    I've updated this script with some adjustments.

    Code:
    Import("TemporalDegrain-v2.6.6.avsi")
    
    # Load source
    video_audio = FFmpegSource2("1_New_Raw_Sample_2.avi", atrack=-1, fpsnum=30000, fpsden=1001).AssumeTFF()
    
    # QTGMC at 59.94 fps
    processed = QTGMC(video_audio, preset="Slower")
    
    # Crop after deinterlacing
    crop_left = 4
    crop_top = 4
    crop_right = 12
    crop_bottom = 4
    cropped = processed.crop(crop_left, crop_top, -crop_right, -crop_bottom)
    
    # Denoise and sharpen in YV12 (this is to avoid unnecessary format switching)
    denoised = cropped.TemporalDegrain2(degrainTR=1)
    # Reconvert to YV12 due to TempDegrain output
    sharpened = denoised.ConvertToYV12().LSFmod(defaults="slow")
    
    # Restore borders
    border_left   = Round((crop_left + crop_right) / 2)
    border_right  = (crop_left + crop_right) - border_left
    border_top    = Round((crop_top + crop_bottom) / 2)
    border_bottom = (crop_top + crop_bottom) - border_top
    restored = sharpened.AddBorders(border_left, border_top, border_right, border_bottom)
    
    # Output with prefetch
    return restored.Prefetch(12)
    See attached. I'd be interested to see if anyone can spot some improvements.
    Image Attached Files
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!