Watermarking video from the Linux command line
ffmpeg -y -i 'inputFile.mpg' -vhook '/usr/lib/vhook/watermark.so -f /home/user/logo.gif'
Make note of the "-vhook" parameter; watermark.so path may vary.
Command for putting watermark on video
If anyone has the issue in future with putting watermark on video here is how you can do it. This can be done using writingminds compiled FFmpeg library:
http://writingminds.github.io/ffmpeg-android-java/
Follow the instructions how to setup FFmpeg
into your project. After that by running this command I was able to put watermark on video:
String commands[]={"-y","-i",videoInputPath,"-i", imagePath,"-filter_complex","[1:v]scale=200:200 [ovrl], [0:v][ovrl]overlay=main_w-overlay_w-5:main_h-overlay_h-5:enable='between(t,"+0+","+timeInSec+")'","-codec:a","copy","-strict","-2","-c:v","libx264","-preset","ultrafast",videoOutPath};
videoInputPath
- is path of video
imagePath
- is path of an image from external storage. I tried by using image from Drawable
but didn't find that working (not saying it's not possible)
timeInSec
- is length of video which you can get from MediaMetadataRetriever
:
File videoFile = new File(path);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, Uri.fromFile(videoFile));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time );
timeInSec = (int) (timeInMillisec /1000);
videoOutPath
- path where video is going to be saved after putting watermark
Command above will also scale watermark on 200:200
you can adjust according to your needs and put it in bottom right side.
How to add transparent watermark in center of a video with ffmpeg?
Examples to add a watermark / logo image on video using the overlay filter.
Centered
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.mp4
or with the shortened overlay options:
overlay=(W-w)/2:(H-h)/2
Top left
This is the easy one because the default, if you provide no options to overlay, is to place the image in the top left.
This example adds 5 pixels of padding so the image is not touching the edges:
overlay=5:5
Top right
With 5 pixels of padding:
overlay=main_w-overlay_w-5:5
or with the shortened options:
overlay=W-w-5:5
Bottom right
With 5 pixels of padding:
overlay=main_w-overlay_w-5:main_h-overlay_h-5
or with the shortened options:
overlay=W-w-5:H-h-5
Bottom left
With 5 pixels of padding:
overlay=5:main_h-overlay_h
or with the shortened options:
overlay=5:H-h-5
Transparency / opacity / alpha
Example to make watermark 50% transparent using the format and colorchannelmixer filters:
ffmpeg -i input.mp4 -i watermark.jpg -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.5[logo];[0][logo]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p" -c:a copy output.mp4
Improved quality
Using the format=auto
option in the overlay filter can make PNG watermarks look better:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=5:H-h-5:format=auto,format=yuv420p" -c:a copy output.mp4
Note the addition of the format filter (yes, same name as the option, but a standalone filter) to reset it to YUV 4:2:0 which is needed for MP4 output. Remove ,format=yuv420p
if you are not outputting MP4.
Scale watermark in relation to main video
Use the scale2ref filter:
Example to make logo 10% (1/10) the size of the main video:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5" -c:a copy output.mp4
How to show a watermark for 3 second on a MP4 using FFmpeg
FFmpeg 1.2 does not have timeline editing support. Please refer to your local FFmpeg documentation when using old releases. The online FFmpeg documentation is synced daily with the source code, and because FFmpeg development is very active the online documentation may not be suitable for your old release.
Releases are intended for distributors. General users should use the most recent source code from git master.
Watermarking Flash Videos (server-side)
You can use FFMPEG, a command line video tool to do this. It is cross-platform and easy enough to be used.
Watermarking example is shown in this tutorial.
I hope this helps.
Related Topics
How to Execute Shell Builtin from Scala
Why Doesn't Tar Preserve File Permissions
How to Remember Multiple Tabs' Session in Terminal? (Alike Ff Session Manager)
Why Does Pages Allocation with Order of 10 or 11 Using _Get_Free_Pages() Usually Fail
Fork() and Stdout/Stderr to The Console from Child Processes
Too Many Open Files Error on Lucene
What Is The Equivalent of /Proc/Cpuinfo on Freebsd V8.1
Can Multiple .Gz Files Be Combined Such That They Extract into a Single File
Getting Following Error After The Command Sudo Apt-Get Update on Ubuntu 16.04
Linux Kernel - How to Get Physical Address (Memory Management)
Under What Circumstances Does The Read() Syscall Return 0
In Linux, How to Create a File Descriptor for a Memory Region
Check If All Lines from One File Are Present Somewhere in Another File
Finding Threading Bottlenecks and Optimizing for Wall-Time with Perf
How to Convert Dynamically Linked Application to Statically One