Fun with ffmpeg filter and transparency #1862
toots
started this conversation in
Show and tell
Replies: 2 comments 5 replies
-
This is great work, thanks! Any chance that you could add pre-written functions in the standard library? Something like |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is a great example to see. When using larger sized transparent videos, CPU usage creates a lot of buffering/ Is there a way to reduce the CPU usage, or dedicate processes to individual cores for processing? Also, when you have time, can you show an example for using a Video playlist, with embeded audio, as the background source. Thanks - |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Note: This post requires the latest
liquidsoap
main andocaml-ffmpeg
master branch at time of writting (Aug. 28, 2021)Had some fun with ffmpeg, video and transparency after a request from a user! Here's the gist of it:
Static image, audio and transparent overlay
The goal of the script is to:
We achieve this using
ffmpeg
filters!1. Static logo image
The first version of our script will use static images for both background and logo. First, we need our basic sources:
Next, we write the ffmpeg filter used to overlay the logo on top of the background:
And finally, we put it all together:
The one thing to note is the use of
%video.raw
for the video encoder. This makes sure that we keep the video frame as ffmpeg frame all along.The source is decoded as ffmpeg frames, passed to the filter as such and then to the encoder. This way, we are never converting the frame to the internal liquidsoap video frame data. This is good for two reasons:
Time to see the script in action! The whole script:
Full script
2. Dynamic transparent video
Next, we're adding a transparent video! This is pretty much the same, except:
vp9
video since this is one of the only codec that supports transparent video..vp9
in ffmpeg is still very new and a bit rough. In particular, we need to force the use of google'slibvpx-vp9
vp9
decoder instead of the internal one.This is easily achieved, though, by adding this to the top of our script:
Next, we wil scale the logo video to the size we want it to be. Here's our updated ffmpeg filter:
Then we only need to change
logo.png
tologo.webm
, our transparentvp9
video. Here we go:Full script
And that's it! I'm attaching the script and files to this discussion for anyone to reproduce locally!
transparent.zip
Beta Was this translation helpful? Give feedback.
All reactions