0

I'm working with multiple filters using ffmpeg's -filter_complex, and I'm running into some weird problems using the tpad filter to add padding. I'm running ffmpeg 4.4 on a Mac.


Issue with tpad and -r flag

When I use the "-r 30" flag to set input framerate and the tpad filter at the same time, it produces some strange output.

ffmpeg -y -r 30 -i 'input.mp4' -filter_complex '
[0:v] tpad=stop=1 [outV]
' -map [outV] 'output.mp4'

Expected output: The input video with one frame of black added to the end.

Actual output: The input video followed by ~17 seconds of cloning the final frame, followed by one frame of black. The length of the extra cloned frame varied depending on the input video, but was always 3-6x the length of the input video.

When the "-r 30" flag is removed, the output is exactly as expected (the input video plus one frame of black).

ffmpeg -y -i 'input.mp4' -filter_complex '
[0:v] tpad=stop=1 [outV]
' -map [outV] 'output.mp4'

Or, keeping "-r 30" but removing the tpad filter, everything behaves as expected.

ffmpeg -y -r 30 -i 'input.mp4' 'output.mp4'

Using the -filter_complex command with other filters (concat, split, select, setpts, scale, overlay) seem to work fine as long as tpad isn't included.


Issue with tpad and concat

When I use tpad on a clip that has been spliced together with concat, I get weird behavior.

ffmpeg -y -i 'input.mp4' -filter_complex '
[0:v] split [one][two];
[one][two] concat [doubled];
[doubled] tpad=stop=30 [outV]
' -map [outV] 'output.mp4'

Expected output: Two copies of the input, then 30 black frames. Actual output: Two copies of the input (no black frames at the end).

I though maybe the presentation timestamps were getting messed up, so I tried resetting them after the concat operation. No change to the output.

ffmpeg -y -i 'input.mp4' -filter_complex '
[0:v] split [one][two];
[one][two] concat, setpts=PTS-STARTPTS [doubled];
[doubled] tpad=stop=30 [outV]
' -map [outV] 'output.mp4'

I tried tpad by itself and it works as expected (input followed by 30 black frames).

ffmpeg -y -i 'input.mp4' -filter_complex '
[0:v] tpad=stop=30 [outV]
' -map [outV] 'output.mp4'

I tried putting the padding in between two clips, and that creates even weirder behavior.

ffmpeg -y -i 'input.mp4' -filter_complex '
[0:v] split [one][two];
[one][two] concat [doubled];
[doubled] split [one][two];
[one] tpad=stop=30 [one];
[one][two] concat [outV]
' -map [outV] 'output.mp4'

Expected output: Two copies of the input, then 30 black frames, then two more copies of the input. Actual output: Two copies of the input, then a repeat of the final 30 frames of the input video.

Adding PTS resets after each step didn't help here either.


Neither of these issues makes any sense to me. Am I totally misunderstanding how tpad and ffmpeg in general are supposed to work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.