FFmpeg Scale2Ref Overlay Complex Filters Returning Audio-Only MP4 Output
In this article, we will explore how to use FFmpeg's Scale2Ref filter to overlay a watermark image on a video, while retaining only the audio output in MP4 format. We will cover key concepts, such as filtering, complex filters, and audio-only output.
Background
FFmpeg is a powerful, open-source multimedia framework that can handle a wide variety of audio and video formats. It provides a command-line interface that allows users to perform various operations, such as transcoding, filtering, and streaming media.
Filtering with FFmpeg
Filtering is a powerful feature in FFmpeg that allows users to apply various effects and transformations to audio and video streams. FFmpeg provides a wide range of built-in filters that can be combined to create complex filtering chains. These filtering chains can be used to perform operations such as scaling, cropping, rotating, and overlays.
Scale2Ref Filter
The Scale2Ref filter is a complex filter that allows users to scale one video stream to match the resolution of another video stream. This filter is particularly useful when overlaying a watermark image on a video, as it ensures that the watermark is displayed at the correct size and position.
Overlaying a Watermark Image
To overlay a watermark image on a video, we can use the following command:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.25[wm][base];[base][wm]overlay=W-w-10:H-h-10" -c:a copy output.mp4In this command, we first scale the watermark image to match the aspect ratio of the video stream, and then overlay it on the video stream with a 10-pixel margin from the bottom-right corner. The '-c:a copy' option ensures that only the audio stream is copied to the output file.
Returning Audio-Only MP4 Output
To return an audio-only MP4 output, we can modify the command as follows:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.25[wm][base];[base][wm]overlay=W-w-10:H-h-10" -map 0:a -c:a copy output.mp4In this command, we use the '-map 0:a' option to select only the audio stream from the input file. The '-c:a copy' option ensures that the audio stream is copied to the output file without any re-encoding.
FFmpeg's Scale2Ref filter is a powerful tool for overlaying watermark images on videos while retaining only the audio output in MP4 format. By combining this filter with other filtering chains, users can perform a wide range of audio and video transformations.