Search code examples
aws-lambdaffmpegffmpeg-python

"No Output pad"error when using ffmpeg to create a subtitle overlay


I am using a Lambda function to run ffmpeg to rescale a video and then add subtitles from an .ass file.

I have tried a few variations, but am continuing to get an error: [AVFilterGraph @ 0x721bec0] No output pad can be associated to link label '2'.

The code is below, with the error stemming from the line: '[0]scale=iw/1.5:ih/1.5,setsar=1[v];[1][v]overlay=-100:320[vid][2]overlay[out]'

CODE

    try:
        subprocess.check_call([
            '/opt/ffmpeg',
            '-i', source_file,
            '-i', padding_image_file,
            '-i', subtitles_file,    # Input caption file path
            '-filter_complex',
            '[0]scale=iw/1.5:ih/1.5,setsar=1[v];[1][v]overlay=-100:320[vid][2]overlay[out]',
            '-c:a', 'copy', '-crf', '20', '-preset', 'fast', '-movflags', '+faststart',
            '-y', output_file
    ])

Solution

  • You need to add an output pad for the first overlay and then refer to it in the 2nd overlay. You can omit the final output pad.

    So, your filtergraph should be

    '[0]scale=iw/1.5:ih/1.5,setsar=1[v];[1][v]overlay=-100:320[vid];[vid][2]overlay'