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...

how to get frames per second value from video file using ffmpeg c++

  To get the frames per second (FPS) value from a video file using FFmpeg and C++, you can follow these steps: Include the required FFmpeg header files in your C++ source code: #include <libavformat/avformat.h> #include <libavcodec/avcodec.h> Open the input video file using the avformat_open_input() function: AVFormatContext *format_context = nullptr; int error = avformat_open_input(&format_context, input_filename, nullptr, nullptr); if (error < 0) { // Handle error } Find the stream information in the input file using the avformat_find_stream_info() function: error = avformat_find_stream_info(format_context, nullptr); if (error < 0) { // Handle error } Find the video stream in the input file using the av_find_best_stream() function: int video_stream_index = av_find_best_stream(format_context, AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0); if (video_stream_index < 0) { // Handle error } Get the FPS value from the video stream's codec context using the...

Image overlay on video using c++ and ffmpeg API

This project is NOT a command line, It is a tool written in C++ that uses the FFmpeg library to overlay an image on top of a video. The tool takes as input a video file, an image file, and the output file name, and overlays the image on top of the video at a specified location and for a specified duration. watch the demo on youtube The tool uses the FFmpeg library to decode the video and image, and to encode the output video with the overlay. It also allows the user to specify the x and y coordinates of the top-left corner of the image, as well as the width and height of the image, in pixels. The tool can be used to add a logo or watermark to a video, or to add other types of visual overlays. To use the tool, the user needs to have FFmpeg installed on their system and available in the system's PATH. The user can then compile the C++ source code and run the resulting executable from the command line, specifying the necessary arguments. source code: https://github.com/abdullahfarwees...