FFmpeg watermark

4

ffmpeg –i test.mkv -vf "movie=watermark.png [watermark]; [in][watermark] overlay=10:10 [out]" outputvideo.mkv

I'm trying to simply add a watermark to a video to start testing with ffmpeg. But it simply does not work although I can't see any error.

I also tried

ffmpeg -i test.mkv -i watermark.png -filter_complex 'overlay=10:main_h-overlay_h-10' output.mkv

But no success there either.

Output:

ffmpeg version 1.1.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan 20 2013 23:05:28 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 86.100 / 54. 86.100
  libavformat    54. 59.106 / 54. 59.106
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 32.100 /  3. 32.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'test.mkv':
  Metadata:
    creation_time   : 2012-11-01 02:35:10
  Duration: 00:00:59.74, start: 0.000000, bitrate: 5821 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1280x720, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc
    Stream #0:1: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
Input #1, image2, from 'watermark.png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: png, rgba, 1600x200, 25 tbr, 25 tbn, 25 tbc
[Parsed_overlay_0 @ 00328000] Overlay area (10,510)<->(1610,710) not within the main area (0,0)<->(1280,720) or zero-sized
[auto-inserted scaler 0 @ 03da0f60] Failed to configure input pad on Parsed_overlay_0

Milanezi

Posted 2013-06-10T19:37:37.680

Reputation: 63

2Please include the complete ffmpeg console output(s). Otherwise we can only guess. Your second command is the recommended version (-vf is for simple filtergraphs: one input and one output). – llogan – 2013-06-10T20:05:25.640

I tried echo and > output.txt for my output but it didn't work.

So I took a small screenshot from my output. – Milanezi – 2013-06-11T06:55:31.763

Maybe Windows doesn't like the single quotes. Try removing the single quotes or replacing them with double quotes: ". – llogan – 2013-06-11T07:02:49.723

You need to redirect output with 2> output.txt – slhck – 2013-06-11T07:25:14.523

The 2> output.txt did the trick, thanks!

@LordNeckbeard I think you are right. I get a new error now but I think that's because my dimensions of my watermark are bigger than my videos dimensions:

I think the command -s in ffmpeg can fix the dimension problem when i put it after the logo input. – Milanezi – 2013-06-11T07:41:58.290

To quote the output please use Ctrl-K or the {} code button, not the blockquote format. This way it'll be rendered as preformatted text. Thanks! – slhck – 2013-06-11T08:46:45.917

Answers

2

It seems that your watermark is larger than the main video. Since you're using filters already, the cleanest way to fix that is with the scale filter. scale=25:20 will scale it to a 25x20 pixel square. If you were to use scale=25:-1 it would scale the video (watermark in this case) to a width of 25, and scale the height down such that the aspect ratio stays the same (you can also use scale=-1:20).

Here is an example use:

ffmpeg -i test.mkv -i watermark.png -filter_complex \
"[1:v]scale=25:20[wat];[0:v][wat]overlay=10:main_h-overlay_h-10[outv]" \
-map "[outv]" -map 0:a output.mkv

With a complex filtergraph, I personally always label my inputs and outputs in order to increase readability. If you don't have any audio, or don't want to take any audio from test.mkv, then cut out the -map 0:a.

Within the filtergraph, [1:v] refers to 'the video of input 1' (watermark.png in this case, since ffmpeg starts counting from 0). You could equally use [1:0] for 'the zeroth stream of input 1', or just [1], since in this case there is only one stream in the input. See the stream specifiers documentation for a bit more information.

The [wat] at the end of the scale filter simply allows for the rest of the filtergraph to refer to the output of the scale filter -- akin to setting a variable in a script. The [outv] at the very end of the filtergraph serves a similar function, but here I'm using it outside of the filtergraph too (all labels set within a filtergraph are similarly accessible outside of the filtergraph, with the -map option).

To achieve decent-quality video, you'll need to set several other options; check out this general encoding primer, or one of the more in-depth guides at the FFmpeg wiki.

evilsoup

Posted 2013-06-10T19:37:37.680

Reputation: 10 085

Could you explain the parameter [1:v]? Does it target the second "video" (as I suppose counting starts with 0)? The [wat] is the name for watermark but isn't it needed to put watermark.png [wat] in your code? – Milanezi – 2013-06-11T08:44:15.833

1

Another option for resizing the watermark image is the crop video filter which would be useful if the watermark has a large blank area for example.

– llogan – 2013-06-11T17:13:45.447

After some testing the script tells me that atleast one output file must be specified.

And: '-map' is not recognized as an internal or external command, operable program or batch file. Any idea? – Milanezi – 2013-06-11T17:17:14.690

Double-check that you typed it in correctly, I suppose. I don't know if the Windows CLI allows the use of escaped newlines (it probably does, I just haven't used it enough to know), so also make sure you're typing it all out as one big line, rather than breaking it up as I have in the example. – evilsoup – 2013-06-11T17:23:18.057

It is working now, thanks a lot. But is it normal that rendering takes a lot of time? A 42MB video file take about 10 minutes? – Milanezi – 2013-06-11T17:31:22.110