منبع اصلی نوشتار زیر در این لینک قرار دارد

یک اسکریپت برای واترمارک عکس و ویدیو

چند وقت پیش مطلبی نوشته بودم در این خصوص که چطوری روی یک عکس یا روی یک فایل ویدیویی واترمارک خودمون رو اضافه کنیم. مدتی بعدش تصمیم گرفتم این دو تا کار رو با هم ادغام کنم و در قالب یک اسکریپت استفاده کنم. نتیجه کار شد این:

#!/bin/bash
#
# A script to add an image as a watermark over videos or image files.
# I'm not a developer, and I wrote this script just for my needs.
# 07 November 2016
# Amin [email protected] http://linuxvaman.ir
# Feel free to make this script better :)
#

path_of_first_file=$(dirname "$2")
name_of_first_file=$(basename "$2")

new_name="$(echo "wmark-$name_of_first_file")"
new_output=$(echo "$path_of_first_file/$new_name")


if [ $# -lt 1 ]
then
    echo
    echo "A simple script to add an image as a watermark over videos or image files."
    echo "As of simplicity of usage, all watermarks will be added to the northwest area of the image or the video files."
    echo "to change these positions you should edit the script codes"
    echo
    echo "-i     add watermark to a single image "
    echo "example: wmark -i /path/to/image.png /path/to/watermark.jpg"
    echo
    echo "-v     add watermark to a single video "
    echo "example: wmark -v /path/to/video.mpg /path/to/watermark.jpg"
    echo
    echo "-ia     add watermark to all image files in a directory that wmark runs in"
    echo "example: wmark -ia /path/to/watermark.jpg"
    echo
    echo "-va     add watermark to all video files in a directory that wmark runs in "
    echo "example: wmark -va /path/to/watermark.jpg"
    echo
    echo "-r     replaces the space in all filenames with a dash "
    echo "example: wmark -r"
    echo
exit
fi


case $1 in

#Here you can change "northwest" to these variables: northeast, southwest, southeast
-i)
composite -dissolve 70% -gravity northwest -geometry +10+10 "$3" "$2" "$new_output"
echo
echo "New image saved in: " "$path_of_first_file"\/$new_name
exit 0
;;

#As ffmpeg is more complex, you should know the resolution of the video file to change the possition of the watermark, by editing "overlay=15:10" (top:left)
-v)
ffmpeg -i "$2" -i "$3" -filter_complex "overlay=15:10" -preset veryfast "$new_output"
echo
echo "New video saved in: " "$path_of_first_file"\/$new_name
exit 0
;;

#Here you can change "northwest" to these variables: northeast, southwest, southeast
-ia)
for i in *.png *.jpg;
do
composite -dissolve 70% -gravity northwest -geometry +10+10 "$2" $i wmark-$i
done
echo
exit 0
;;

#As ffmpeg is more complex, you should know the resolution of the video file to change the possition of the watermark, by editing "overlay=15:10" (top:left)
-va)
for i in *.mp4 *.flv *.mpg *.rm;
do
ffmpeg -i $i -i "$2" -filter_complex "overlay=15:10" -preset veryfast wmark-$i.mp4
done
echo
exit 0
;;

-r)
for i in *\ *; do mv "$i" "${i// /-}";
done
echo
exit 0
;;

esac




اسکریپت رو خوب نگاه کنید تا با طرز کارش آشنا بشید. این اسکریپت رو با نام مثلا wmark جایی ذخیره کنید و براش یک alias بسازید. اونوقت میتونید باهاش کار کنید. یک بار wmark رو در ترمینال اجرا کنید تا خودش راهنماییتون کنه و مثال بزنه.