Search code examples
ffmpegoverlaytransparencygifopacity

ffmpeg overlay image and lower transparency


I have this ffmpeg command that I use to create a video from a photo and a animated GIF border overlay, and a audio track.

ffmpeg -framerate 15 -loop 1 -i photo.jpg -ignore_loop 0 -i overlay.gif -filter_complex "scale=(iw*sar)*max(600/(iw*sar)\,750/ih):ih*max(600/(iw*sar)\,750/ih), crop=600:750, overlay" -i audio.wav -c:v libx264 -c:a aac -b:a 192k -shortest output.mp4

What I want is to lower the opacity of the overlay image.

I have checked a lot of threads, but I can't figure out how to combine something like this with my existing filters.

 -filter_complex "blend=all_mode='overlay':all_opacity=0.7" 

Any ideas?


Here's the full ffmpeg output of one of my tests:

ffmpeg -framerate 15 -loop 1 -i photo.jpg -ignore_loop 0 -i overlay.gif -filter_complex "scale=(iw*sar)*max(600/(iw*sar)\,750/ih):ih*max(600/(iw*sar)\,750/ih), crop=600:750, blend=all_mode='overlay':all_opacity=0.7" -i audio.wav -c:v libx264 -c:a aac -b:a 192k -shortest output.mp4

ffmpeg version N-83507-g8fa18e0 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enabl
e-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug -
-enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspe
ex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable
-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 47.100 / 55. 47.100
  libavcodec     57. 80.100 / 57. 80.100
  libavformat    57. 66.102 / 57. 66.102
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 73.100 /  6. 73.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, image2, from 'photo.jpg':
  Duration: 00:00:00.07, start: 0.000000, bitrate: 15374 kb/s
    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 400x600 [SAR 72:72 DAR 2:3], 15 fps, 15 tbr, 15 tbn, 15 tbc
Input #1, gif, from 'overlay.gif':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: gif, bgra, 600x750, 5.42 fps, 5 tbr, 100 tbn, 100 tbc
Guessed Channel Layout for Input Stream #2.0 : mono
Input #2, wav, from 'audio.wav':
  Duration: 00:00:23.00, bitrate: 705 kb/s
    Stream #2:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
[swscaler @ 00000000023300a0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000000000234d1e0] deprecated pixel format used, make sure you did set range correctly
[Parsed_blend_2 @ 00000000022fd0c0] First input link top parameters (size 600x750, SAR 1:1) do not match the corresponding second input link bottom parameters (600x750, SAR 0:1)
[Parsed_blend_2 @ 00000000022fd0c0] Failed to configure output pad on Parsed_blend_2
Error configuring complex filters.
Invalid argument

Solution

  • Use the colorchannelmixer filter.

    ffmpeg -framerate 15 -loop 1 -i photo.jpg
           -ignore_loop 0 -i overlay.gif
           -i audio.wav
      -filter_complex "[0]scale=(iw*sar)*max(600/(iw*sar)\,750/ih):ih*max(600/(iw*sar)\,750/ih),
                          crop=600:750[b];
                       [1]format=argb,colorchannelmixer=aa=0.5[ol];[b][ol]overlay"
      -c:v libx264 -c:a aac -b:a 192k -shortest output.mp4
    

    The 0.5 sets it to 50% transparent.