0

I've searched for days to find this solution. All i found was ways to add the logo the first seconds or after a few seconds or only between certain parts (for example between 30 and 210 seconds)

So the main question is: How to add my logo for the last 60 seconds in a video with ffmpeg? I have a lot of videos all different lengths and simply want the last 60 seconds to overlay with a .png logo (in this case also at the left bottom of the screen)

Currently i'm using what you see below which works fine (shows logo always except between 30-210 seconds of videos) but like i mentioned in title, it does not do exactly do what i want.

-i video.mp4 -vf "movie=/logo.png [watermark]; [in][watermark] overlay=1:main_h-overlay_h-1:enable=not(between'(t,30,210)') [out]"
Ƭᴇcʜιᴇ007
  • 111,883
  • 19
  • 201
  • 268
razz
  • 41
  • 1
  • 7

2 Answers2

2

There is a, likely inefficient, method to do this that worked here in a test but may fail when input timestamps are irregular i.e. start from non-zero.

Basic template is

ffmpeg -i in.mp4 -sseof -60 -copyts -i in.mp4 -loop 1 -i logo.png -filter_complex "[1][2]overlay=shortest=1[logo];[0][logo]overlay" out.mp4

The video is inputted twice. In the 2nd input, the sseof option is set which allows one to seek using a time interval measured from the end. Of course, unless specified otherwise, FFmpeg will reset input timestamps, so copyts is set to preserve input TS.

First, the logo is overlaid on the trimmed video, and that result overlaid on the first input. Since timestamps are preserved, the frames are in alignment and the purpose is achieved.

Gyan
  • 34,439
  • 6
  • 56
  • 98
  • That's a pretty cute trick! – Ouroborus Aug 25 '16 at 20:53
  • This worked like a charm, thank you :) Only trouble i still have is getting this working in a batch with the cms i'm working with but that has nothing to do with your answer, which is simply working! – razz Aug 25 '16 at 21:53
1

overlay and enable do not have the ability to reference the end or duration of the video. You'll need to use an additional command (probably ffprobe and grep, such as described in this answer) to extract the duration then use that to generate the ffmpeg command with the right between values.

Ouroborus
  • 2,792
  • 2
  • 15
  • 32
  • Just wondering if this all is possible in one command? Lets say i have a batch of 2000 videos and want to run it with a single command? – razz Aug 25 '16 at 16:35
  • No need for `grep`: you can use `ffprobe` alone. See one of the [other answers](http://superuser.com/a/945604/110524) in the link you provided. – llogan Aug 25 '16 at 18:57
  • @razz You have to do it in two commands. As Ouroborus mentioned do one command using `ffprobe` to determine length, and then the `ffmpeg` command using the duration you got from `ffprobe`. – llogan Aug 25 '16 at 18:58