Skip to main content

Overlaying the animated gif logo file on corner of mp4 video using FFmpeg command

 



Sometimes, I inspire from some online videos that their logo continiously animated throughtout their length. Hence tried this work and FFmpeg command essentially takes two files as input - mp4 video file and an animated gif, apply various filters and then overlays the gif on the mp4, loops the gif infinitely and saves the final output as mp4 file (without audio).




ffmpeg -i input.mp4 -stream_loop -1 -i animals.gif -filter_complex "[1]colorchannelmixer=aa=1,scale=iw*1:-1[a];[0][a]overlay=x='35':y='35':shortest=1" -c:v libx264 -an output2.mp4


Breaking it down


-stream_loop -1 - This option tells ffmpeg to loop the gif file indefinitely.

-filter_complex - this option is used to specify a complex filtergraph, a chain of filter in a single instance. This complex filtergraph is composed of two filters:
a. [1]colorchannelmixer=aa=1 - This filter changes the color channel of the gif file.
b. scale=iw*1:-1[a] - this filter changes the scale of the gif.

[0][a]overlay=x='35':y='35':shortest=1 - this filter overlays the gif on the mp4 file. Here x and y specifies the position of the gif on the mp4 file. shortest=1 option tells the filter to end the output when the shortest input terminates.

-c:v libx264 - this option tells FFmpeg to encode the output file using the libx264 codec. The codec is responsible for compressing and decompressing the video data. This option is specific for the video codec.

-an - this option tells FFmpeg to drop the audio stream from the input file. This option is specific for the audio codec.

mp4 source: https://file-examples.com/storage/fea8fc38fd63bc5c39cf20b/2017/04/file_example_MP4_1920_18MG.mp4





Comments

Popular posts from this blog

Video display in Imgui using C++ and ESCAPI

To create an application that can view the webcam using ImGUI, C++, and ESCAPI, you can follow these steps: Install the required libraries and tools: You will need to have the ImGUI, C++, and DirectX11 libraries and tools installed on your system in order to build the application. You may also need to install additional libraries or tools that are required to access the webcam and capture video frames, such as the Microsoft Media Foundation library or the OpenCV library. Set up the ImGUI interface: Use the ImGUI library to set up the user interface for the application. This will typically involve creating the layout for the application's window, as well as any necessary buttons, sliders, or other controls that will be used to interact with the webcam. Initialize the ESCAPI context: Use the ESCAPI library to create a context that will be used to grabbing the webcam video frames. This will typically involve setting up a creating a render target, and initializing any necessary reso...

About FFmpeg

Do you know what's common in Chrome browser, VLC media player, TikTok, Youtube, Netflix, Instagram Reels ? FFmpeg is a powerful, open-source, cross-platform library for handling multimedia files. It is widely used for video and audio recording, conversion, and streaming, and is the backbone of many popular media players, video editing tools, and media centers. FFmpeg is written in the C programming language and has a modular design, with a wide range of codecs and filters that can be easily added or removed. This allows it to support a vast array of media formats, including MP3, MP4, H.264, HEVC, and many others. One of the key features of FFmpeg is its command-line interface, which allows users to perform a wide range of operations on multimedia files without having to write any code. For example, you can use FFmpeg to convert an audio file from one format to another, extract the audio from a video file, or even combine multiple audio and video files into a single output file. FFm...

Codec and pixel formats CODEC_ID_MPEG1VIDEO and PIX_FMT_YUV420P

The CODEC_ID_MPEG1VIDEO and PIX_FMT_YUV420P constants are part of the FFmpeg library, which is a popular open-source library for working with audio and video. These constants are used to identify specific codecs and pixel formats that can be used when processing audio and video data. If you are getting an error involving these constants, it could be due to a number of factors. Some possible causes of the error could include: Missing or incorrect include statement: Make sure that you have included the necessary FFmpeg header files in your source code, and that the include statements are correct. For example, to use the CODEC_ID_MPEG1VIDEO and PIX_FMT_YUV420P constants, you would need to include the avcodec.h header file. Linking errors: If you are using a pre-built version of the FFmpeg library, make sure that you have linked your project to the correct version of the library. If you are building FFmpeg from source, make sure that the library was built correctly and that your project...