ieXcept
ieXcept

Reputation: 1127

How to set an overlay image on the subpart of a video?

I need to set an overlay (image.png with alpha channel) on the subpart of a video. Setting it on the whole video works great. But I need to make 10 seconds gap without PNG in the beggining and in the end of a video.

So the overlay should appear on the 10th second after the start and automatically disappear on the (length - 10) second. I spent a day trying to make it work, but it seems that trim video filter simply doesn't support trimming "single-PNG-image video stream".

In this command

ffmpeg -y -i "$INPUT" -i "$PNG" -c:v libx264 -preset ultrafast -filter_complex \
"[0:v]setpts=0.5*PTS,fps=25[vm]; [1:0]trim=10:190[vo]; [vm][vo]overlay=x=0:y=0:overlay=eof_action=pass[v]; [0:a]atempo=2.0[a]" \
-map "[v]" -map "[a]" qtest_AVUP.avi

the 190 should be replaced with some function/calculations, but the real problem is that the overlay isn't applied at all. As the result we've got normal video without overlays. Could you please help me to solve this?

  1. How can I fix the overlay inapplicability error?
  2. How to set (video_stream_length-10s) instead of 190?

Upvotes: 1

Views: 299

Answers (1)

UltrasoundJelly
UltrasoundJelly

Reputation: 1900

Try this for your overlay code:

-filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,20,40)'" 

This will put your overlay between 20 and 40 seconds. You'll have to do a calculation to get your EOF-10. Here's some code to get your video duration:

DURATION=$(ffprobe -v error  -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $INPUT )

Upvotes: 1

Related Questions