Search code examples
javaffmpegmediawatermark

Creating an FFMPEG command for setting all videos to the same size and adding an watermark?


I'm writing a Java app that uses at some point an ffMPEG command in the console. This command needs to do the following:

  • Take the input file from DDTV/episodes-unconverted/example.[mpg/avi]
  • Make it 1280x780. (If it's 4:3, add pillar boxes, if it's 16:9... just you know do nothing I guess)
  • Add the watermark DDTV/DDTVwatermark.png at 10px from the bottom, and 10px from the right, at 33% transparency to the video.
  • Output it to DDTV/episodes-converted/example.mpg

Solution

  • This would work :

    ffmpeg -i "DDTV/DDTVwatermark.png" -i "DDTV/episodes-unconverted/example.mpg" \
    -filter_complex "[0:v]colorchannelmixer=0.33[ov];[1:v]scale=iw*sar*min(1280/(iw*sar)\,780/ih):ih*min(1280/(iw*sar)\,780/ih),pad=1280:780:(ow-iw)/2:(oh-ih)/2:black[mainv];[ov][mainv]overlay=main-w-10:main_h-10[video_out] \
    -map [video_out] -map 1:a DDTV/episodes-converted/example.mpg
    

    If you want to addd more output option(like codec) put it here in following command :

    -filter_complex "~" -map [video_out] -map 1:a -c:v mpeg2video -c:a mp3 DDTV/episodes-converted/example.mpg
    

    Actually, you can put it anywhere in command line but it just conventional thing. and don't use copy in this case. you can't copy input codec because you're using filter. copy option only works when no filter is used.

    let me know if you have any further question.