<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Video App – IMG.LY Blog</title><description>Posts tagged Video App on the IMG.LY blog.</description><link>https://img.ly/blog/tag/video-app/</link><language>en-us</language><image><url>https://img.ly/apple-touch-icon.png</url><title>Video App – IMG.LY Blog</title><link>https://img.ly/blog/tag/video-app/</link></image><atom:link href="https://img.ly/blog/tag/video-app/rss.xml" rel="self" type="application/rss+xml"/><generator>Astro</generator><lastBuildDate>Fri, 19 Jun 2026 11:26:07 GMT</lastBuildDate><ttl>60</ttl><item><title>IMG.LY Partners with Soundstripe to Infuse Video Editing with Epic Royalty-Free Music &amp; SFX</title><link>https://img.ly/blog/img-ly-partners-with-soundstripe/</link><guid isPermaLink="true">https://img.ly/blog/img-ly-partners-with-soundstripe/</guid><description>Elevated storytelling and captivating viewers is everything: unlock the ultimate video editing experience with this integration.</description><pubDate>Wed, 24 May 2023 07:31:24 GMT</pubDate><content:encoded>&lt;p&gt;We are excited to announce our exciting new partnership with Soundstripe, the leading provider of royalty-free music for video creators. Our VideoEditor SDK now features a seamless integration with Soundstripe, offering users access to a vast collection of over &lt;strong&gt;9,000 hand-curated songs&lt;/strong&gt; from &lt;strong&gt;150+ musicians&lt;/strong&gt;, along with an extensive library of &lt;strong&gt;70,000 sound effects&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/soundstripe_2.mp4&quot; controls playsinline poster=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/integrate-soundstripe-into-app.jpg&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;Starting from version 11, our &lt;a href=&quot;https://img.ly/products/video-sdk/&quot;&gt;VideoEditor SDK&lt;/a&gt; now comes pre-equipped with a seamless Soundstripe integration, as detailed in our &lt;a href=&quot;https://img.ly/docs/vesdk/ios/guides/audio-overlays/custom-overlays/soundstripe-integration/#soundstripe-api&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;streamlining-music-licensing-for-digital-platforms&quot;&gt;Streamlining Music Licensing for Digital Platforms&lt;/h3&gt;
&lt;p&gt;Finding the right music for digital platforms hasn’t been easy. Music licensing complexities and the challenge of finding high-quality tracks that align with your brand standards can be overwhelming.&lt;/p&gt;
&lt;p&gt;But now, with our &lt;a href=&quot;https://www.soundstripe.com/blogs/how-to-use-soundstripe-video-0&quot;&gt;partnership with Soundstripe&lt;/a&gt;, you can effortlessly enhance your app with royalty-free music and video editing.&lt;/p&gt;
&lt;p&gt;Our mission has always been to provide the ultimate toolkit for building captivating creative experiences, and video editing plays a central role in achieving this. We recognize the significant role that music plays in video storytelling, as it has the power to evoke emotions, set the mood, tone, and atmosphere, and greatly influence the pacing and energy of a video. With Soundstripe’s diverse range of over 50 genres, your users will have no trouble finding the perfect track to complement their visual narrative.&lt;/p&gt;
&lt;h3 id=&quot;effortless-music-selection&quot;&gt;Effortless Music Selection&lt;/h3&gt;
&lt;p&gt;We have developed an &lt;strong&gt;intuitive search&lt;/strong&gt; interface that allows users to explore music by &lt;strong&gt;title, genre, and description&lt;/strong&gt; effortlessly. Once users have found their desired song, they can easily position any section of the track over their video. Furthermore, we are delighted to provide every one of our customers with seven complimentary sample songs, allowing them to get a taste of the fantastic library available. To unlock the full audio library, simply head over to Soundstripe and &lt;a href=&quot;https://www.soundstripe.com/enterprise-licensing&quot;&gt;request an API key&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We are eagerly looking forward to working closely with Soundstripe to deliver the most exceptional video editing experience on the market. We invite you to try out &lt;a href=&quot;https://img.ly/products/video-sdk/&quot;&gt;VideoEditor SDK&lt;/a&gt; in your Android or iOS app and witness the transformative impact it will have on your users’ creativity. Together, we can take your video editing capabilities to new heights.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thanks for reading! Stay ahead of the curve with our newsletter and &lt;a href=&quot;https://share.hsforms.com/1IgAOV1wASXGPnFG4ZPLejg1hk3i&quot;&gt;sign up&lt;/a&gt; now!&lt;/strong&gt;&lt;/p&gt;</content:encoded><dc:creator>Jan</dc:creator><media:content url="https://blog.img.ly/2023/06/soundstripe-app.jpg" medium="image"/><category>Video App</category><category>Royalty-Free Music</category><category>App Development</category><category>Mobile App Development</category><category>Video Editing</category><category>Company</category></item><item><title>FFmpeg - The Ultimate Guide</title><link>https://img.ly/blog/ultimate-guide-to-ffmpeg/</link><guid isPermaLink="true">https://img.ly/blog/ultimate-guide-to-ffmpeg/</guid><description>This guide covers the ins and outs of FFmpeg starting with fundamental concepts and moving to media transcoding and video and audio processing providing practical examples along the way.</description><pubDate>Mon, 21 Nov 2022 12:16:19 GMT</pubDate><content:encoded>&lt;p&gt;In this guide, we’ll go through the hot topics of FFmpeg. But before that, we’ll cover some base ground to help you understand basic media concepts and FFmpeg. Feel free to skip the parts that are already trivial for you!&lt;/p&gt;
&lt;h2 id=&quot;introduction-to-ffmpeg&quot;&gt;Introduction to FFmpeg&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://ffmpeg.org/about.html&quot;&gt;FFmpeg.org&lt;/a&gt;’s definition is the following: “FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation.”&lt;/p&gt;
&lt;p&gt;I think of FFmpeg as the go-to application for audio/video manipulation in an automated or scripted manner.&lt;/p&gt;
&lt;p&gt;When you need to implement a service that manipulates video, or just have 300 media files that need to be converted into a different format, FFmpeg is your - nerdy - friend.&lt;/p&gt;
&lt;p&gt;FFmpeg can do large chunks of the basic functionalities of a modern Non-linear (NLE) video editors, e.g., Davinci Resolve Studio or Premiere Pro. But, it does not have a graphical interface in that sense as those behemoths do, and unarguably it is way less friendly.&lt;/p&gt;
&lt;p&gt;In a general NLE, you might do things like these:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click to import a file&lt;/li&gt;
&lt;li&gt;Drop it into the timeline&lt;/li&gt;
&lt;li&gt;Trim and Cut&lt;/li&gt;
&lt;li&gt;Add an overlay image&lt;/li&gt;
&lt;li&gt;Crop that overlay&lt;/li&gt;
&lt;li&gt;Add vignette&lt;/li&gt;
&lt;li&gt;Add some color changing effects, e.g. change the hue&lt;/li&gt;
&lt;li&gt;Add an extra audio track to the mix&lt;/li&gt;
&lt;li&gt;Change the volume&lt;/li&gt;
&lt;li&gt;Add some effects, e.g.: echo&lt;/li&gt;
&lt;li&gt;Export into various formats&lt;/li&gt;
&lt;li&gt;Export into a deployable video format&lt;/li&gt;
&lt;li&gt;Export the master audio in wav&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Learn how to &lt;a href=&quot;https://img.ly/blog/how-to-crop-and-trim-videos-in-flutter/#get-started&quot;&gt;crop and trim videos in Flutter&lt;/a&gt;. Or, to achieve the exact same thing, you could also execute this command:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    -ss&lt;/span&gt;&lt;span&gt; 20&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 60&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    -i&lt;/span&gt;&lt;span&gt; train.jpg&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    -ss&lt;/span&gt;&lt;span&gt; 4&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; voice_recording.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    -filter_complex&lt;/span&gt;&lt;span&gt; &quot;[0:v]hue=h=80:s=1[main] ; [1:v]crop=w=382:h=304:x=289:y=227[train] ; [main][train]overlay=x=200:y=200,vignette=PI/4[video] ; [2:a]volume=1.5,aecho=0.8:0.9:100:0.3[speech] ; [0:a][speech]amix=duration=shortest,asplit[audio1][audio2]&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    -map&lt;/span&gt;&lt;span&gt; &apos;[video]&apos;&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; &apos;[audio1]&apos;&lt;/span&gt;&lt;span&gt; -metadata&lt;/span&gt;&lt;span&gt; title=&quot;Editor&apos;s cut&quot;&lt;/span&gt;&lt;span&gt; bbb_edited.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    -map&lt;/span&gt;&lt;span&gt; &apos;[audio2]&apos;&lt;/span&gt;&lt;span&gt; bbb_edited_audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yes, it isn’t friendly at all, but it is very, very powerful once you become friends with FFmpeg.&lt;/p&gt;
&lt;p&gt;Check out this comparison of the original and the edited one:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1520px) 1520px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1520&quot; height=&quot;488&quot; src=&quot;https://img.ly/_astro/img-1-edit-before-after_Z1QXYCT.webp&quot; srcset=&quot;/_astro/img-1-edit-before-after_ZGfT24.webp 640w, /_astro/img-1-edit-before-after_27k274.webp 750w, /_astro/img-1-edit-before-after_oiRf3.webp 828w, /_astro/img-1-edit-before-after_XVrkH.webp 1080w, /_astro/img-1-edit-before-after_1CaUoV.webp 1280w, /_astro/img-1-edit-before-after_Z1QXYCT.webp 1520w&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you want to try this command out, get the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#example-material&quot;&gt;example&lt;/a&gt; files and see it for yourself!&lt;/p&gt;
&lt;h3 id=&quot;installing-ffmpeg&quot;&gt;Installing FFmpeg&lt;/h3&gt;
&lt;p&gt;FFmpeg is available for most common and even uncommon platforms and architectures. You can be on Linux, Mac OS X or Microsoft Windows, and you’ll be able to run or link to FFmpeg.&lt;/p&gt;
&lt;p&gt;Installing FFmpeg is easy on most platforms! There is no installer, usually just a compressed archive you need to get for your platform and architecture.&lt;/p&gt;
&lt;p&gt;In the case of Linux, most distributions include a pre-built FFmpeg in their software repositories. Therefore, you can install FFmpeg from those even more quickly.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/download.html#build-windows&quot;&gt;Download for Microsoft Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/download.html#build-mac&quot;&gt;Download for Mac&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/download.html#build-linux&quot;&gt;Download for Linux&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;ffmpeg-history&quot;&gt;FFmpeg history&lt;/h3&gt;
&lt;p&gt;The project was started in 2000 by the awesome &lt;a href=&quot;https://bellard.org&quot;&gt;Fabrice Bellard&lt;/a&gt;. The name is a concatenation of “FF” meaning “fast-forward” and MPEG, the name of a video standards group. It has been very well, active and alive since then, &lt;a href=&quot;https://ffmpeg.org/releases/&quot;&gt;releasing&lt;/a&gt; a new release about every three months.&lt;/p&gt;
&lt;h3 id=&quot;ffmpeg-supported-codecs-and-formats&quot;&gt;FFmpeg supported codecs and formats&lt;/h3&gt;
&lt;p&gt;The default FFmpeg shipped with my Ubuntu Linux distribution supports about 460 codecs and 370 formats.&lt;/p&gt;
&lt;p&gt;See it for yourself:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -codecs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -formats&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;compilation-of-ffmpeg&quot;&gt;Compilation of FFmpeg&lt;/h3&gt;
&lt;p&gt;Keep in mind that the supported codecs and formats (and filters, demuxers, muxers, input and output methods, etc.) are highly dependent on the so-called compilation flags.&lt;/p&gt;
&lt;p&gt;This means that the above number only represents the fact that it supports at least this many codecs and formats. Still, there are even more that the package builders excluded for various reasons, e.g.: licensing, architecture, size considerations, etc.&lt;/p&gt;
&lt;p&gt;Since FFmpeg is &lt;a href=&quot;https://ffmpeg.org/download.html#repositories&quot;&gt;open source&lt;/a&gt;, you can &lt;a href=&quot;https://trac.ffmpeg.org/wiki/CompilationGuide&quot;&gt;compile FFmpeg&lt;/a&gt; for yourself at any time.&lt;/p&gt;
&lt;p&gt;Suppose for example, that you care about your layer’s size (therefore the bootstrap speed) in AWS Lambda. In this case, you can compile an FFmpeg binary that only contains the mp3 encoder for example, and nothing else. For a full tutorial on &lt;a href=&quot;https://img.ly/blog/how-to-run-ffmpeg-on-aws-spot-instances-for-scalable-low-cost-video-processing/&quot;&gt;running FFmpeg on AWS Spot Instances&lt;/a&gt;, see our cloud guide. Prefer Google Cloud? Our guide on &lt;a href=&quot;https://img.ly/blog/ffmpeg-on-google-cloud-platform-guide/&quot;&gt;running FFmpeg on Google Cloud Platform&lt;/a&gt; shows you how.&lt;/p&gt;
&lt;p&gt;Also, you might not want to run into licensing issues and leave out stuff that would cause problems for your use case. Therefore you choose to leave out particular codecs/formats. I highly recommend checking out the “—enable-gpl”, “—enable-nonfree” and “—enable-version3” &lt;a href=&quot;https://github.com/FFmpeg/FFmpeg/blob/master/configure&quot;&gt;compilation flags&lt;/a&gt; in this case, as well as &lt;a href=&quot;https://ffmpeg.org/legal.html&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Or you might want to have a standalone FFmpeg binary in your project (e.g.: embedded, or some cloud instance), that does not depend on any operating system libraries. Then you want to make a so-called static build, that compiles in all the libraries into a single binary file, and does not depend on your OS’ libraries and the runtime loading of other FFmpeg libraries. Search around for “—enable-static” in this case.&lt;/p&gt;
&lt;p&gt;Finally, you can find pre-built static FFmpeg builds &lt;a href=&quot;https://johnvansickle.com/ffmpeg/&quot;&gt;right here&lt;/a&gt; too. Alternatively, you can &lt;a href=&quot;https://img.ly/blog/how-to-run-ffmpeg-inside-a-docker-container/&quot;&gt;package FFmpeg in a Docker container&lt;/a&gt; for consistent environments - our Docker guide covers this approach.&lt;/p&gt;
&lt;h3 id=&quot;ffmpegs-strengths&quot;&gt;FFmpeg’s strengths&lt;/h3&gt;
&lt;p&gt;FFmpeg reads and writes most video and audio formats that matter for most of us. It is a very capable and high-performance tool for converting and manipulating these formats.&lt;/p&gt;
&lt;p&gt;But FFmpeg can do even more! For examples of these operations integrated into an automated pipeline, read our article on a &lt;a href=&quot;https://img.ly/blog/building-a-production-ready-batch-video-processing-server-with-ffmpeg/&quot;&gt;batch video processing server.&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;filtering&quot;&gt;Filtering&lt;/h3&gt;
&lt;p&gt;FFmpeg has vast amounts of filters for audio and video. Therefore, video manipulation is also a key feature of FFmpeg.&lt;/p&gt;
&lt;h3 id=&quot;hardware-acceleration&quot;&gt;Hardware acceleration&lt;/h3&gt;
&lt;p&gt;It does support many kinds of hardware accelerations! Video encoding is a very resource-intensive operation, and you might come across quite a few hardware devices or features that might speed up your process!&lt;/p&gt;
&lt;p&gt;Most notably, if you have an NVIDIA card, you can increase your H.264 or H.265 encoding and decoding throughput by multipliers compared to your CPU. But other things, such as VDPAU, VAAPI, or OpenCL, can be leveraged to boost your pipeline’s throughput.&lt;/p&gt;
&lt;p&gt;Learn more about the supported hardware acceleration methods &lt;a href=&quot;https://trac.ffmpeg.org/wiki/HWAccelIntro&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;versatile-inputoutput-methods&quot;&gt;Versatile input/output methods&lt;/h3&gt;
&lt;p&gt;FFmpeg is also very capable when it comes to accessing input and output data.&lt;/p&gt;
&lt;p&gt;Just to name a few: it can use your webcam, record from your microphone, grab your screen, or capture from your Blackmagic DeckLink. But FFmpeg can download directly from a web address, open all kinds of streams, read from a pipe, a socket, and of course, from files.&lt;/p&gt;
&lt;p&gt;The same holds true for outputting the data. It can write to your webcam, play audio on your microphone… Just kidding:) It can output to files, streams, pipes, sockets and so on.&lt;/p&gt;
&lt;h3 id=&quot;running-example-commands&quot;&gt;Running example commands&lt;/h3&gt;
&lt;p&gt;This article is full of FFmpeg commands that are working examples. The reason for that is that you could test these out for yourself! But the command line interfaces of different operating systems are slightly different, so the commands in this article are meant to be executed in a Linux bash shell.&lt;/p&gt;
&lt;p&gt;To adopt these command lines to Microsoft Windows, you might need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Change (cd) into the directory where you extracted the ffmpeg.exe. Alternatively, add that directory to the &lt;a href=&quot;https://duckduckgo.com/?t=ffab&amp;#x26;q=add+binary+to+path+windows&quot;&gt;path&lt;/a&gt; to make it callable from anywhere.&lt;/li&gt;
&lt;li&gt;You might need to replace “ffmpeg” to “ffmpeg.exe”&lt;/li&gt;
&lt;li&gt;You will need to replace ”&lt;strong&gt;\&lt;/strong&gt;“-s (backslashes) at the end of the lines with ”&lt;strong&gt;^&lt;/strong&gt;“-s (hats)&lt;/li&gt;
&lt;li&gt;You’ll need to replace the &lt;code&gt;fontfile&lt;/code&gt; argument’s value to something like this: &lt;code&gt;fontfile=/Windows/Fonts/arial.ttf&lt;/code&gt; to get commands with the drawtext filter working.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;MacOS users will need steps #1 and #4.&lt;/p&gt;
&lt;h2 id=&quot;introduction-to-media-concepts&quot;&gt;Introduction to media concepts&lt;/h2&gt;
&lt;p&gt;Now let’s have a quick overview of media concepts. These concepts will be vital for us if we want to understand the latter sections of this article and FFmpeg’s workings. To keep this section brief, it is a higher-level, simplified explanation of these concepts.&lt;/p&gt;
&lt;h3 id=&quot;audio&quot;&gt;Audio&lt;/h3&gt;
&lt;p&gt;We’ll briefly cover the following terms:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sampling rate&lt;/li&gt;
&lt;li&gt;Bitrate&lt;/li&gt;
&lt;li&gt;Channels&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;sampling-rate&quot;&gt;Sampling Rate&lt;/h3&gt;
&lt;p&gt;The sampling rate is the factor that shows how many times we measure/scan/sample the input data stream.&lt;/p&gt;
&lt;p&gt;The image below shows the measurement windows (quantization) as gray bars.&lt;/p&gt;
&lt;p&gt;Why does this matter? Because it is a balancing act. If we measure the signal less often, we’ll lose more details (bad). Also, by having fewer samples, we’ll have less data in the end. Therefore the file size will be smaller (good).&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1600px) 1600px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://img.ly/_astro/img-2-sampling-rate_16IiDT.webp&quot; srcset=&quot;/_astro/img-2-sampling-rate_ZEjEs8.webp 640w, /_astro/img-2-sampling-rate_2lFo7Q.webp 750w, /_astro/img-2-sampling-rate_ZptRzw.webp 828w, /_astro/img-2-sampling-rate_2dctkz.webp 1080w, /_astro/img-2-sampling-rate_ZlnVMi.webp 1280w, /_astro/img-2-sampling-rate_16IiDT.webp 1600w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Here are some ballpark values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;8 kHz (GSM - Low quality)&lt;/li&gt;
&lt;li&gt;44.1 kHz (CD - High quality)&lt;/li&gt;
&lt;li&gt;48 kHz (Very high quality)&lt;/li&gt;
&lt;li&gt;88.2 kHz (Insane - usually for production only)&lt;/li&gt;
&lt;li&gt;96 kHz (Insane - usually for production only)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are no definite “right answers” here. The question is what is “good enough” for your use case? GSM focuses on speech, and not even quality but understandability and the least possible amount of data. Therefore, they found that 8 kHz is enough (there are quite a few more tricks), for their purposes.&lt;/p&gt;
&lt;p&gt;The “CD quality” aimed for high quality. Therefore they chose 44.1 kHz, that number has some history in it, but the main reason for aiming above 40 kHz lies in physics and how the human ear works.&lt;/p&gt;
&lt;p&gt;There were two very smart guys whose &lt;a href=&quot;https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem&quot;&gt;theorem&lt;/a&gt; basically says that if you want a quite good signal representation, you have to sample it at twice the speed as its original frequency. Human hearing generally &lt;a href=&quot;https://en.wikipedia.org/wiki/Hearing_range&quot;&gt;works&lt;/a&gt; up until about 20 kHz, so if you want “good quality”, you should aim for at least 40 kHz. And 40 kHz + some headroom + some more physics + historical reasons = 44.1 kHz! :)&lt;/p&gt;
&lt;p&gt;As for the higher rates, those are only used when very high-quality audio editing is needed.&lt;/p&gt;
&lt;h3 id=&quot;bitrate&quot;&gt;Bitrate&lt;/h3&gt;
&lt;p&gt;Bitrate represents the amount of data per second that results from our transcoding/quantization process. If it is 1411 kbit/s, that means that for every second of audio data, about 1411 kbit of output data will be produced.&lt;/p&gt;
&lt;p&gt;Therefore, you can say that 1 minute of audio with 1411 kbit/sec will require:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;(1411 kbit / 8) kbyte * 60 second = 10582 kbyte = 10.33 mbyte&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, it is only easy like that with raw audio data and with a few simple codecs, e.g. PCM in WAVs.&lt;/p&gt;
&lt;p&gt;Codecs compressing hard might throw your numbers around a little, as input data might be compressible with different rates. Variable bitrate is usually happening to save space. The encoder might output a lower bitrate if the data is “simple” and does not require high precision.&lt;/p&gt;
&lt;p&gt;Here are some ballpark values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;13 kbits/s (GSM quality)&lt;/li&gt;
&lt;li&gt;320 kbit/s (High-quality MP3)&lt;/li&gt;
&lt;li&gt;1411 kbit/s (16bit WAV, CD quality, PCM)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;channels&quot;&gt;Channels&lt;/h3&gt;
&lt;p&gt;Inside of most audio formats, you can have more audio channels. This means multiple, separated audio streams can be in the same file.&lt;/p&gt;
&lt;p&gt;Many times, multiple channels have their own name:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you have a single microphone, you will most probably record it into a single channel called Mono.&lt;/li&gt;
&lt;li&gt;General music from the FM radio or streaming services usually has two channels in a so-called “Stereo” configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With stereo, there could be several methods how the audio “image” can be made richer by leveraging audio &lt;a href=&quot;https://en.wikipedia.org/wiki/Panning%5F(audio)&quot;&gt;panning&lt;/a&gt;, time and phase-shifting and much more. There is a special recording technique too, called &lt;a href=&quot;https://en.wikipedia.org/wiki/Binaural_recording&quot;&gt;Binaural recording&lt;/a&gt;, which is super awesome. Wear headphones for &lt;a href=&quot;https://www.youtube.com/watch?v=aQH-jwE_kfo&quot;&gt;this&lt;/a&gt;, and don’t be scared:)&lt;/p&gt;
&lt;p&gt;For example, here are &lt;a href=&quot;https://peach.blender.org/&quot;&gt;Big Buck Bunny&lt;/a&gt;’s audio waveforms in &lt;a href=&quot;https://www.audacityteam.org/&quot;&gt;Audacity&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1756px) 1756px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1756&quot; height=&quot;307&quot; src=&quot;https://img.ly/_astro/img-3-waveforms_QyR5N.webp&quot; srcset=&quot;/_astro/img-3-waveforms_d7t0d.webp 640w, /_astro/img-3-waveforms_20zbLg.webp 750w, /_astro/img-3-waveforms_2hIR4S.webp 828w, /_astro/img-3-waveforms_1Awtx2.webp 1080w, /_astro/img-3-waveforms_Z31aji.webp 1280w, /_astro/img-3-waveforms_UYkTp.webp 1668w, /_astro/img-3-waveforms_QyR5N.webp 1756w&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can see that there are two lines of waveforms and also that they are pretty similar. That is normal, as you usually hear the same thing with your two ears, but the matter is in the subtle differences between the two. That’s where directionality, richness, and all kinds of other effects lie.&lt;/p&gt;
&lt;p&gt;But why stop at two? The list continues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2.1, as it is often called, means three channels: 2 for stereo and one for the LFE (“low-frequency effects” a.k.a.: “bass”).&lt;/li&gt;
&lt;li&gt;5.1 is similar, with five directional channels (2 front, 1 center, 2 rear) and the LFE.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So channels are just separate “recordings” or “streams” of audio signals.&lt;/p&gt;
&lt;h3 id=&quot;image-properties&quot;&gt;Image properties&lt;/h3&gt;
&lt;p&gt;For images, there are quite a few parameters, but we’ll check out only these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Resolution&lt;/li&gt;
&lt;li&gt;Bit-depth&lt;/li&gt;
&lt;li&gt;Transparency&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;resolution&quot;&gt;Resolution&lt;/h3&gt;
&lt;p&gt;An image consists of pixels, single points that have a single color. The resolution of an image determines how many columns and rows of pixels are in an image. In other words: an image has a width and a height.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1520px) 1520px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1520&quot; height=&quot;572&quot; src=&quot;https://img.ly/_astro/img-4-resolution-1_Z28Fb9g.webp&quot; srcset=&quot;/_astro/img-4-resolution-1_2oaDvQ.webp 640w, /_astro/img-4-resolution-1_Z1a5LF7.webp 750w, /_astro/img-4-resolution-1_2cdshh.webp 828w, /_astro/img-4-resolution-1_Z2vj565.webp 1080w, /_astro/img-4-resolution-1_Zv4bSK.webp 1280w, /_astro/img-4-resolution-1_Z28Fb9g.webp 1520w&quot;&gt;&lt;/p&gt;
&lt;p&gt;This image shows the first 10 pixels in the first row.&lt;/p&gt;
&lt;p&gt;Here are some ballpark values for resolution:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“HD” or “Full HD” or “1K” or “1080p” means 1920x1080 pixels.&lt;/li&gt;
&lt;li&gt;“4K” could mean a few values, but it should be about 3840x2160 pixels.&lt;/li&gt;
&lt;li&gt;A regular 16mp photo you make of your cat is about 4608x3456 pixels.&lt;/li&gt;
&lt;li&gt;General social media image posts are about 1080x1080 pixels.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;bit-depth&quot;&gt;Bit-depth&lt;/h3&gt;
&lt;p&gt;Bit-depth represents the number of bits used for storing a single pixel’s color value. This is the same balancing game, and you need to decide between quality or file size.&lt;/p&gt;
&lt;p&gt;General ballpark values for bit-depth:&lt;/p&gt;






























&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Bits&lt;/th&gt;&lt;th&gt;Colors&lt;/th&gt;&lt;th&gt;Notes&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;Black &amp;#x26; White&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;256&lt;/td&gt;&lt;td&gt;B/W or Limited color palette&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;24&lt;/td&gt;&lt;td&gt;16.7m&lt;/td&gt;&lt;td&gt;3x&lt;strong&gt;8 bit&lt;/strong&gt; for R-G-B “True color”&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;30&lt;/td&gt;&lt;td&gt;1073m&lt;/td&gt;&lt;td&gt;3x&lt;strong&gt;10 bit&lt;/strong&gt; for R-G-B “Deep color”&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;These last two sometimes are referred to as “8 bit” or “10 bit” respectively, especially when talking about videos. That means 8/10 bits per single color channel.&lt;/p&gt;
&lt;h3 id=&quot;transparency&quot;&gt;Transparency&lt;/h3&gt;
&lt;p&gt;Some image formats support an additional channel together with the red, green, and blue components: the alpha channel. The alpha channel determines how transparent a single pixel is, and it can have different bit-depths, it is usually either 1, 8 or 16 bits.&lt;/p&gt;
&lt;p&gt;If the alpha channel is 1 bit, then the format can encode a pixel to be either transparent or non-transparent. If it is 8 or more bits, then the format can encode 256 or more steps of transparency.&lt;/p&gt;
&lt;h3 id=&quot;video-properties&quot;&gt;Video properties&lt;/h3&gt;
&lt;p&gt;Video data is built by single images shown right after each other. This brings in most attributes of images and a few more!&lt;/p&gt;
&lt;p&gt;So a video has a &lt;code&gt;resolution&lt;/code&gt; that is its width and height.&lt;/p&gt;
&lt;p&gt;Then the first obvious parameter of a video is the &lt;code&gt;framerate&lt;/code&gt;, which defines how many images are shown in a second. Common values for this are 24, 25, 30, or 60.&lt;/p&gt;
&lt;p&gt;A video file also has a &lt;code&gt;codec&lt;/code&gt; assigned to it, which is the format describing how all those images were compressed into this video file. There are many more attributes of videos, but this is a good start.&lt;/p&gt;
&lt;h3 id=&quot;video-codecs&quot;&gt;Video codecs&lt;/h3&gt;
&lt;p&gt;Compression is a super important thing when it comes to video because you have thousands of images to keep together. If you aren’t doing it in a smart way, then the resulting video will be very, very large.&lt;/p&gt;
&lt;p&gt;Just imagine a 2-minute video, with 30 fps. That means it will have 60 s * 2 * 30 fps = 3600 frames! I have just taken a screenshot of an HD video, which was 730 kbyte in JPEG format. Now 3600 frame * 730 kbyte equals 2.5 gigabytes!&lt;/p&gt;
&lt;p&gt;Can you imagine that? I hope not, and that’s because compression brings that way, way down, to the level of tens of megabytes. These days a video of that size is quite high quality and about 2 hours long. Also, don’t forget, that JPEG is already compressed, a single frame would be 6 mbyte when uncompressed. Now that 2-minute video would be 21 gigabytes if we’d store it uncompressed.&lt;/p&gt;
&lt;p&gt;Standard codecs such as H.264 and H.265 are doing very clever and complex operations to achieve high compression ratios with good quality.&lt;/p&gt;
&lt;p&gt;Just think about that, most frames in a video are quite similar, only containing small differences. So if we could only store that little difference between frames, we’d won a huge bonus! And that’s just one of the many tricks codecs do.&lt;/p&gt;
&lt;p&gt;Codec designers are also exploiting the weaknesses and features of the human eye. Such as the fact that we are more sensitive to light intensity changes than color changes (say hello to &lt;a href=&quot;https://en.wikipedia.org/wiki/YUV&quot;&gt;YUV&lt;/a&gt;). And they can get away with lower quality details for parts &lt;a href=&quot;https://en.wikipedia.org/wiki/Motion_blur#Biology&quot;&gt;that are moving fast&lt;/a&gt;, and so on.&lt;/p&gt;
&lt;p&gt;Because why lose precious bits for things that you can’t even notice?!&lt;/p&gt;
&lt;p&gt;There are many codecs out there, with different goals in mind, although the majority focus on keeping the file size low.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;H.264, H.265: These are the most common ones, with the widest support in browsers, phones, players, etc. It focuses on small file sizes with good quality. (At the cost of resource intensiveness.)&lt;/li&gt;
&lt;li&gt;Apple ProRes, DNxHD: These are common formats for production. They focus on quality and ease of processing and not on file size.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;audio-codecs&quot;&gt;Audio codecs&lt;/h3&gt;
&lt;p&gt;The goal of audio codecs is the same as what we saw with the video codecs. It is just harder to demonstrate it as audio does not consist of single image frames but audio frames/packets. So an analog audio signal is of an almost infinite, or at least very high quality if you think of it.&lt;/p&gt;
&lt;p&gt;At the lowest level, the speed and amplitude resolution is very high. We could say “atomic”, as we need to measure and store the speed and direction of atoms. So if you want to store that exactly, that will require a super high-quality measurement, which will also result in a very high bitrate data stream.&lt;/p&gt;
&lt;p&gt;Thankfully, the sound is at least not propagating with light speed so we can save quite a lot just by that fact. (There’s no need for an extreme sampling rate.) Then our hearing is very limited if we take the previous paragraph as a scale, so we win there again. We don’t need most of that high precision that is there.&lt;/p&gt;
&lt;p&gt;But still, if we take our hearing capability and want to store raw audio data with about 44.1 kHz of sample rate with about 1 Mbit/sec bitrate, we’d still get quite a lot of data. Check the calculations in the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#bitrate&quot;&gt;audio bitrate&lt;/a&gt; section above.&lt;/p&gt;
&lt;p&gt;So raw audio can be compressed further, which is what many popular codecs do. They also exploit the human senses, but this time the human ear. We started with the basics that the human ear has a limit on the frequencies it can detect. Therefore, we can save a lot by cutting out the range of frequencies outside our hearing range. Unless you are a bat, you are fine between 20-20khz! :)&lt;/p&gt;
&lt;p&gt;But there are other tricks, for example, &lt;a href=&quot;https://en.wikipedia.org/wiki/Auditory_masking&quot;&gt;auditory masking&lt;/a&gt;. That means that the presence of one frequency can affect your capability to detect a different frequency. From the codec’s viewpoint, it can skip encoding a few frequencies if it is smart enough to know which ones you’ll not notice. I’m sure there are a lot more tricks, let me know if you know about a few more interesting ones!&lt;/p&gt;
&lt;p&gt;Here is a list of common codecs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MP3, AAC, OGG: These are common lossy audio formats.&lt;/li&gt;
&lt;li&gt;PCM (e.g. in a WAV container), FLAC: These are lossless formats.&lt;/li&gt;
&lt;li&gt;MIDI: It is a funny format. It is like a music sheet that might sound different on different players or settings. It is usually not made from real audio data, but from recording a digital keyboard or as an output from an audio composing software.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;containers&quot;&gt;Containers&lt;/h3&gt;
&lt;p&gt;Now we got through the fundamental building blocks, the image, the video, the video codecs, and the audio codecs, and we reached the top of this iceberg: the containers.&lt;/p&gt;
&lt;p&gt;A container is a format specification, that combines all these streams into a single file format. It defines how to put all these data together, how to attach metadata (e.g. author, description, etc), how to synchronize these streams, and sometimes a container even contains indexes to aid seeking.&lt;/p&gt;
&lt;p&gt;So, for example, a MOV container can contain an H.264 video stream and an AAC audio stream together.&lt;/p&gt;
&lt;p&gt;Common containers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MOV&lt;/li&gt;
&lt;li&gt;MP4&lt;/li&gt;
&lt;li&gt;MKV&lt;/li&gt;
&lt;li&gt;WebM&lt;/li&gt;
&lt;li&gt;WAV (audio only)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;example-material&quot;&gt;Example Material&lt;/h2&gt;
&lt;p&gt;I will use these example materials as inputs in the following parts of this article. If you’d like to follow along, save these files for yourself!&lt;/p&gt;





























&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Resource&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Big Buck Bunny&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4&quot;&gt;http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Train&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-examples/train.jpg&quot;&gt;train.jpg&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Smiley&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-examples/smiley.png&quot;&gt;smiley.png&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Voice recording&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-examples/voice_recording.wav&quot;&gt;voice_recording.wav&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Big Buck Bunny’s audio&lt;/td&gt;&lt;td&gt;ffmpeg -i bbb_sunflower_1080p_60fps_normal.mp4 -map 0:1 bbb_audio.wav&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;n&lt;/p&gt;
&lt;p&gt;And we will make our own audio file by extracting the audio from the Big Buck Bunny movie! We’ll use this file as an example, so after downloading the video file, please execute this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:1&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By the middle of this article, you’ll understand this command, but for now, just make sure to have the WAV file next to your video file to test out the commands later in the article.&lt;/p&gt;
&lt;p&gt;We’ll use these files in the following parts of this article. Therefore make sure to get them!&lt;/p&gt;
&lt;h2 id=&quot;ffplay-and-ffprobe&quot;&gt;FFplay and FFprobe&lt;/h2&gt;
&lt;p&gt;FFmpeg is the name of the main binary and the project itself, but it is shipped together with two other binaries, ffplay and ffprobe.&lt;/p&gt;
&lt;p&gt;Let’s check them out quickly, right in the command line!&lt;/p&gt;
&lt;h3 id=&quot;ffplay&quot;&gt;FFplay&lt;/h3&gt;
&lt;p&gt;FFplay is a basic video player, that can be used for playing media. It’s not a friendly video player, but it is a good testing ground for various things.&lt;/p&gt;
&lt;p&gt;To execute it, just simply supply a media file:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffplay&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want to test this exact command, you’ll need to get the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#example-material&quot;&gt;example&lt;/a&gt; files.&lt;/p&gt;
&lt;p&gt;For example, it can be used to preview filters (we’ll discuss those &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#filtering&quot;&gt;later&lt;/a&gt;), but let’s see an example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffplay&lt;/span&gt;&lt;span&gt; -vf&lt;/span&gt;&lt;span&gt; &quot;drawtext=text=&apos;HELLO THERE&apos;:y=h-text_h-10:x=(w/2-text_w/2):fontsize=200:f&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1962px) 1962px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1962&quot; height=&quot;1145&quot; src=&quot;https://img.ly/_astro/img-5-big-bunny_Z1KSyDO.webp&quot; srcset=&quot;/_astro/img-5-big-bunny_Z2tEJ77.webp 640w, /_astro/img-5-big-bunny_Z2gSLvG.webp 750w, /_astro/img-5-big-bunny_1Aamch.webp 828w, /_astro/img-5-big-bunny_Z14XPyG.webp 1080w, /_astro/img-5-big-bunny_1Yyeb4.webp 1280w, /_astro/img-5-big-bunny_1AAWwo.webp 1668w, /_astro/img-5-big-bunny_Z1KSyDO.webp 1962w&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;ffprobe&quot;&gt;FFprobe&lt;/h3&gt;
&lt;p&gt;FFprobe, as its name implies, is a tool for getting information about media files.&lt;/p&gt;
&lt;p&gt;This command:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffprobe&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Will return us some general information about the video file:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &apos;bbb_sunflower_1080p_60fps_normal.mp4&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Metadata:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    title           : Big Buck Bunny, Sunflower version&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:0[0x1](und): Video: h264 [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:1[0x2](und): Audio: mp3 [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:2[0x3](und): Audio: ac3 [...]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have abbreviated it heavily, as we’ll check this out later.&lt;/p&gt;
&lt;p&gt;But FFprobe is way more powerful than just this!&lt;/p&gt;
&lt;p&gt;With the following command, we can get the same listing in JSON format, which is machine-readable!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffprobe&lt;/span&gt;&lt;span&gt; -v&lt;/span&gt;&lt;span&gt; error&lt;/span&gt;&lt;span&gt; -hide_banner&lt;/span&gt;&lt;span&gt; -print_format&lt;/span&gt;&lt;span&gt; json&lt;/span&gt;&lt;span&gt; -show_streams&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The explanation of this command is the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“&lt;strong&gt;-v error -hide_banner&lt;/strong&gt;”: This part hides extra output, such as headers and the default build information.&lt;/li&gt;
&lt;li&gt;“&lt;strong&gt;-print_format json&lt;/strong&gt;”: Obviously, this causes ffprobe to output a JSON.&lt;/li&gt;
&lt;li&gt;“&lt;strong&gt;-show_streams&lt;/strong&gt;” is the main switch that requests the stream information.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  &quot;streams&quot;&lt;/span&gt;&lt;span&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;index&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;codec_name&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;h264&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;codec_long_name&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;width&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;1920&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;height&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;1080&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;bit_rate&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;4001453&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;duration&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;634.533333&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;############################&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;[~50 lines removed]&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;index&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;codec_name&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;mp3&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;channels&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;bit_rate&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;160000&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;############################&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;[~40 lines removed]&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;index&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;codec_name&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;ac3&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;channels&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;6&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;############################&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;[~20 lines removed]&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this output, you can see three streams of data in this video file. The first (index: 0) is a video stream, that is an HD video with an H.264 codec. Then we have two audio streams, the first (index: 1) is a simple mp3 stream with stereo audio, and the second (index: 2) is an ac3 stream with 6 channels, most likely in an 5.1 configuration.&lt;/p&gt;
&lt;p&gt;I have removed quite a lot of output for brevity, but you can get way more information out of these streams, e.g. fps for the video stream and so on.&lt;/p&gt;
&lt;p&gt;Other than &lt;strong&gt;-show_streams&lt;/strong&gt;, there are 3 more: &lt;strong&gt;-show_format&lt;/strong&gt;, &lt;strong&gt;-show_packets&lt;/strong&gt; and &lt;strong&gt;-show_frames&lt;/strong&gt;. Unless you are really deep in the rabbit hole, you’ll not need the last two, but &lt;strong&gt;-show_format&lt;/strong&gt; could be useful:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffprobe&lt;/span&gt;&lt;span&gt; -v&lt;/span&gt;&lt;span&gt; error&lt;/span&gt;&lt;span&gt; -hide_banner&lt;/span&gt;&lt;span&gt; -print_format&lt;/span&gt;&lt;span&gt; json&lt;/span&gt;&lt;span&gt; -show_format&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  &quot;format&quot;&lt;/span&gt;&lt;span&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;filename&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;bbb_sunflower_1080p_60fps_normal.mp4&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;nb_streams&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;nb_programs&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;format_name&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;mov,mp4,m4a,3gp,3g2,mj2&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;format_long_name&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;QuickTime / MOV&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;start_time&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;0.000000&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;duration&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;634.533333&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;size&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;355856562&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;bit_rate&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;4486529&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;probe_score&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;100&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    &quot;tags&quot;&lt;/span&gt;&lt;span&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;major_brand&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;isom&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;minor_version&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;1&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;compatible_brands&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;isomavc1&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;creation_time&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;2013-12-16T17:59:32.000000Z&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;title&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;Big Buck Bunny, Sunflower version&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;artist&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;Blender Foundation 2008, Janus Bager Kristensen 2013&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;comment&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;genre&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;Animation&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      &quot;composer&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;&quot;Sacha Goedegebure&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is an overview of “what is this file”. As we see, it is a MOV file (format_name), with three streams (nb_streams), and it is 634 seconds long. Also, there are some tags where we can see the title, the artist, and other information.&lt;/p&gt;
&lt;h2 id=&quot;ffmpeg-concepts&quot;&gt;FFmpeg concepts&lt;/h2&gt;
&lt;p&gt;Here is a quick intro to how FFmpeg actually works!&lt;/p&gt;
&lt;p&gt;For those who are just joining in: please get the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#example-material&quot;&gt;example assets&lt;/a&gt; if you want to test out the commands shown in this chapter!&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1592px) 1592px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1592&quot; height=&quot;948&quot; src=&quot;https://img.ly/_astro/img-6-input-output_1VpFon.webp&quot; srcset=&quot;/_astro/img-6-input-output_1ca7gh.webp 640w, /_astro/img-6-input-output_KPHvd.webp 750w, /_astro/img-6-input-output_1qXtyE.webp 828w, /_astro/img-6-input-output_8zrzA.webp 1080w, /_astro/img-6-input-output_Wreqk.webp 1280w, /_astro/img-6-input-output_1VpFon.webp 1592w&quot;&gt;&lt;/p&gt;
&lt;p&gt;FFmpeg opens the file, decodes it into memory, then encodes the in-memory packets back and puts them into some container: some output file. The term “codec” is a mix of the words “&lt;strong&gt;cod&lt;/strong&gt;er &amp;#x26; &lt;strong&gt;e&lt;/strong&gt;n&lt;strong&gt;c&lt;/strong&gt;oder”. Those are the magic parts before and after the “decoded frames”.&lt;/p&gt;
&lt;p&gt;The decoded frames are uncompressed images in-memory, e.g. the most basic pixel format for video frames is called “rgb24”. This just stores red, green, and blue values right after each other in 3x8 bits, or 3x1 byte, which could hold 16m colors.&lt;/p&gt;
&lt;p&gt;The importance of this is that other than &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#editing-without-reencoding&quot;&gt;a few exceptions&lt;/a&gt;, you can only manipulate or encode the decoded frames. So when we get to different audio/video filters or transcoding, you’ll need the decoded frames for all that. But don’t worry, FFmpeg does this automatically for you.&lt;/p&gt;
&lt;h3 id=&quot;inputs&quot;&gt;Inputs&lt;/h3&gt;
&lt;p&gt;So you see and probably guessed, that FFmpeg must access the input data somehow. FFmpeg knows how to handle most media files, as the awesome people who develop FFmpeg and the related libraries made encoders and decoders for most formats available!&lt;/p&gt;
&lt;p&gt;Don’t think that it is a trivial thing. Many formats are reverse engineered, a hard task requiring brilliant people.&lt;/p&gt;
&lt;p&gt;So although we often refer to input files, the input could come from many sources, such as the network, a hardware device and so on. We’ll learn more about that &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#inputs&quot;&gt;later&lt;/a&gt; on in this article.&lt;/p&gt;
&lt;p&gt;Many media files are containers for different streams, meaning that a single file might contain multiple streams of content.&lt;/p&gt;
&lt;p&gt;For example, a .mov file might contain one or more streams:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;video tracks&lt;/li&gt;
&lt;li&gt;audio tracks (e.g. for the different languages or audio formats such as stereo or 5.1)&lt;/li&gt;
&lt;li&gt;subtitle tracks&lt;/li&gt;
&lt;li&gt;thumbnails&lt;/li&gt;
&lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All these are streams of data from the viewpoint of FFmpeg. Input files and their streams are numerically differentiated with a 0-based index. So, for example, 1:0 means the first(0) stream of the second(1) input file. We’ll &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#mapping&quot;&gt;learn more&lt;/a&gt; about that later too!&lt;/p&gt;
&lt;p&gt;Important to note that FFmpeg can open any number of input files simultaneously, and the filtering and mapping will decide what it will do with those. Again more on that later!&lt;/p&gt;
&lt;h3 id=&quot;streams&quot;&gt;Streams&lt;/h3&gt;
&lt;p&gt;As we have seen in the previous section, streams are the fundamental building blocks of containers. So every input file must have at least one stream. And that’s what you can list by the simple &lt;code&gt;ffmpeg -i&lt;/code&gt; command for example.&lt;/p&gt;
&lt;p&gt;A stream might contain an audio format such as MP3, or a video format such as an H.264 stream.&lt;/p&gt;
&lt;p&gt;Also, a stream, depending on the codec, might contain multiple “things”. For example, an mp3 or a WAV stream might include various audio channels.&lt;/p&gt;
&lt;p&gt;So the building block hierarchy, in this case is: File → Stream → Channels.&lt;/p&gt;
&lt;h3 id=&quot;outputs&quot;&gt;Outputs&lt;/h3&gt;
&lt;p&gt;Of course, an output could be a local file, but it doesn’t need to be. It could be a socket, a stream and so on. In the same way as with inputs, you could have multiple outputs, and the mapping determines what goes into which output file.&lt;/p&gt;
&lt;p&gt;The output also must have some format or container. Most of the time FFmpeg can and will guess that for us, mostly from the extension, but we can specify it too.&lt;/p&gt;
&lt;h3 id=&quot;mapping&quot;&gt;Mapping&lt;/h3&gt;
&lt;p&gt;Mapping refers to the act of connecting input file streams with output file streams. So if you give 3 input files and 4 output files to FFmpeg, you must also define what should go to where.&lt;/p&gt;
&lt;p&gt;If you give a single input and a single output, then FFmpeg will guess it for you without specifying any mapping, but make sure you know how exactly that happens, to avoid surprises. More on all that later!&lt;/p&gt;
&lt;h3 id=&quot;filtering-1&quot;&gt;Filtering&lt;/h3&gt;
&lt;p&gt;Filtering stands for the feature of FFmpeg to modify the decoded frames (audio or video). Other applications might call them effects, but i’m sure there is a reason why FFmpeg calls them filters.&lt;/p&gt;
&lt;p&gt;There are two kinds of filtering supported by FFmpeg, simple and complex. In this article we’ll only discuss the complex filters, as it is a superset of the simple filters, and this way, we avoid confusion and redundant content.&lt;/p&gt;
&lt;p&gt;Simple filters are a single chain of filters between a single input and output. Complex filters can have more chains of filters, with any number of inputs and outputs.&lt;/p&gt;
&lt;p&gt;The following figure extends the previous overview image with the filtering module:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1686px) 1686px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1686&quot; height=&quot;1520&quot; src=&quot;https://img.ly/_astro/img-7-encode-decode_Z2fYIgb.webp&quot; srcset=&quot;/_astro/img-7-encode-decode_13jrWu.webp 640w, /_astro/img-7-encode-decode_1P8TzA.webp 750w, /_astro/img-7-encode-decode_ZMUCC2.webp 828w, /_astro/img-7-encode-decode_10OkPy.webp 1080w, /_astro/img-7-encode-decode_kekdC.webp 1280w, /_astro/img-7-encode-decode_KN3vN.webp 1668w, /_astro/img-7-encode-decode_Z2fYIgb.webp 1686w&quot;&gt;&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;complex filter graph&lt;/code&gt; is built from &lt;code&gt;filter chains&lt;/code&gt;, which are built from &lt;code&gt;filters&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So a single &lt;strong&gt;filter&lt;/strong&gt; does a single thing, for example, changes the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#volume&quot;&gt;volume&lt;/a&gt;. This filter is quite trivial, it has a single input, changes the volume, and it has a single output.&lt;/p&gt;
&lt;p&gt;For video, we could check out the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#scale&quot;&gt;scale&lt;/a&gt; filter, which is also quite straightforward: it has a single input, scales the incoming frames, and it has a single output too.&lt;/p&gt;
&lt;p&gt;You can &lt;strong&gt;chain&lt;/strong&gt; these filters, meaning that you connect the output of one to the input of the next one! So you can have a &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#volume&quot;&gt;volume&lt;/a&gt; filter after an &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#aecho&quot;&gt;echo&lt;/a&gt; filter, for example, and this way, you’ll add echo, and then you change the volume.&lt;/p&gt;
&lt;p&gt;This way, your chain will have a single input, and it will do several things with it and will output something at the end.&lt;/p&gt;
&lt;p&gt;Now, the “&lt;strong&gt;complex&lt;/strong&gt;” comes in when you have multiple chains of these filters!&lt;/p&gt;
&lt;p&gt;But before we go there, you should also know that some single filters might have multiple inputs or outputs!&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#overlay&quot;&gt;overlay&lt;/a&gt; filter puts 2 video streams above each other and will output a single video stream.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#split&quot;&gt;split&lt;/a&gt; filter splits a single video stream into 2+ video streams (by copying).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So let’s discuss a complex example from a bird’s eye view! I have two video files, I want to put them above each other, and I want the output in two files/sizes, 720p and 1080p.&lt;/p&gt;
&lt;p&gt;Now, that’s where complex filtering will be faithful to its name: to achieve this, you’ll need several filter chains!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Chain 1: &lt;code&gt;[input1.mp4] [input2.mp4]&lt;/code&gt; → &lt;strong&gt;overlay&lt;/strong&gt; → &lt;strong&gt;split&lt;/strong&gt; → &lt;code&gt;[overlaid1] [overlaid2]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Chain 2: &lt;code&gt;[overlaid1]&lt;/code&gt; → &lt;strong&gt;scale&lt;/strong&gt; → &lt;code&gt;[720p_output]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Chain 3: &lt;code&gt;[overlaid2]&lt;/code&gt; → &lt;strong&gt;scale&lt;/strong&gt; → &lt;code&gt;[1080p_output]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As you see, you can connect chains, and you can connect chains to output files. There is a rule that you can only consume a chain once, and that’s why we used split instead of the same input for chains 2 and 3.&lt;/p&gt;
&lt;p&gt;The takeaway is this: with complex filter graphs (and mapping), you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;build individual chains of filters&lt;/li&gt;
&lt;li&gt;connect input files to filter chains&lt;/li&gt;
&lt;li&gt;connect filter chains to filter chains&lt;/li&gt;
&lt;li&gt;connect filter chains to output files&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ffmpegs-command-line-system&quot;&gt;FFmpeg’s command line system&lt;/h2&gt;
&lt;p&gt;For those who are just joining in: please get the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#example-material&quot;&gt;example assets&lt;/a&gt; if you want to test out the commands shown in this chapter!&lt;/p&gt;
&lt;h3 id=&quot;ffmpeg-cli&quot;&gt;FFmpeg CLI&lt;/h3&gt;
&lt;p&gt;Finally, we arrived at FFmpeg, and trust me, we’ll execute it quite a lot of times! Let’s see how FFmpeg’s command line options are organized, as that is the first tricky part we need to understand!&lt;/p&gt;
&lt;p&gt;FFmpeg mostly thinks about input and output files and their options together with global options. You specify input files with the “-i” flag followed by a file name. For the output file, specify it as-is without any preceding CLI (command line interface) flag.&lt;/p&gt;
&lt;h3 id=&quot;specifying-an-input-file&quot;&gt;Specifying an input file&lt;/h3&gt;
&lt;p&gt;Let’s specify just an input file:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following image helps to understand the output:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1623px) 1623px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1623&quot; height=&quot;907&quot; src=&quot;https://img.ly/_astro/img-8-output_12XQP9.webp&quot; srcset=&quot;/_astro/img-8-output_Z1rgNnu.webp 640w, /_astro/img-8-output_Z2duH6y.webp 750w, /_astro/img-8-output_Z29hKMP.webp 828w, /_astro/img-8-output_ZaxUwk.webp 1080w, /_astro/img-8-output_Z1MW61C.webp 1280w, /_astro/img-8-output_12XQP9.webp 1623w&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First, you get the “banner”, where you see the build information and lib versions. If you watch closely, you’ll see the compilation flags, starting with &lt;strong&gt;—&lt;/strong&gt;, e.g. —enable-shared.&lt;/li&gt;
&lt;li&gt;Then you get the same output as we have seen with ffprobe earlier.&lt;/li&gt;
&lt;li&gt;And then you get a complaint that there is no output file(s) specified. That’s fine for now.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can remove the banner here with “-hide_banner”, but for brevity’s sake I’ll not include that anymore in the commands here, and I will leave it out from the outputs too.&lt;/p&gt;
&lt;p&gt;Now, let’s get brave, and specify an output file!&lt;/p&gt;
&lt;h3 id=&quot;specifying-an-output&quot;&gt;Specifying an output&lt;/h3&gt;
&lt;p&gt;As I’ve said earlier, the output file is understood by FFmpeg as it is just a filename. But more specifically, it is after the input(s) specifications, and it is not a value of any other switches.&lt;/p&gt;
&lt;p&gt;Don’t be confused for now, but yes, FFmpeg can have as many inputs and outputs as you’d like. We’ll cover that in more detail soon!&lt;/p&gt;
&lt;p&gt;This command line specifies a single output file:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Before taking a look at the output, let me congratulate you! You have just converted a video file into an audio file, by keeping just the audio content!&lt;/p&gt;
&lt;p&gt;This is how you transcode! Of course, you’ll want to specify more parameters later on.&lt;/p&gt;
&lt;p&gt;So, here is the output:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1174px) 1174px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1174&quot; height=&quot;533&quot; src=&quot;https://img.ly/_astro/img-9-output_yvlsv.webp&quot; srcset=&quot;/_astro/img-9-output_ZXLK5E.webp 640w, /_astro/img-9-output_Z1dxq3z.webp 750w, /_astro/img-9-output_Z1fKoIz.webp 828w, /_astro/img-9-output_256iWk.webp 1080w, /_astro/img-9-output_yvlsv.webp 1174w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Let’s analyze it!&lt;/p&gt;
&lt;p&gt;(1) First, we have our input metadata printing, which we saw many times already.&lt;/p&gt;
&lt;p&gt;(2) Then we have something called “stream mapping”. We forced FFmpeg into a decision situation, as we specified an input file with 1 video and 2 audio streams. We said we wanted an audio output (guessed from the .wav extension). But we didn’t specify which audio stream we wanted, so let’s see what FFmpeg decided:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“&lt;strong&gt;Stream #0:2&lt;/strong&gt;” means “The first input file’s third stream” or “input file index 0’s stream with index 2.” This is the input.&lt;/li&gt;
&lt;li&gt;”&lt;strong&gt;-&gt; #0:0&lt;/strong&gt;” means the first output file’s first stream. This is the output.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg.html#Automatic-stream-selection&quot;&gt;Here&lt;/a&gt; you can learn more about how FFmpeg decide this.&lt;/li&gt;
&lt;li&gt;Later on, we’ll manually override the mapping.&lt;/li&gt;
&lt;li&gt;Summary: FFmpeg decided to convert the third stream in the input file (the ac3 5.1 audio) into the first stream of the output file.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(3) Then we have our output metadata information. This reveals what FFmpeg will output. It usually copies most of the metadata, and here you also see the container/format information too.&lt;/p&gt;
&lt;p&gt;(4) And then we see the output summary. For example, the transcoding was 181x faster than the playback speed. Nice!&lt;/p&gt;
&lt;h3 id=&quot;understanding-the-command-line-order&quot;&gt;Understanding the command line order&lt;/h3&gt;
&lt;p&gt;Before going further, let’s understand FFmpeg’s command line arguments from a bird’s eye view!&lt;/p&gt;
&lt;p&gt;In the &lt;a href=&quot;https://ffmpeg.org/ffmpeg.html#Synopsis&quot;&gt;manual&lt;/a&gt;, you’ll see this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Parts in […] are meant to be optional, and parts in {…} are meant to be specified 1 or more times.)&lt;/p&gt;
&lt;p&gt;This is the general outline of how to specify inputs, outputs, input options, output options, and global options. The order matters, but it is easy to remember: global options, inputs and outputs. Also, i/o options come BEFORE the i/o specification.&lt;/p&gt;
&lt;p&gt;Let’s put these into pseudo command line options, to understand it better:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# One inputs, one output, nothing fancy&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input1.mp4&lt;/span&gt;&lt;span&gt; output1.wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Two inputs, one output&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input1.mp4&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input2.mp4&lt;/span&gt;&lt;span&gt; output1.wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Two inputs, two outputs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input1.mp4&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input2.mp4&lt;/span&gt;&lt;span&gt; output1.wav&lt;/span&gt;&lt;span&gt; output2.mp3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# One input, one output, with options&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; [input1 &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input1.mp4&lt;/span&gt;&lt;span&gt; [output2 &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; output1.wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Two inputs, two outputs with options&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; [input1 &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input1.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;       [input2 &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; input2.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;       [output1 &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; output1.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;       [output2 &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; output2.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As for the global options, these are the ones you might care about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-hide_banner&lt;/strong&gt;: To skip printing the banner.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-y&lt;/strong&gt;: To overwrite the output even if it exists.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, you can run this as many times as you want:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -hide_banner&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And it will overwrite the output and be less verbose than earlier.&lt;/p&gt;
&lt;p&gt;Without explaining the options themselves, let’s just see some real-world examples with options:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1047px) 1047px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1047&quot; height=&quot;345&quot; src=&quot;https://img.ly/_astro/img-10-cmd-order_1VUsz0.webp&quot; srcset=&quot;/_astro/img-10-cmd-order_Z24PuYm.webp 640w, /_astro/img-10-cmd-order_2rcG5A.webp 750w, /_astro/img-10-cmd-order_tI8X3.webp 828w, /_astro/img-10-cmd-order_1VUsz0.webp 1047w&quot;&gt;&lt;/p&gt;
&lt;p&gt;And here it is with two inputs and two outputs:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1296px) 1296px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1296&quot; height=&quot;381&quot; src=&quot;https://img.ly/_astro/img-11-cmd-order_1tE6MK.webp&quot; srcset=&quot;/_astro/img-11-cmd-order_Z13ghw4.webp 640w, /_astro/img-11-cmd-order_Z130DqX.webp 750w, /_astro/img-11-cmd-order_Z1YzaGd.webp 828w, /_astro/img-11-cmd-order_4yOs1.webp 1080w, /_astro/img-11-cmd-order_1CBEPs.webp 1280w, /_astro/img-11-cmd-order_1tE6MK.webp 1296w&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;mapping-files&quot;&gt;Mapping files&lt;/h3&gt;
&lt;p&gt;We saw above that this command:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;… will result in an audio file that contains one of the audio streams from the input video chosen by FFmpeg. This &lt;a href=&quot;https://ffmpeg.org/ffmpeg.html#Automatic-stream-selection&quot;&gt;automatic stream selection&lt;/a&gt; is usually handy when it is trivial. For example, when you have one stream as input and one output file, you don’t need to specify any mapping manually.&lt;/p&gt;
&lt;p&gt;But in cases where it is not so trivial, you are usually better off manually specifying what you really want to do.&lt;/p&gt;
&lt;p&gt;The following image summarises what our current situation is:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1770px) 1770px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1770&quot; height=&quot;918&quot; src=&quot;https://img.ly/_astro/img-12-mapping_Z1pRjg7.webp&quot; srcset=&quot;/_astro/img-12-mapping_1bbT7B.webp 640w, /_astro/img-12-mapping_2dl19K.webp 750w, /_astro/img-12-mapping_1WXOdo.webp 828w, /_astro/img-12-mapping_5YBOe.webp 1080w, /_astro/img-12-mapping_fvTdb.webp 1280w, /_astro/img-12-mapping_Z2oS17K.webp 1668w, /_astro/img-12-mapping_Z1pRjg7.webp 1770w&quot;&gt;&lt;/p&gt;
&lt;p&gt;The video stream was not matched, as the output format was an audio file (.wav). But then FFmpeg chose Stream #2, because it has more channels.&lt;/p&gt;
&lt;p&gt;So what if we’d like to get the stereo track instead? That is where mapping comes in! The mapping is a parameter of the OUTPUT file. Therefore the mapping arguments should come right before our output file definition!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:1&lt;/span&gt;&lt;span&gt; stereo_audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The argument &lt;strong&gt;-map 0:1&lt;/strong&gt; means, that in the &lt;code&gt;output&lt;/code&gt; (since we specify it as an output option) we’d like to have &lt;code&gt;Input #0&lt;/code&gt;’s (the first input file) &lt;code&gt;Stream #1&lt;/code&gt;!&lt;/p&gt;
&lt;p&gt;Let’s see the relevant parts from the output!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &apos;bbb_sunflower_1080p_60fps_normal.mp4&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Stream mapping:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:1 -&gt; #0:0 (mp3 (mp3float) -&gt; pcm_s16le (native))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Output #0, wav, to &apos;stereo_audio_only.wav&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Metadata:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    Stream #0:0(und): [...] stereo [...]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The “Stream #0:1 -&gt; #0:0” part means that we have successfully overridden the mapping, to get the mp3 stream (0:1) into our output! Also, the output metadata reveals that we’ll get a stereo result instead of the 5.1 earlier.&lt;/p&gt;
&lt;h3 id=&quot;multiple-outputs&quot;&gt;Multiple outputs&lt;/h3&gt;
&lt;p&gt;You can have multiple outputs from a single input, let’s see when that might be useful!&lt;/p&gt;
&lt;p&gt;Let’s say, we want to extract BOTH audio streams into two separate WAV files! It is super easy:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:1&lt;/span&gt;&lt;span&gt; stereo_audio_only.wav&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:2&lt;/span&gt;&lt;span&gt; ac3_audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See? I have just specified two output files with two mapping specifications! Also, I have sneaked in the “-y” to have it overwrite our previous file!&lt;/p&gt;
&lt;p&gt;Let’s check out the relevant parts of the output!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &apos;bbb_sunflower_1080p_60fps_normal.mp4&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Stream mapping:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:1 -&gt; #0:0 (mp3 (mp3float) -&gt; pcm_s16le (native))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:2 -&gt; #1:0 (ac3 (native) -&gt; pcm_s16le (native))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Output #0, wav, to &apos;stereo_audio_only.wav&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    Stream #0:0(und): [...] stereo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Output #1, wav, to &apos;ac3_audio_only.wav&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    Stream #1:0(und): Audio: [...] 5.1(side)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now the mapping reveals two lines, as we have two outputs! And indeed, you’ll get two .wav files as the output, one is stereo, and one is 5.1!&lt;/p&gt;
&lt;p&gt;There might be several other reasons why you’d want to get multiple outputs. Let’s briefly check out a few!&lt;/p&gt;
&lt;p&gt;Different formats:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; stereo_audio_only.wav&lt;/span&gt;&lt;span&gt;  stereo_audio_only.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Wow, did you catch that? We just created a WAV and an mp3 in a single command line! I’ve reverted to the automatic stream selection for brevity’s sake.&lt;/p&gt;
&lt;p&gt;A bit closer to real-life needs, you might want different output qualities:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;0:1&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; stereo_audio_only_high_quality.mp3&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;0:1&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 64k&lt;/span&gt;&lt;span&gt;  stereo_audio_only_low_quality.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here &lt;strong&gt;-b:a 320k&lt;/strong&gt; means “&lt;strong&gt;b&lt;/strong&gt;itrate of &lt;strong&gt;a&lt;/strong&gt;udio should be around &lt;strong&gt;320 kbit/sec&lt;/strong&gt;”. So I have requested FFmpeg to make two mp3s for me, from the stereo stream of the input.&lt;/p&gt;
&lt;p&gt;Checking on the files, this is what we got:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 25Mb stereo_audio_only_high_quality.mp3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;4,9Mb stereo_audio_only_low_quality.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One more common reason for having multiple outputs or using mapping is when we introduce filters into our pipeline, but that will be discussed later!&lt;/p&gt;
&lt;p&gt;Now you understand the foundations of how to communicate your basic requirements to FFmpeg via its command line! Great job! Now we can dive even deepert.&lt;/p&gt;
&lt;h2 id=&quot;hands-on-with-ffmpeg&quot;&gt;Hands-on with FFmpeg&lt;/h2&gt;
&lt;p&gt;In this section, we will discover and even try out some common features of FFmpeg!&lt;/p&gt;
&lt;p&gt;For those who are just joining in: please get the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#example-material&quot;&gt;example assets&lt;/a&gt; if you want to test out the commands shown in this chapter!&lt;/p&gt;
&lt;h3 id=&quot;inputs-1&quot;&gt;Inputs&lt;/h3&gt;
&lt;p&gt;Let’s see the common ways FFmpeg is fed with different data!&lt;/p&gt;
&lt;h3 id=&quot;file&quot;&gt;File&lt;/h3&gt;
&lt;p&gt;Of course, you have already seen that if you have a local file on your filesystem, FFmpeg is happy to read it!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:1&lt;/span&gt;&lt;span&gt; stereo_audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This command which is exactly the same as one of our previous ones just reads a local file. Really, that’s it.&lt;/p&gt;
&lt;h3 id=&quot;network&quot;&gt;Network&lt;/h3&gt;
&lt;p&gt;Did you know, that FFmpeg can open a file directly on the network?!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; bbb_first_5_seconds.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The command above opens the file directly from the network and saves the first 5 seconds into a local file!&lt;/p&gt;
&lt;p&gt;I wanted to spare bandwidth for these awesome guys over renderfarming.net, so I added the duration flag: &lt;strong&gt;-t 5&lt;/strong&gt;. FFmpeg doesn’t even download the full video for this operation. Isn’t that wonderful?!&lt;/p&gt;
&lt;h3 id=&quot;webcam&quot;&gt;Webcam&lt;/h3&gt;
&lt;p&gt;FFmpeg can also open your webcam!&lt;/p&gt;
&lt;p&gt;This is an example command for Linux:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; v4l2&lt;/span&gt;&lt;span&gt; -framerate&lt;/span&gt;&lt;span&gt; 25&lt;/span&gt;&lt;span&gt; -video_size&lt;/span&gt;&lt;span&gt; 640x480&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 10&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; /dev/video0&lt;/span&gt;&lt;span&gt; 10seconds_of_webcam.webm&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This would record 10 seconds of your webcam!&lt;/p&gt;
&lt;p&gt;Accessing the webcam happens differently on different platforms. Also specifying parameters is different for each platform, so for this reason, if you’d like to access your webcam with FFmpeg, please refer to the documentation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki/Capture/Webcam#Linux&quot;&gt;Linux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki/Capture/Webcam#Windows&quot;&gt;Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki/Capture/Webcam#OSX&quot;&gt;OS X&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;microphone&quot;&gt;Microphone&lt;/h3&gt;
&lt;p&gt;Let’s record some audio directly from your microphone!&lt;/p&gt;
&lt;p&gt;List microphones:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;arecord&lt;/span&gt;&lt;span&gt; -l&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Start 10 seconds of recording:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; alsa&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; hw:0,0&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 10&lt;/span&gt;&lt;span&gt; out.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This command was meant to work on Linux, but you can check out how to do that on &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Capture/Desktop#Windows&quot;&gt;Microsoft Windows&lt;/a&gt; or &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Capture/Desktop#macOS&quot;&gt;macOS&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;pipe&quot;&gt;Pipe&lt;/h3&gt;
&lt;p&gt;Finally, FFmpeg can read from a pipe, and also output to a pipe.&lt;/p&gt;
&lt;p&gt;On Linux, you could do something like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;cat&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; wav&lt;/span&gt;&lt;span&gt; pipe:1&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; pv&lt;/span&gt;&lt;span&gt; &gt;&lt;/span&gt;&lt;span&gt; output.wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Alternative, without pv:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;cat&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; wav&lt;/span&gt;&lt;span&gt; pipe:1&lt;/span&gt;&lt;span&gt; &gt;&lt;/span&gt;&lt;span&gt; output.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This command would use the &lt;strong&gt;cat&lt;/strong&gt; program to simply read in the video file and output it to its standard output. Then this output is piped INTO FFmpeg, through its standard input. The combination “&lt;strong&gt;-i -&lt;/strong&gt;” means “read from standard input”. By the way, standard input would be your keyboard otherwise, if we wouldn’t use any redirection here.&lt;/p&gt;
&lt;p&gt;Then we specify the required output format for FFmpeg, with “&lt;strong&gt;-f wav&lt;/strong&gt;”. This is needed because now we’ll have no output file name, and FFmpeg will not be able to guess the format. Then we specify “&lt;strong&gt;pipe:1&lt;/strong&gt;” as an output, meaning we’d like FFmpeg to output to its standard output.&lt;/p&gt;
&lt;p&gt;From then, we pipe the data into a program called “&lt;strong&gt;pv&lt;/strong&gt;”, it is just a metering tool, that dumps information on the throughput (from its stdin to its stdout). Finally, we redirect pv’s output into a WAV file.&lt;/p&gt;
&lt;p&gt;You might ask why we’d want to do that, why we talk about this. Piping can be useful if you build a complex pipeline from different programs or if you want to spare reading and writing to a local file.&lt;/p&gt;
&lt;p&gt;For example, the node package &lt;a href=&quot;https://www.npmjs.com/package/fluent-ffmpeg&quot;&gt;fluent-ffmpeg&lt;/a&gt; can leverage this functionality by supplying input and output streams. For example, you can read from an S3 bucket and write to one directly.&lt;/p&gt;
&lt;p&gt;But be warned, hell is awaiting you on that road. No kidding. You need to research the limitations of this technique. For example, many formats can not be streamed in this manner, as they need random access to the output data to write the indices at the beginning of the file after processing.&lt;/p&gt;
&lt;h3 id=&quot;outputs-1&quot;&gt;Outputs&lt;/h3&gt;
&lt;p&gt;FFmpeg can output into many protocols, from local file storage and ftp to message queue protocols all the way to streaming protocols.&lt;/p&gt;
&lt;p&gt;For more information, check out the documentation &lt;a href=&quot;https://ffmpeg.org/ffmpeg-protocols.html#Protocols&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;transcoding-audio-with-ffmpeg&quot;&gt;Transcoding audio with FFmpeg&lt;/h2&gt;
&lt;p&gt;In this chapter, we’ll be going to see how to transcode into audio with FFmpeg!&lt;/p&gt;
&lt;p&gt;The general formula is:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; {input&lt;/span&gt;&lt;span&gt; audio&lt;/span&gt;&lt;span&gt; or&lt;/span&gt;&lt;span&gt; video&lt;/span&gt;&lt;span&gt; file&lt;/span&gt;&lt;span&gt; with&lt;/span&gt;&lt;span&gt; audio}&lt;/span&gt;&lt;span&gt; [output &lt;/span&gt;&lt;span&gt;options]&lt;/span&gt;&lt;span&gt; output_audio.ext&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;choosing-a-format&quot;&gt;Choosing a format&lt;/h3&gt;
&lt;p&gt;FFmpeg is quite smart, and by the extension, it can determine which codec to use. If you specify “audio.wav” or “audio.mp3” for example, FFmpeg will use the appropriate codec to do the encoding.&lt;/p&gt;
&lt;p&gt;It is perfectly guessing most of the time. But if you want to specify the format manually, then the “-f” flag is your friend.&lt;/p&gt;
&lt;p&gt;For this, you might want to consult the list of formats:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -formats&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, these three commands will do exactly the same, but the last two requires the &lt;strong&gt;-f&lt;/strong&gt; flag.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Output codec is determined from the extension&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; bbb_audio.mp3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# No extension in the filename&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; mp3&lt;/span&gt;&lt;span&gt; bbb_audio&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Piped output therefore no filename, so no extension to use for guessing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; mp3&lt;/span&gt;&lt;span&gt; pipe:1&lt;/span&gt;&lt;span&gt; &gt;&lt;/span&gt;&lt;span&gt; bbb_audio&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;setting-the-bitrate&quot;&gt;Setting the bitrate&lt;/h3&gt;
&lt;p&gt;In most cases. you want to specify the target bitrate you expect from your codec to output. If you are unsure what bitrate is, please read this article’s &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#bitrate&quot;&gt;audio bitrate&lt;/a&gt; section.&lt;/p&gt;
&lt;p&gt;To specify the audio bitrate, use the “&lt;strong&gt;-b:a&lt;/strong&gt;” option with a corresponding value, e.g.:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-b:a 320k&lt;/strong&gt;: For the mp3 codec this is considered high quality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-b:a 128k&lt;/strong&gt;: Lower quality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-b:a 64k&lt;/strong&gt;: Low quality.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; bbb_audio_320k.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;setting-the-sample-rate&quot;&gt;Setting the sample rate&lt;/h3&gt;
&lt;p&gt;You may want to specify the sample rate to ensure quality or low output file size. Half the sample rate could mean half the output file size. If you are unsure what the sample rate is, please read the “&lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#sampling-rate&quot;&gt;audio sample rate&lt;/a&gt;” section of this article.&lt;/p&gt;
&lt;p&gt;To specify the audio sample rate, use the “&lt;strong&gt;-ar&lt;/strong&gt;” option with a corresponding value, e.g.:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-ar 48000&lt;/strong&gt;: For high quality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-ar 44100&lt;/strong&gt;: For CD quality (still high).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-ar 22500&lt;/strong&gt;: A bit of a compromise, not recommended for music, but for speech, it might be enough.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-ar 8000&lt;/strong&gt;: Low quality, e.g. if you only want “understandable” speech.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; bbb_audio_44100khz.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;setting-the-channel-count&quot;&gt;Setting the channel count&lt;/h3&gt;
&lt;p&gt;Setting the channel count can be useful, for example, if you have a stereo recording of a single person’s speech. In that case, you might be content with just a mono output half the size of the original recording.&lt;/p&gt;
&lt;p&gt;If you are unsure what an audio channel is, please read the “&lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#channels&quot;&gt;audio channels&lt;/a&gt;” section of this article.&lt;/p&gt;
&lt;p&gt;To specify the channel count use the “&lt;strong&gt;-ac&lt;/strong&gt;” option with a corresponding value, e.g.:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-ac 1&lt;/strong&gt;: For mono&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-ac 2&lt;/strong&gt;: For stereo&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-ac 6&lt;/strong&gt;: For 5.1&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -ac&lt;/span&gt;&lt;span&gt; 1&lt;/span&gt;&lt;span&gt; bbb_audio_mono.mp3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;complete-command-line-for-converting-audio-with-ffmpeg&quot;&gt;Complete command line for converting audio with FFmpeg&lt;/h3&gt;
&lt;p&gt;This is how you produce a high-quality output:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Convert wav to mp3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -ac&lt;/span&gt;&lt;span&gt; 2&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; bbb_audio_hqfull.mp3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Convert wav to m4a (aac)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -ac&lt;/span&gt;&lt;span&gt; 2&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; bbb_audio_hqfull.m4a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Convert wav to ogg (vorbis)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -ac&lt;/span&gt;&lt;span&gt; 2&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; bbb_audio_hqfull.ogg&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Check out &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio&quot;&gt;this&lt;/a&gt; documentation about good quality audio transcoding too!.&lt;/p&gt;
&lt;h3 id=&quot;lossless-formats&quot;&gt;Lossless formats&lt;/h3&gt;
&lt;p&gt;If you want to convert audio into a lossless format, here are a few choices for you:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Convert to flac (Free Lossless Audio Codec)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -compression_level&lt;/span&gt;&lt;span&gt; 12&lt;/span&gt;&lt;span&gt; bbb_audio_lossless_12.flac&lt;/span&gt;&lt;span&gt; # Best compression, slowest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -compression_level&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; bbb_audio_lossless_5.flac&lt;/span&gt;&lt;span&gt;   # Default&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; -compression_level&lt;/span&gt;&lt;span&gt; 0&lt;/span&gt;&lt;span&gt; bbb_audio_lossless_0.flac&lt;/span&gt;&lt;span&gt;   # Least compression, fastest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Convert to wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;cp&lt;/span&gt;&lt;span&gt; bbb_audio.wav&lt;/span&gt;&lt;span&gt; bbb_audio_lossless.wav&lt;/span&gt;&lt;span&gt; # Just kidding:)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Convert to wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; any_audio.ext&lt;/span&gt;&lt;span&gt; bbb_audio_lossless.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s good if you know that flac results in a smaller file than WAV, as WAV doesn’t actually compress by default:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;117M bbb_audio.wav&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;52M  bbb_audio_lossless_0.flac&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;45M  bbb_audio_lossless_5.flac&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;43M  bbb_audio_lossless_12.flac&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;WAV is generally thought of as a lossless format, but keep in mind that the WAV container can contain lossy content too, but by default FFmpeg uses the pcm_s16le format, which is the 16 bit PCM, that could be understood as lossless.&lt;/p&gt;
&lt;p&gt;Learn more &lt;a href=&quot;https://en.wikipedia.org/wiki/WAV#Comparison_of_coding_schemes&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://trac.ffmpeg.org/wiki/audio%20types&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;transcoding-video-with-ffmpeg&quot;&gt;Transcoding video with FFmpeg&lt;/h2&gt;
&lt;p&gt;In this chapter, we’ll be going to see how to transcode a video file into the two most common formats!&lt;/p&gt;
&lt;h3 id=&quot;converting-to-h264&quot;&gt;Converting to H.264&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Advanced_Video_Coding&quot;&gt;H264&lt;/a&gt; is one of the most popular video codecs. Most devices, browsers and video players understand how to play it. It is efficient in storing video content, but as with most advanced video codecs, it is a resource intensive-process to encode and decode.&lt;/p&gt;
&lt;p&gt;A complete command line for a high-quality H.264 transcoding with high-quality AAC audio is the following:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-c:v &lt;/span&gt;&lt;span&gt;libx264&lt;/span&gt;&lt;span&gt; -preset&lt;/span&gt;&lt;span&gt; slow&lt;/span&gt;&lt;span&gt; -crf&lt;/span&gt;&lt;span&gt; 22&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-profile:v &lt;/span&gt;&lt;span&gt;main&lt;/span&gt;&lt;span&gt; -g&lt;/span&gt;&lt;span&gt; 250&lt;/span&gt;&lt;span&gt; -pix_fmt&lt;/span&gt;&lt;span&gt; yuv420p&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;0:0&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:1&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-acodec &lt;/span&gt;&lt;span&gt;aac&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; bbb_transcoded_h264_HQ.mov&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Make sure to understand this command and to customize it to match your needs.&lt;/p&gt;
&lt;p&gt;To help you do that, let’s dissect this command!&lt;/p&gt;
&lt;p&gt;Global options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-y&lt;/strong&gt;: Overwrite the output.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Input options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-i bbb_sunflower_1080p_60fps_normal.mp4&lt;/strong&gt;: The input file.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Output options:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-c:v libx264&lt;/strong&gt;: Set the codec to libx264.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-preset slow&lt;/strong&gt;: libx264 has a lot of variables that you can be tune, and most of them balance the coding speed and the resulting file size. To make your life easier, there are &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.264#Preset&quot;&gt;presets&lt;/a&gt; by which you can easily declare what you need: small size or speed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-crf 22&lt;/strong&gt;: This is the constant rate factor, the main option for setting image quality. It is a number between 0-51, where 0 is lossless, and 51 is the worst quality. Generally, you want something between 17 and 28. This is the option to tune the balance between image quality and file size. Check my comparison video &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#comparing-crf-values-with-h264-and-h265&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-profile:v main -g 250 -pix_fmt yuv420p&lt;/strong&gt;: These are advanced options, guaranteeing you a quite backward compatible result. (See &lt;a href=&quot;https://ffmpeg.org/ffmpeg-codecs.html#Options-26&quot;&gt;this&lt;/a&gt;, &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.264#Profile&quot;&gt;this&lt;/a&gt;, and &lt;a href=&quot;https://ffmpeg.org/ffmpeg.html#Advanced-Video-options&quot;&gt;this&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-map 0:0 -map 0:1&lt;/strong&gt;: You might not need this: these options are selecting the correct video and audio streams. &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#ffprobe&quot;&gt;In our case&lt;/a&gt;, we have two audio streams, and we need the stereo one to avoid some issues with our aac stream.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-acodec aac&lt;/strong&gt;: Select the AAC (Advanced Audio Coding) &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#audio-codecs&quot;&gt;codec&lt;/a&gt; for the audio in the output. We need to be more specific than just &lt;strong&gt;-f&lt;/strong&gt; for the format. We need to specify the audio codec here manually.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-ar 44100&lt;/strong&gt;: Set the audio &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#sampling-rate&quot;&gt;sampling rate&lt;/a&gt; (learn more about that in previous chapters of this article).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-b:a 320k&lt;/strong&gt;: Set the audio &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#bitrate&quot;&gt;bitrate&lt;/a&gt; (learn more about that in previous chapters of this article).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;30seconds_of_bb.mkv&lt;/strong&gt;: The output file name. All the options since the last -i (or the last output file) considered to be a modifier for this output.&lt;/p&gt;
&lt;p&gt;Let’s see the output:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &apos;bbb_sunflower_1080p_60fps_normal.mp4&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Stream mapping:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:0 -&gt; #0:0 (h264 (native) -&gt; h264 (libx264))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:1 -&gt; #0:1 (mp3 (mp3float) -&gt; aac (native))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Output #0, mov, to &apos;bbb_transcoded_h264_HQ.mov&apos;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 60 fps, 15360 tbn, 60 tbc (default)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, 5.1(side), fltp, 320 kb/s (default)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;frame=38074 fps= 35 q=-1.0 Lsize=  324855kB time=00:10:34.51 bitrate=4194.1kbits/s dup=2 drop=0 speed=0.58x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From this, we understand that FFmpeg chose the mp3 stream from the input file because we told it to do so. (Remember, it has two audio streams in it, a stereo mp3 and a 5.1 ac3.) We also see that my machine could transcode with 35fps (0.58 times the playback speed), and our settings resulted in an average video bitrate of 4200 kbit/s.&lt;/p&gt;
&lt;p&gt;The video bitrate is an interesting question in this mode. With the CRF option, we specify the “constant visual quality” we want. To reach a constant visual quality, the encoder works hard to guess how much it can compress certain parts of every frame, and the result of that guess defines the final average video bitrate.&lt;/p&gt;
&lt;p&gt;If you want even better results with H.264, and you can afford a bit more processing time and a bit more complicated process, check out the &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.264#twopass&quot;&gt;2-pass encoding&lt;/a&gt; instead of the constant rate factor method introduced above.&lt;/p&gt;
&lt;p&gt;To learn more about these two different rate control methods, read the awesome &lt;a href=&quot;https://slhck.info/video/2017/03/01/rate-control.html&quot;&gt;Understanding Rate Control Modes&lt;/a&gt; article. And to learn more about the intricacies of H.264 encoding, check out the &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.264&quot;&gt;H264 encoding guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Finally, &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#comparing-crf-values-with-h264-and-h265&quot;&gt;later on&lt;/a&gt;, I will show you a comparison video that shows how different CRF values perform!&lt;/p&gt;
&lt;h3 id=&quot;converting-to-h265&quot;&gt;Converting to H.265&lt;/h3&gt;
&lt;p&gt;H.265 is the successor of H.264, according to the &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.265&quot;&gt;official FFmpeg manual&lt;/a&gt;, it offers 25-50% bitrate savings while retaining the same visual quality.&lt;/p&gt;
&lt;p&gt;A complete command line for a high-quality H.265 transcoding with high-quality AAC audio is the following:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-c:v &lt;/span&gt;&lt;span&gt;libx265&lt;/span&gt;&lt;span&gt; -preset&lt;/span&gt;&lt;span&gt; slow&lt;/span&gt;&lt;span&gt; -crf&lt;/span&gt;&lt;span&gt; 27&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-profile:v &lt;/span&gt;&lt;span&gt;main&lt;/span&gt;&lt;span&gt; -g&lt;/span&gt;&lt;span&gt; 250&lt;/span&gt;&lt;span&gt; -pix_fmt&lt;/span&gt;&lt;span&gt; yuv420p&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;0:0&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; 0:1&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-acodec &lt;/span&gt;&lt;span&gt;aac&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; bbb_transcoded_h265_HQ.mov&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the result is:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;encoded 38074 frames in 3384.84s (11.25 fps), 1720.32 kb/s, Avg QP:35.29&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;H.265 also has multiple rate control algorithms, I used the CRF method here. If you want to use a different rate control algorithm, then you may check out the &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.265&quot;&gt;H.265 encoding guide&lt;/a&gt;. Also, check out the next section, where I’ll reveal how different CRF values perform!&lt;/p&gt;
&lt;p&gt;This command is almost the same as what we used in the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#converting-to-h264&quot;&gt;H.264 example&lt;/a&gt; above, so please refer to that section to understand the arguments.&lt;/p&gt;
&lt;p&gt;If we compare H.264 and H.265 with our commands above, taking into account this 10-minute long video on my system, these are the results:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;H.264 is 3 times faster (35 fps vs 11 fps)&lt;/li&gt;
&lt;li&gt;H.264 produces a 2 times larger file (318 mb vs 156 mb)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;comparing-crf-values-with-h264-and-h265&quot;&gt;Comparing CRF values with H.264 and H.265&lt;/h3&gt;
&lt;p&gt;I have created a video for your convenience, that shows the different crf values in action. The selected frame had some movement on it with the leaves in the bunny’s hand. Movement is important with video codecs, as usually that’s where quality losses are first visible.&lt;/p&gt;
&lt;p&gt;This video shows how the different CRF values perform, from 0-51 with the H.264 and H.265 formats!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/videos/vid-1-comparison-264-265.mov&quot;&gt;H.264 &amp;#x26; H.265 CRF comparison video&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(Can you guess which program I was using to make this?:))&lt;/p&gt;
&lt;h2 id=&quot;basic-editing-with-ffmpeg&quot;&gt;Basic editing with FFmpeg&lt;/h2&gt;
&lt;p&gt;In this section, we’ll achieve basic editing tasks by using FFmpeg only!&lt;/p&gt;
&lt;p&gt;We’ll just get a basic mp4 with default settings in these examples to keep things simple. But to encode the result in a proper, high quality way, please check the earlier sections where we learned how to encode into H.264 and H.265!&lt;/p&gt;
&lt;h3 id=&quot;trimming-from-the-beginning-of-the-clip&quot;&gt;Trimming from the beginning of the clip&lt;/h3&gt;
&lt;p&gt;It is possible to specify an in-point for a media file. By doing that, you essentially cut off the specified amount from the beginning of the input file. Therefore, FFmpeg will skip the first part of the file and only transcode the remainder!&lt;/p&gt;
&lt;p&gt;For this, you need the “&lt;strong&gt;-ss&lt;/strong&gt;” flag! The value can be specified in seconds (5 or 5.2) or as a timestamp (HOURS:MM:SS.MILLISECONDS).&lt;/p&gt;
&lt;p&gt;To get the outro only, we could seek all the way to the end of the video! (It is 00:10:34.53 or 635 seconds long!)&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Get&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# 635 - 4 = 631&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -ss&lt;/span&gt;&lt;span&gt; 631&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; last_4_seconds.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# 00:10:34.53 - 4 = 00:10:30.53&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -ss&lt;/span&gt;&lt;span&gt; 00:10:30.53&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; last_4_seconds.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Seeking can be a bit tricky, so you may want to learn more about seeking &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Seeking&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;trimming-from-the-end-of-the-clip&quot;&gt;Trimming from the end of the clip&lt;/h3&gt;
&lt;p&gt;You can also set an out-point for an input file, therefore shortening it. There are two options for this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-t&lt;/strong&gt;: This sets the duration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-to&lt;/strong&gt;: This sets the timestamp where the input video should stop.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These two are mutually exclusive, and also they do the same if no -ss is specified. The value can be specified in seconds (5 or 5.2) or as a timestamp (HOURS:MM:SS.MILLISECONDS).&lt;/p&gt;
&lt;p&gt;Let’s experiment with them!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# &quot;Get 30 seconds of the input.&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 30&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; first_30_seconds.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 00:00:30.0&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; first_30_seconds.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# &quot;Get everything until the content&apos;s 30th second.&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -to&lt;/span&gt;&lt;span&gt; 30&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; first_30_seconds.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -to&lt;/span&gt;&lt;span&gt; 00:00:30.0&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; first_30_seconds.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All four above commands result in exactly the same video. (For nerds: even the md5sum is the same.)&lt;/p&gt;
&lt;p&gt;But let’s see how they perform when we introduce seeking!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# &quot;Seek to the 10th second and get me 30 seconds of the input.&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -ss&lt;/span&gt;&lt;span&gt; 10&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 30&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; part_between_10_and_40.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# &quot;Seek to the 10th second and get the content until the 30th second.&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; -ss&lt;/span&gt;&lt;span&gt; 10&lt;/span&gt;&lt;span&gt; -to&lt;/span&gt;&lt;span&gt; 30&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; part_between_10_and_30.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first command will result in a 30 second long video, while the second command will be 20 seconds long only!&lt;/p&gt;
&lt;p&gt;The figure below shows the difference:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2000px) 2000px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2000&quot; height=&quot;521&quot; src=&quot;https://img.ly/_astro/img-13-trimming_k6wLr.webp&quot; srcset=&quot;/_astro/img-13-trimming_Z151890.webp 640w, /_astro/img-13-trimming_2j0cm0.webp 750w, /_astro/img-13-trimming_DVKAT.webp 828w, /_astro/img-13-trimming_Z1NCTy9.webp 1080w, /_astro/img-13-trimming_Z1Fq4uO.webp 1280w, /_astro/img-13-trimming_Z7BfOo.webp 1668w, /_astro/img-13-trimming_k6wLr.webp 2000w&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;editing-without-reencoding&quot;&gt;Editing without reencoding&lt;/h3&gt;
&lt;p&gt;FFmpeg can do something I’m not aware of in any other popular NLE: it can edit videos without reencoding them!&lt;/p&gt;
&lt;p&gt;The usual &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#ffmpeg-concepts&quot;&gt;workflow&lt;/a&gt; is to decode the data frames (a/v) into memory, modify them as much as we like and then encode them into a new video file. The problem with this is that unless you work with raw or lossless codecs, you’ll lose some quality in the process. Another issue with this approach is that it is computationally intensive.&lt;/p&gt;
&lt;p&gt;For certain operations, you can configure FFmpeg, to keep the data frames intact, and this way, you can avoid decoding and encoding them! This is incredibly faster than regular transcoding, usually hundreds of times faster.&lt;/p&gt;
&lt;p&gt;The “certain operations” are those that don’t need to modify the data frames themselves. For example, you can cut and trim this way. Also, you can manipulate streams while keeping others, like you can replace the audio track without touching the video frames.&lt;/p&gt;
&lt;p&gt;All this is a bit of magic, and there are caveats you need to prepare for, but it is good if you know about this, as it is often handy!&lt;/p&gt;
&lt;p&gt;The trick lies in two options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-c:v copy&lt;/strong&gt;: The “copy” video codec&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-c:a copy&lt;/strong&gt;: The “copy” audio codec&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let’s see a few examples!&lt;/p&gt;
&lt;h4 id=&quot;remove-audio-while-keeping-the-video-without-reencoding&quot;&gt;Remove audio while keeping the video without reencoding&lt;/h4&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -c:v&lt;/span&gt;&lt;span&gt; copy&lt;/span&gt;&lt;span&gt; -an&lt;/span&gt;&lt;span&gt; copied_video_only.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, we used the “&lt;strong&gt;-an&lt;/strong&gt;” option, which removes all audio streams. I remembered it as “&lt;strong&gt;a&lt;/strong&gt;udio &lt;strong&gt;n&lt;/strong&gt;o”, but that is just my mnemonic:)&lt;/p&gt;
&lt;p&gt;Let’s see how fast it was:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;frame=38072 fps=20950 q=-1.0 Lsize=  310340kB time=00:10:34.51 bitrate=4006.7kbits/s speed= 349x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So It processed the whole 10 minutes of video in 2 seconds, 349x faster than playback, with 20950 fps!&lt;/p&gt;
&lt;h4 id=&quot;remove-video-while-keeping-the-audio-without-reencoding&quot;&gt;Remove video while keeping the audio without reencoding&lt;/h4&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -c:a&lt;/span&gt;&lt;span&gt; copy&lt;/span&gt;&lt;span&gt; -vn&lt;/span&gt;&lt;span&gt; copied_audio_only.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, we used the “&lt;strong&gt;-vn&lt;/strong&gt;” option, which removes all video streams. I remembered it as “&lt;strong&gt;v&lt;/strong&gt;ideo &lt;strong&gt;n&lt;/strong&gt;o”.&lt;/p&gt;
&lt;p&gt;Let’s see how fast it was:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;size=   24772kB time=00:10:34.14 bitrate= 320.0kbits/s speed= 776x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;776x faster than playback, finished in about a second, not bad!&lt;/p&gt;
&lt;h4 id=&quot;cut-and-trim-without-reencoding&quot;&gt;Cut and trim without reencoding&lt;/h4&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -ss&lt;/span&gt;&lt;span&gt; 10&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 10&lt;/span&gt;&lt;span&gt;  -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -c:a&lt;/span&gt;&lt;span&gt; copy&lt;/span&gt;&lt;span&gt; -c:v&lt;/span&gt;&lt;span&gt; copy&lt;/span&gt;&lt;span&gt; part_from_10_to_20_copied.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There could be precision issues with seeking while you do this, so you may want to learn more about seeking and copying &lt;a href=&quot;https://trac.ffmpeg.org/wiki/Seeking&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;replace-audio-on-video-file-without-reencoding&quot;&gt;Replace audio on video file without reencoding&lt;/h4&gt;
&lt;p&gt;We have removed audio and video already, but what if we want to swap them?&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;voice_recording.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;&quot;0:v&quot;&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; &quot;1:a&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-c:v &lt;/span&gt;&lt;span&gt;copy&lt;/span&gt;&lt;span&gt; -c:a&lt;/span&gt;&lt;span&gt; copy&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;bbb_with_replaced_audio.mov&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is quite a lot going on in here, so let’s explain the parts!&lt;/p&gt;
&lt;p&gt;First, we have two inputs (&lt;strong&gt;-i&lt;/strong&gt;), meaning we are better off manually specifying the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#mapping&quot;&gt;mapping&lt;/a&gt;. The command would work without the “&lt;strong&gt;-map&lt;/strong&gt;” options, but it would ignore our second input.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;-map &quot;0:v&quot; -map &quot;1:a&quot;&lt;/code&gt; means that please use the first file’s (first) video stream and the second file’s (first) audio stream.&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;-c:v copy -c:a copy&lt;/code&gt;, we require FFmpeg to copy the already encoded data packets without touching them. Therefore FFmpeg’s work is mostly really just copying bytes, no decoding, no encoding.&lt;/p&gt;
&lt;p&gt;Not surprisingly, that’s what we see in the stream mapping too:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Stream mapping:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:0 -&gt; #0:0 (copy)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #1:0 -&gt; #0:1 (copy)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Press [q] to stop, [?] for help&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;frame=38072 fps=9750 q=-1.0 Lsize=  320645kB time=00:10:34.51 bitrate=4139.7kbits/s speed= 162x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And since it is just copying, it was crazy fast, 162x of the playback speed, or almost 10k frames per second!&lt;/p&gt;
&lt;p&gt;But!&lt;/p&gt;
&lt;p&gt;Execute the exact same command, but with “bbb_with_replaced_audio.&lt;strong&gt;mp4&lt;/strong&gt;” (.mp4 container instead of .mov) as an output file! You’ll get this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Could not find tag for codec pcm_s16le in stream #1, codec not currently supported in container&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The message is quite clear. You can not have a pcm_s16le (raw WAV, say that 10 times:)) stream in an MP4 container. I’m not sure if it is FFmpeg’s or the container’s lack of support, but we need to solve this. If you run into this situation, you might consider two solutions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Change the container: I’ve just tried MOV, and it worked.&lt;/li&gt;
&lt;li&gt;Encode the audio: We still copy the video data, and encoding audio isn’t that painful.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I just showed you option #1, so let’s see option #2:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;voice_recording.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;&quot;0:v&quot;&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; &quot;1:a&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-c:v &lt;/span&gt;&lt;span&gt;copy&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-c:a &lt;/span&gt;&lt;span&gt;aac&lt;/span&gt;&lt;span&gt; -b:a&lt;/span&gt;&lt;span&gt; 320k&lt;/span&gt;&lt;span&gt; -ar&lt;/span&gt;&lt;span&gt; 44100&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;bbb_with_replaced_audio_aac.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This copies the video frames and encodes our WAV into a supported codec to be held in the mp4 container. You can refer back to the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#how-to-transcode-audio-with-ffmpeg&quot;&gt;audio encoding&lt;/a&gt; section if you want to learn more about that.&lt;/p&gt;
&lt;p&gt;Here is the output:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Stream mapping:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #0:0 -&gt; #0:0 (copy)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  Stream #1:0 -&gt; #0:1 (pcm_s16le (native) -&gt; aac (native))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Press [q] to stop, [?] for help&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;frame=38072 fps=2176 q=-1.0 Lsize=  313058kB time=00:10:34.51 bitrate=4041.8kbits/s speed=36.3x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;“Only” 36x faster than playback, 2176 fps, still not that bad!&lt;/p&gt;
&lt;h2 id=&quot;filtering-overview&quot;&gt;Filtering overview&lt;/h2&gt;
&lt;p&gt;FFmpeg supports many audio and video &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html&quot;&gt;filters&lt;/a&gt;. Currently, there are 116 audio and 286 video filters, but there are a bit more if we count the hardware accelerated ones too.&lt;/p&gt;
&lt;p&gt;So how do we leverage them?&lt;/p&gt;
&lt;p&gt;There are two ways to define filters, but I’m going to explain the complex filter, as the difference is not much, but it is more versatile. So there is a global option for FFmpeg, called: &lt;strong&gt;&lt;code&gt;-filter_complex&lt;/code&gt;&lt;/strong&gt;. With quite a weird syntax, you can specify all your filters and their parameters right after this option.&lt;/p&gt;
&lt;p&gt;You can imagine the process with the following image:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1352px) 1352px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1352&quot; height=&quot;512&quot; src=&quot;https://img.ly/_astro/img-14-complex_filter_intro_G5hEn.webp&quot; srcset=&quot;/_astro/img-14-complex_filter_intro_117lQc.webp 640w, /_astro/img-14-complex_filter_intro_Yucac.webp 750w, /_astro/img-14-complex_filter_intro_Z1VS6KM.webp 828w, /_astro/img-14-complex_filter_intro_CDlGA.webp 1080w, /_astro/img-14-complex_filter_intro_1ezHqr.webp 1280w, /_astro/img-14-complex_filter_intro_G5hEn.webp 1352w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Basically, your filter graph can access all the inputs (-i a.mp4 -i b.mp4 -i c.mp4), and it can produce as many outputs as you like (-map might be needed).&lt;/p&gt;
&lt;h3 id=&quot;basic-syntax&quot;&gt;Basic syntax&lt;/h3&gt;
&lt;p&gt;Let’s take a look at a simple, basic example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  -t&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;HELLO THERE&apos;:y=20:x=30:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex1.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Although &lt;code&gt;-filter_complex&lt;/code&gt; is a global option, I like to put it after the inputs and before the outputs as it is a bit easier to overlook the whole command that way. Thankfully the command line parser of FFmpeg is smart enough, and it works.&lt;/p&gt;
&lt;p&gt;The command above produces a 5-second-long video, where the text “HELLO THERE” is overlaid on the intro of Big Buck Bunny.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1397px) 1397px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1397&quot; height=&quot;912&quot; src=&quot;https://img.ly/_astro/img-15-hello-there_TGV9p.webp&quot; srcset=&quot;/_astro/img-15-hello-there_ZcTUvf.webp 640w, /_astro/img-15-hello-there_Zjr7vJ.webp 750w, /_astro/img-15-hello-there_Z2dDYkq.webp 828w, /_astro/img-15-hello-there_ZRoNox.webp 1080w, /_astro/img-15-hello-there_4xGVW.webp 1280w, /_astro/img-15-hello-there_TGV9p.webp 1397w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Let’s understand the weird format for specifying filters!&lt;/p&gt;
&lt;p&gt;We’ll go bottom-up, and we’ll build it from there. So the most basic format is this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;FILTER_NAME=ARGUMENT1=VALUE1:ARGUMENT2=VALUE2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;drawtext=text=&apos;HELLO THERE&apos;:y=20:x=30&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first thing before the first equal (=) sign is the filter’s name, which is the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#drawtext-1&quot;&gt;drawtext&lt;/a&gt; filter in this case. Then we have our first argument, “text” and its value “‘HELLO THERE’”. Right after that, separated with a colon (:) comes the next argument, “y” with a value of “20”.&lt;/p&gt;
&lt;p&gt;You can guess what each of the text, y, x, fontsize and fontfile arguments do, as it is quite self-explaining. But especially for the first time, you’ll heavily rely on the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html&quot;&gt;filtering documentation&lt;/a&gt; to understand every filter and every argument.&lt;/p&gt;
&lt;p&gt;Also, several characters are reserved, such as: &lt;code&gt;, : =&lt;/code&gt; and a few others depending on your environment, so sooner or later you need to learn about &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#toc-Notes-on-filtergraph-escaping&quot;&gt;escaping&lt;/a&gt; too.&lt;/p&gt;
&lt;p&gt;To recap, our pipeline looks like this now:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2384px) 2384px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2384&quot; height=&quot;594&quot; src=&quot;https://img.ly/_astro/img-16-complex_filter_multi_EsmbN.webp&quot; srcset=&quot;/_astro/img-16-complex_filter_multi_2gMSNr.webp 640w, /_astro/img-16-complex_filter_multi_Z171xGF.webp 750w, /_astro/img-16-complex_filter_multi_Z1K5OSl.webp 828w, /_astro/img-16-complex_filter_multi_1VImWl.webp 1080w, /_astro/img-16-complex_filter_multi_1vVNzi.webp 1280w, /_astro/img-16-complex_filter_multi_Z1czkU1.webp 1668w, /_astro/img-16-complex_filter_multi_aGdU2.webp 2048w, /_astro/img-16-complex_filter_multi_EsmbN.webp 2384w&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;multiple-filters-in-a-chain&quot;&gt;Multiple filters in a chain&lt;/h3&gt;
&lt;p&gt;This previous command is a single filter chain that consists of a single filter only, but you could have more filters put right after each other! It means that the output of one filter will be the input for the next! The way to do this is by separating them with a comma!&lt;/p&gt;
&lt;p&gt;Let’s draw two boxes with the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#drawbox&quot;&gt;drawbox&lt;/a&gt; filter!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  -t&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;  drawbox=x=10:y=10:w=100:h=100:color=red  ,  drawbox=x=200:y=200:w=100:h=100:color=blue  &quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex2.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See? The output of the first filter is passed to the output of the second filter!&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1596px) 1596px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1596&quot; height=&quot;1044&quot; src=&quot;https://img.ly/_astro/img-17-filter-bick-buck_2mfaYg.webp&quot; srcset=&quot;/_astro/img-17-filter-bick-buck_Z1lJ69B.webp 640w, /_astro/img-17-filter-bick-buck_Z1SUwKi.webp 750w, /_astro/img-17-filter-bick-buck_fycbY.webp 828w, /_astro/img-17-filter-bick-buck_ZC3JU5.webp 1080w, /_astro/img-17-filter-bick-buck_ZQcKyY.webp 1280w, /_astro/img-17-filter-bick-buck_2mfaYg.webp 1596w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Let’s visualize our pipeline again:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2384px) 2384px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2384&quot; height=&quot;594&quot; src=&quot;https://img.ly/_astro/img-18-complex_filter_multi_2_2bafu7.webp&quot; srcset=&quot;/_astro/img-18-complex_filter_multi_2_Z1qWCdN.webp 640w, /_astro/img-18-complex_filter_multi_2_XFBaH.webp 750w, /_astro/img-18-complex_filter_multi_2_1E6QOl.webp 828w, /_astro/img-18-complex_filter_multi_2_1UA8rw.webp 1080w, /_astro/img-18-complex_filter_multi_2_Z1aU3Xr.webp 1280w, /_astro/img-18-complex_filter_multi_2_Z2qfGxK.webp 1668w, /_astro/img-18-complex_filter_multi_2_pgEz4.webp 2048w, /_astro/img-18-complex_filter_multi_2_2bafu7.webp 2384w&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;input-and-output-pads&quot;&gt;Input and output pads&lt;/h3&gt;
&lt;p&gt;Now, we have skipped something this far, because for simple uses FFmpeg is smart enough to do it for us. And this is the specification of a chain’s input and output pads!&lt;/p&gt;
&lt;p&gt;Let’s draw just a single rectangle for now:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  -t&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -filter_complex&lt;/span&gt;&lt;span&gt; &quot;drawbox=x=10:y=10:w=100:h=100:color=red&quot;&lt;/span&gt;&lt;span&gt; filter_complex3.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;FFmpeg sees that the input for our filter chain is a single video file, and the output is a single output video file. Therefore, it safely assumes that we want that single input as the input of our single filter chain. And that single output should be the single output of our single output chain.&lt;/p&gt;
&lt;p&gt;That’s really nice, as, in simple situations like this, we don’t need to assign and map inputs and outputs manually! But when we get more inputs, filter chains, or outputs, it is no longer possible. Therefore, we need to understand how to assign inputs and outputs!&lt;/p&gt;
&lt;p&gt;First of all, let’s compare the following two command lines. They result in exactly the same result, but the second one represents what FFmpeg does internally (roughly):&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  -t&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -filter_complex&lt;/span&gt;&lt;span&gt; &quot;drawbox=x=10:y=10:w=100:h=100:color=red&quot;&lt;/span&gt;&lt;span&gt; filter_complex3.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  -t&lt;/span&gt;&lt;span&gt; 5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; -filter_complex&lt;/span&gt;&lt;span&gt; &quot;[0:v]drawbox=x=10:y=10:w=100:h=100:color=red[out_link_0]&quot;&lt;/span&gt;&lt;span&gt; -map&lt;/span&gt;&lt;span&gt; &quot;[out_link_0]&quot;&lt;/span&gt;&lt;span&gt; filter_complex3.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do you see the difference? Before our filter chain, an “input pad” is defined: &lt;code&gt;[0:v]&lt;/code&gt;. The expected format between the square brackets is documented in the &lt;a href=&quot;https://ffmpeg.org/ffmpeg.html#Stream-selection&quot;&gt;stream selection&lt;/a&gt; section of the official documentation, and this article already &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#mapping&quot;&gt;covered&lt;/a&gt; it.&lt;/p&gt;
&lt;p&gt;But, a quick summary:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;0:v&lt;/strong&gt;: This means the first video stream of the first input file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0:v:0&lt;/strong&gt;: Means exactly the same thing but in a long form.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0:0&lt;/strong&gt;: Means the first stream of the first input file (not recommended, as it could be anything in theory. It could be a subtitle stream, a thumbnail, a video or an audio stream…)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0:a&lt;/strong&gt;: This means the first audio stream of the first input file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0:a:0&lt;/strong&gt;: Means exactly the same thing but in a long form.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0:a:1&lt;/strong&gt;: Means the second (index #1) audio stream of the first input file.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So we can specify which input file should be connected to which input of the filter graph!&lt;/p&gt;
&lt;p&gt;Also, something similar is going on at the end! Do you see, the &lt;code&gt;[out_link_0]&lt;/code&gt; output pad definition at the end of our filter chain?&lt;/p&gt;
&lt;p&gt;The naming here is easier, as basically you can specify any arbitrary name in here. It roughly means, “please store the output data under this name”.&lt;/p&gt;
&lt;p&gt;And when you specify your output file, you can or need to map it by selecting one of your filter graph outputs! Therefore, we must add the -map “[out_link_0]” option before our output file.&lt;/p&gt;
&lt;p&gt;This map option means this: “Please save the data stream with this name into the following output file.”&lt;/p&gt;
&lt;p&gt;This is how you can visualize this input/output mapping:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2590px) 2590px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2590&quot; height=&quot;724&quot; src=&quot;https://img.ly/_astro/img-19-complex_filter_multi_3_cb9GV.webp&quot; srcset=&quot;/_astro/img-19-complex_filter_multi_3_Z2sAwc5.webp 640w, /_astro/img-19-complex_filter_multi_3_ZfzIQf.webp 750w, /_astro/img-19-complex_filter_multi_3_Z1SuENk.webp 828w, /_astro/img-19-complex_filter_multi_3_1NtTKc.webp 1080w, /_astro/img-19-complex_filter_multi_3_1F6bbb.webp 1280w, /_astro/img-19-complex_filter_multi_3_Z1dAxRT.webp 1668w, /_astro/img-19-complex_filter_multi_3_RAhvH.webp 2048w, /_astro/img-19-complex_filter_multi_3_ZCLv9A.webp 2560w, /_astro/img-19-complex_filter_multi_3_cb9GV.webp 2590w&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;multiple-chains&quot;&gt;Multiple chains&lt;/h3&gt;
&lt;p&gt;Coming from the previous sections, you are now ready to see and understand an even more complicated configuration, which has multiple input files, output files, and filter chains!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;train.jpg&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;[0:v]drawbox=x=10:y=10:w=100:h=100:color=red[train_box] ; [1:v]drawbox=x=10:y=10:w=100:h=100:color=red[bbb_box]&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;&quot;[train_box]&quot;&lt;/span&gt;&lt;span&gt; filter_complex4_train.jpg&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;&quot;[bbb_box]&quot;&lt;/span&gt;&lt;span&gt; filter_complex4_bbb.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s see the output (two files next to each other):&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1470px) 1470px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1470&quot; height=&quot;656&quot; src=&quot;https://img.ly/_astro/img-20-filters_output_3_1wupPS.webp&quot; srcset=&quot;/_astro/img-20-filters_output_3_ZQfV9n.webp 640w, /_astro/img-20-filters_output_3_Zswwdy.webp 750w, /_astro/img-20-filters_output_3_1gyM4x.webp 828w, /_astro/img-20-filters_output_3_CwvA.webp 1080w, /_astro/img-20-filters_output_3_Z12PHKj.webp 1280w, /_astro/img-20-filters_output_3_1wupPS.webp 1470w&quot;&gt;&lt;/p&gt;
&lt;p&gt;We had two inputs, and we got two output files, an image, and a video, with a red rectangle on them, with a single command!&lt;/p&gt;
&lt;p&gt;Are you still here? I hope! Let’s understand what happened in that crazy command! We have two input files:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-i train.jpg&lt;/strong&gt;: A simple image file&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-t 5 -i bbb_sunflower_1080p_60fps_normal.mp4&lt;/strong&gt;: Our video file, but to make it quick, just the first five seconds of it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then the first thing to note is that we have two filter chains! They are separated with a ”&lt;strong&gt;;&lt;/strong&gt;”.&lt;/p&gt;
&lt;p&gt;Our first filter graph is this: &lt;code&gt;[0:v]...[train_box]&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This requests the first input file as an input&lt;/li&gt;
&lt;li&gt;Draws a red box&lt;/li&gt;
&lt;li&gt;Saves the output into the “train_box” output pad&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Our second filter graph is this: &lt;code&gt;[1:v]...[bbb_box]&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This requests the second input file as an input&lt;/li&gt;
&lt;li&gt;Draws a red box&lt;/li&gt;
&lt;li&gt;Saves the output into the “bbb_box” output pad&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And finally, we got two outputs, each mapping to one of the outputs of the filter graph:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-map “[train_box]” filter_complex4_train.jpg&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-map “[bbb_box]” filter_complex4_bbb.mp4&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the same thing visually:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2898px) 2898px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2898&quot; height=&quot;988&quot; src=&quot;https://img.ly/_astro/img-21-complex_filter_multi_4_4Rlkm.webp&quot; srcset=&quot;/_astro/img-21-complex_filter_multi_4_1MDtiy.webp 640w, /_astro/img-21-complex_filter_multi_4_279DG.webp 750w, /_astro/img-21-complex_filter_multi_4_WpIQ9.webp 828w, /_astro/img-21-complex_filter_multi_4_Cj59z.webp 1080w, /_astro/img-21-complex_filter_multi_4_MmBkH.webp 1280w, /_astro/img-21-complex_filter_multi_4_2odyoG.webp 1668w, /_astro/img-21-complex_filter_multi_4_26HLAj.webp 2048w, /_astro/img-21-complex_filter_multi_4_Z2rPCuv.webp 2560w, /_astro/img-21-complex_filter_multi_4_4Rlkm.webp 2898w&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you are thinking about making it even more complex and making filter graphs that combine multiple inputs into one for example, you are on the right track! It is possible, and we will get to that!&lt;/p&gt;
&lt;p&gt;This was the introduction to the filtering system and its syntax.&lt;/p&gt;
&lt;h2 id=&quot;editing-video&quot;&gt;Editing video&lt;/h2&gt;
&lt;p&gt;Now let’s get to know a few filters and make some interesting stuff!&lt;/p&gt;
&lt;h3 id=&quot;resizing-or-scaling&quot;&gt;Resizing or scaling&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#scale&quot;&gt;scale&lt;/a&gt; filter is a simple one, yet it is quite powerful!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;scale=width=600:height=-1:force_original_aspect_ratio=decrease&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex5_scaled1.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The arguments speak for themselves, but a few things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Specifying -1 to either width or height means rescaling while keeping the aspect ratio.&lt;/li&gt;
&lt;li&gt;“force_original_aspect_ratio” can be &lt;code&gt;increase&lt;/code&gt;, &lt;code&gt;decrease&lt;/code&gt;. Meaning it will increase or decrease the image to fit the specified bounding box while keeping the aspect ratio.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;adding-text&quot;&gt;Adding text&lt;/h3&gt;
&lt;p&gt;We have already covered this a little, so let’s dive deeper!&lt;/p&gt;
&lt;p&gt;This is what we used earlier:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;HELLO THERE&apos;:y=20:x=30:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex1.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let’s discover how to align the text!&lt;/p&gt;
&lt;p&gt;Many filters, including drawtext, support variables in some of its argument’s values. If you scroll down in the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#drawtext-1&quot;&gt;documentation of drawtext&lt;/a&gt;, you’ll find this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“The parameters for x and y are expressions containing the following constants and functions: ”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And after this part, you’ll see many variables which you can include in your x and y variables!&lt;/p&gt;
&lt;p&gt;Let’s see:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Align the text to the center&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;HELLO THERE&apos;:y=h/2-text_h/2:x=w/2-text_w/2:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex6_center.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# y=h/2-text_h/2 means: y position = (image height / 2) - (text height / 2)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Align the text to the right:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;HELLO THERE&apos;:y=30:x=w-text_w-20:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex6_right.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# x=w-text_w-20 means: x position = image width - text width - 20pixel padding&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# Align the text to the bottom:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;HELLO THERE&apos;:y=h-text_h-20:x=30:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex6_bottom.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# y=h-text_h-20 means: y position = image height - text height - 20pixel padding&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And this is what we’ll get in the end:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1802px) 1802px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1802&quot; height=&quot;1043&quot; src=&quot;https://img.ly/_astro/img-22-filters_output_4_Zc05ub.webp&quot; srcset=&quot;/_astro/img-22-filters_output_4_ZlgkEK.webp 640w, /_astro/img-22-filters_output_4_Z1sYxVz.webp 750w, /_astro/img-22-filters_output_4_ZqN21H.webp 828w, /_astro/img-22-filters_output_4_Z2bweND.webp 1080w, /_astro/img-22-filters_output_4_Z1cq8p8.webp 1280w, /_astro/img-22-filters_output_4_Z27qRVh.webp 1668w, /_astro/img-22-filters_output_4_Zc05ub.webp 1802w&quot;&gt;&lt;/p&gt;
&lt;p&gt;I need to mention one good trick that might not be obvious at first. So the &lt;code&gt;text_h&lt;/code&gt; variable is a tricky one, because different text will be of different height! E.g.: ”____” and “WWW” will result in a different height.&lt;/p&gt;
&lt;p&gt;For this reason, you do not always want to use text_h or even just a constant y=value expression but rather, you need to align text by its &lt;a href=&quot;https://en.wikipedia.org/wiki/Baseline%5F(typography)&quot;&gt;&lt;strong&gt;baseline&lt;/strong&gt;&lt;/a&gt;. So just remember to use the “&lt;strong&gt;ascent&lt;/strong&gt;” variable whenever you need to align text vertically!&lt;/p&gt;
&lt;p&gt;Check out these two examples! Each has two drawtext filters printing ”_” and “_H”:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# This one uses y=200 for both, still the text isn&apos;t aligned properly!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;_&apos;:y=200:x=30:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf,drawtext=text=&apos;_H&apos;:y=200:x=500:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex7_bad_text.mp4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# This one uses y=200-ascent for both and the text is aligned as expected!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;drawtext=text=&apos;_&apos;:y=200-ascent:x=30:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf,drawtext=text=&apos;_H&apos;:y=200-ascent:x=500:fontsize=200:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex7_good_text.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let’s compare the difference:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1771px) 1771px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1771&quot; height=&quot;525&quot; src=&quot;https://img.ly/_astro/img-23-filters_output_4_textalign_2lsx6V.webp&quot; srcset=&quot;/_astro/img-23-filters_output_4_textalign_2qB7V4.webp 640w, /_astro/img-23-filters_output_4_textalign_xgGX5.webp 750w, /_astro/img-23-filters_output_4_textalign_Z1SnAfT.webp 828w, /_astro/img-23-filters_output_4_textalign_1It9OQ.webp 1080w, /_astro/img-23-filters_output_4_textalign_L5FXv.webp 1280w, /_astro/img-23-filters_output_4_textalign_JOoiO.webp 1668w, /_astro/img-23-filters_output_4_textalign_2lsx6V.webp 1771w&quot;&gt;&lt;/p&gt;
&lt;p&gt;See? This is the difference between aligning the “top left” or the “baseline” of the text!&lt;/p&gt;
&lt;h3 id=&quot;adding-an-overlay&quot;&gt;Adding an overlay&lt;/h3&gt;
&lt;p&gt;Overlaying is a very interesting thing to do with FFmpeg. Let’s jump right in!&lt;/p&gt;
&lt;h4 id=&quot;basic&quot;&gt;Basic&lt;/h4&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;smiley.png&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;overlay&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex8_overlay1.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Easy as that!&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1497px) 1497px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1497&quot; height=&quot;980&quot; src=&quot;https://img.ly/_astro/img-24-overlay_1_Z1nBChF.webp&quot; srcset=&quot;/_astro/img-24-overlay_1_ZncyFD.webp 640w, /_astro/img-24-overlay_1_IaJii.webp 750w, /_astro/img-24-overlay_1_ASKXl.webp 828w, /_astro/img-24-overlay_1_my3ED.webp 1080w, /_astro/img-24-overlay_1_Z1N7Swu.webp 1280w, /_astro/img-24-overlay_1_Z1nBChF.webp 1497w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Of course, the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#overlay&quot;&gt;overlay&lt;/a&gt; filter has a ton of options, but I wanted to demonstrate the easiest possible command line. We don’t even need to mess with input/output pads, as FFmpeg automatically understands the situation: two inputs for the overlay filter and its single output into a single output.&lt;/p&gt;
&lt;p&gt;But just to exercise, we could have executed it like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;smiley.png&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;[0:v][1:v]overlay[output]&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-map &lt;/span&gt;&lt;span&gt;&quot;[output]&quot;&lt;/span&gt;&lt;span&gt; filter_complex8_overlay2.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And this would result in the same output! Check it out, now I have specified the two inputs for the overlay: &lt;code&gt;[0:v][1:v]&lt;/code&gt;!&lt;/p&gt;
&lt;h4 id=&quot;aligned&quot;&gt;Aligned&lt;/h4&gt;
&lt;p&gt;Let’s align the smiley into the center!&lt;/p&gt;
&lt;p&gt;As we have seen with the drawtext, the overlay filter’s arguments also support a few dynamic variables. We’ll use those to achieve what we want!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;smiley.png&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;overlay=x=main_w/2-overlay_w/2:y=main_h/2-overlay_h/2&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex8_overlay3.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 869px) 869px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;869&quot; height=&quot;627&quot; src=&quot;https://img.ly/_astro/img-25-overlay_2_UYX62.webp&quot; srcset=&quot;/_astro/img-25-overlay_2_1gM7AF.webp 640w, /_astro/img-25-overlay_2_1EXof0.webp 750w, /_astro/img-25-overlay_2_1JUWjv.webp 828w, /_astro/img-25-overlay_2_UYX62.webp 869w&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;preprocessing-the-input-for-overlay&quot;&gt;Preprocessing the input for overlay&lt;/h4&gt;
&lt;p&gt;Let’s get a bit creative!&lt;/p&gt;
&lt;p&gt;I want to make it &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#scale&quot;&gt;smaller&lt;/a&gt;, and I also want to &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#scale&quot;&gt;blur&lt;/a&gt; it!&lt;/p&gt;
&lt;p&gt;Now pause for a minute, and think about it, how you’d do that?!&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;Ready?&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;smiley.png&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;[1:v]scale=w=200:h=-1,gblur=sigma=3[smiley] ; [0:v][smiley]overlay=x=100:y=100&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex8_overlay4.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 996px) 996px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;996&quot; height=&quot;703&quot; src=&quot;https://img.ly/_astro/img-26-overlay_3_6Y6rG.webp&quot; srcset=&quot;/_astro/img-26-overlay_3_ZvuUJA.webp 640w, /_astro/img-26-overlay_3_jhI7.webp 750w, /_astro/img-26-overlay_3_Z2rI2GV.webp 828w, /_astro/img-26-overlay_3_6Y6rG.webp 996w&quot;&gt;&lt;/p&gt;
&lt;p&gt;For this we needed to have two filter graphs!&lt;/p&gt;
&lt;p&gt;The first one is this: &lt;code&gt;[1:v]scale=w=200:h=-1,gblur=sigma=3[smiley]&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scales the input image (the smiley).&lt;/li&gt;
&lt;li&gt;Then the scaled output is also blurred.&lt;/li&gt;
&lt;li&gt;Then the output is saved into the output pad named “smiley”.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then, we have our second filter graph: &lt;code&gt;[0:v][smiley]overlay=x=100:y=100&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This takes as input the first input file (the video).&lt;/li&gt;
&lt;li&gt;This also takes as input the output pad named “smiley”. (We are connecting two chains this time!)&lt;/li&gt;
&lt;li&gt;Then the overlay filter does its overlaying thing, and we trust FFmpeg to pair the unnamed output with the single output file we specified.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;reusing-content&quot;&gt;Reusing content&lt;/h4&gt;
&lt;p&gt;Let’s do one more, a really complicated one!&lt;/p&gt;
&lt;p&gt;Let’s have the outro overlaid over the intro!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; -ss&lt;/span&gt;&lt;span&gt; 00:09:40&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot; [1:v]scale=w=1920/2:h=-1[outro]; [0:v][outro]overlay&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;filter_complex8_overlay5.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1170px) 1170px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1170&quot; height=&quot;794&quot; src=&quot;https://img.ly/_astro/img-27-overlay_4_ZFl9Ib.webp&quot; srcset=&quot;/_astro/img-27-overlay_4_Z1UFLMT.webp 640w, /_astro/img-27-overlay_4_mGyKD.webp 750w, /_astro/img-27-overlay_4_ZiLCyz.webp 828w, /_astro/img-27-overlay_4_eB1jO.webp 1080w, /_astro/img-27-overlay_4_ZFl9Ib.webp 1170w&quot;&gt;&lt;/p&gt;
&lt;p&gt;We could have achieved it in several ways, e.g. we could use the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#trim&quot;&gt;trim&lt;/a&gt; filter, but to keep it easy, we just open the same file twice and &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#cutting-off-from-the-beginning-of-the-clip&quot;&gt;seek/trim&lt;/a&gt; them.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-t 5 -i bbb_sunflower_1080p_60fps_normal.mp4&lt;/strong&gt;: Open the video, and keep the first five seconds of it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-t 5 -ss 00:09:40 -i bbb_sunflower_1080p_60fps_normal.mp4&lt;/strong&gt;: Open the same video again, but seek to the end and keep five seconds from there.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then we have two filter graphs again, one scales down the outro, and the second is just an overlay.&lt;/p&gt;
&lt;p&gt;Are you excited?:) I hope these made-up examples opened up your eye for the possibilities, and I hope you’ll create very creative stuff with this knowledge!&lt;/p&gt;
&lt;h3 id=&quot;chroma-keying-green-screen-blue-screen&quot;&gt;Chroma keying, green screen, blue screen&lt;/h3&gt;
&lt;p&gt;In this section, we’ll use chroma keying to remove the background from Big Buck Bunny’s intro, and then we will put the transparent logo over the original video, as if it would be some kind of a logo overlay!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-ss &lt;/span&gt;&lt;span&gt;0.5&lt;/span&gt;&lt;span&gt; -t&lt;/span&gt;&lt;span&gt; 2&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-ss &lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; bbb_sunflower_1080p_60fps_normal.mp4&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot; [0:v]chromakey=color=0xfdfdfd:similarity=0.1:blend=0.2 , scale=w=-1:h=300 , loop=loop=-1:start=0:size=120[intro] ; [1:v][intro]overlay=x=-40:y=-40&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-t &lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt; filter_complex9.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So just to recap, Big Buck Bunny’s first few seconds are like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 854px) 854px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;854&quot; height=&quot;614&quot; src=&quot;https://img.ly/_astro/img-28-chroma_basic_ZCF03.webp&quot; srcset=&quot;/_astro/img-28-chroma_basic_ZMx3FJ.webp 640w, /_astro/img-28-chroma_basic_ZusNr3.webp 750w, /_astro/img-28-chroma_basic_1kYLiL.webp 828w, /_astro/img-28-chroma_basic_ZCF03.webp 854w&quot;&gt;&lt;/p&gt;
&lt;p&gt;And this is the result:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1114px) 1114px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1114&quot; height=&quot;764&quot; src=&quot;https://img.ly/_astro/img-29-chroma1_Z2g6XrH.webp&quot; srcset=&quot;/_astro/img-29-chroma1_Z1RBLwH.webp 640w, /_astro/img-29-chroma1_fjr5z.webp 750w, /_astro/img-29-chroma1_2nsk0h.webp 828w, /_astro/img-29-chroma1_14SEPM.webp 1080w, /_astro/img-29-chroma1_Z2g6XrH.webp 1114w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Also, the butterfly moves its wings repeatedly!&lt;/p&gt;
&lt;p&gt;Let’s examine the command!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-ss 0.5 -t 2 -i bbb_sunflower_1080p_60fps_normal.mp4&lt;/strong&gt;: We read in the intro from 0.5 to 2.5 seconds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-ss 10 -i bbb_sunflower_1080p_60fps_normal.mp4&lt;/strong&gt;: We read in the video, starting from the 10th second.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then we have two filter graphs, the first being this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[0:v]chromakey=color=0xfdfdfd:similarity=0.1:blend=0.2 , scale=w=-1:h=300 , loop=loop=-1:start=0:size=120[intro]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;As we see, we have three filters in here!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#chromakey&quot;&gt;&lt;strong&gt;chromakey&lt;/strong&gt;&lt;/a&gt;: This one takes a color and a few parameters as input, and outputs transparent frames. The specified color + the blended areas will be the transparent sections. In our case we replaced the white-ish (#fdfdfd) background color with transparency.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#scale&quot;&gt;&lt;strong&gt;scale&lt;/strong&gt;&lt;/a&gt;: We resize the full 1080p image into something around 300px high.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#loop&quot;&gt;&lt;strong&gt;loop&lt;/strong&gt;&lt;/a&gt;: With the loop filter, we repeat all the 2 seconds worth of 120 frames (60*2) over and over again, to have the butterfly move its wings continuously.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And then, finally we have the second filter graph:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[1:v][intro]overlay=x=-40:y=-40&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Nothing fancy, just an overlay of the original video and our chrome keyed intro.&lt;/p&gt;
&lt;h3 id=&quot;what-else&quot;&gt;What else?&lt;/h3&gt;
&lt;p&gt;You might want to check out a few more &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#toc-Video-Filters&quot;&gt;filters&lt;/a&gt;, that I didn’t cover here.&lt;/p&gt;
&lt;p&gt;Here are just a few interesting ones:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#colorcorrect&quot;&gt;colorcorrect&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#colorchannelmixer&quot;&gt;colorchannelmixer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#colorize&quot;&gt;colorize&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#fps&quot;&gt;fps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#trim&quot;&gt;trim&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#crop&quot;&gt;crop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#delogo&quot;&gt;delogo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#derain&quot;&gt;derain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#deshake&quot;&gt;deshake&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#erosion&quot;&gt;erosion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#edgedetect&quot;&gt;edgedetect&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#hflip&quot;&gt;hflip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#vflip&quot;&gt;vflip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#hstack&quot;&gt;hstack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#vstack&quot;&gt;vstack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#xstack&quot;&gt;xstack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#lumakey&quot;&gt;lumakey&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#reverse&quot;&gt;reverse&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#rotate&quot;&gt;rotate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#scroll&quot;&gt;scroll&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#pad&quot;&gt;pad&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#vignette&quot;&gt;vignette&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#zoompan&quot;&gt;zoompan&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;audio-manipulation&quot;&gt;Audio manipulation&lt;/h2&gt;
&lt;p&gt;In this chapter, we’ll be going to check out some &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#toc-Audio-Filters&quot;&gt;audio manipulation techniques&lt;/a&gt; with FFmpeg!&lt;/p&gt;
&lt;p&gt;First of all, let’s see our &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#example-material&quot;&gt;example&lt;/a&gt; file:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1920px) 1920px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1920&quot; height=&quot;400&quot; src=&quot;https://img.ly/_astro/img-30-voice_recording_1UlWX5.webp&quot; srcset=&quot;/_astro/img-30-voice_recording_1ecLD4.webp 640w, /_astro/img-30-voice_recording_cilwF.webp 750w, /_astro/img-30-voice_recording_1XAAfW.webp 828w, /_astro/img-30-voice_recording_17KzOf.webp 1080w, /_astro/img-30-voice_recording_st2hO.webp 1280w, /_astro/img-30-voice_recording_2jkO3S.webp 1668w, /_astro/img-30-voice_recording_1UlWX5.webp 1920w&quot;&gt;&lt;/p&gt;
&lt;p&gt;It is a voice recording, and it is intentionally… well, quite bad.&lt;/p&gt;
&lt;p&gt;From the waveform, it is obvious that there are very different volume ranges in it. This is an example recording where each sentence was read in different strengths: “normal”, “whisper” or “powerful”, this is why you see repeating patterns of amplitude ranges on the image.&lt;/p&gt;
&lt;p&gt;It isn’t visible, but it has some noise too, and of course, it is not normalized or enhanced in any way. Yet.&lt;/p&gt;
&lt;p&gt;Please note that there are different scenarios, requirements, and ways to enhance audio. This is a simplified method to show the outline of the process in this article. I’m not an audio engineer, although I have some experience in the area. So if you know it better, feel free to fine-tune it for yourself even more, or contact me and recommend improvements!&lt;/p&gt;
&lt;p&gt;I’m showing an example here with a very rough input, one that you’d just reject in real life as it would be useless due to its quality. But it is an excellent example to show the different steps of the enhancing process and to see what can be done to it!&lt;/p&gt;
&lt;p&gt;The following steps are built upon each other, and we’ll reach the complete command at the &lt;a href=&quot;https://img.ly/blog/ultimate-guide-to-ffmpeg//#putting-it-all-together&quot;&gt;end&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Don’t forget that these settings are specific to this voice recording. Sadly this can not be generalized too much.&lt;/p&gt;
&lt;h3 id=&quot;gate&quot;&gt;Gate&lt;/h3&gt;
&lt;p&gt;Let’s start with the &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#agate&quot;&gt;gate&lt;/a&gt; filter!&lt;/p&gt;
&lt;p&gt;A gate is like a switch that opens only if the signal is stronger than the threshold. So if the signal level is lower than the threshold, it cuts to complete silence. Although you might soften or delay this cut with the &lt;em&gt;knee&lt;/em&gt;, &lt;em&gt;attack&lt;/em&gt;, and &lt;em&gt;release&lt;/em&gt; arguments.&lt;/p&gt;
&lt;p&gt;We’ll use this filter as a basic noise reduction method now! This helps us remove the noise between words and sentences by cutting it to silence. It doesn’t remove noise in any other way, e.g. it doesn’t touch the static on the voice itself.&lt;/p&gt;
&lt;p&gt;Check this out!&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;voice_recording.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;agate=threshold=0.01:attack=80:release=840:makeup=1:ratio=3:knee=8&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gate.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s hear it: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-5-gate.wav&quot;&gt;gate.wav&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And let’s see it:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 655px) 655px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;655&quot; height=&quot;599&quot; src=&quot;https://img.ly/_astro/img-31-a_compression_result_ZdNo4g.webp&quot; srcset=&quot;/_astro/img-31-a_compression_result_1rLY1L.webp 640w, /_astro/img-31-a_compression_result_ZdNo4g.webp 655w&quot;&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the “silent” parts were attenuated heavily, while the above-the-threshold parts remained similar. Those parts were still affected by the knee, attack, and release arguments determining how hard (knee) and quick (attack/release) the cut is.&lt;/p&gt;
&lt;p&gt;I’ve left a quite high release timeout here to avoid sudden dips in the amplitude.&lt;/p&gt;
&lt;p&gt;This is where we are right now:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1920px) 1920px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1920&quot; height=&quot;400&quot; src=&quot;https://img.ly/_astro/img-32-gate_2cOAMH.webp&quot; srcset=&quot;/_astro/img-32-gate_ZqA69z.webp 640w, /_astro/img-32-gate_Z2a2c7C.webp 750w, /_astro/img-32-gate_Z2gGRxK.webp 828w, /_astro/img-32-gate_Z1iqObf.webp 1080w, /_astro/img-32-gate_Z1UP9EM.webp 1280w, /_astro/img-32-gate_Z1j6JuW.webp 1668w, /_astro/img-32-gate_2cOAMH.webp 1920w&quot;&gt;&lt;/p&gt;
&lt;p&gt;The silent parts are more silent than before, but still, the amplitude range or the dynamic range is quite high. You must change your volume levels to hear everything and void blowing your speakers/brain out.&lt;/p&gt;
&lt;h3 id=&quot;equalization&quot;&gt;Equalization&lt;/h3&gt;
&lt;p&gt;Before fixing that, let’s do a bit more housekeeping. Let’s do some equalization and frequency filtering!&lt;/p&gt;
&lt;p&gt;We’ll use these filters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#highpass&quot;&gt;highpass&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#lowpass&quot;&gt;lowpass&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#anequalizer&quot;&gt;anequalizer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;gate.wav&lt;/span&gt;&lt;span&gt;  \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;highpass=f=100:width_type=q:width=0.5 , lowpass=f=10000 , anequalizer=c0 f=250 w=100 g=2 t=1|c0 f=700 w=500 g=-5 t=1|c0 f=2000 w=1000 g=2 t=1&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gate_eq.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s hear it: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-5-gate.wav&quot;&gt;gate_eq.wav&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This command gradually attenuates frequencies below 100hz, as there are not much valuable content in there, but it can really lower the clarity of the speech.&lt;/p&gt;
&lt;p&gt;Then we do the same, but for frequencies above 10 kHz. This is mostly needed because we have a lot of high-frequency noise, so this is a workaround for those. Also, a male voice is generally deeper than a woman’s, so you might want to pay attention to how low you can put the bar.&lt;/p&gt;
&lt;p&gt;Then comes anequalizer, which has a crazy an exceptional way of setting its arguments:&lt;/p&gt;
&lt;p&gt;This: &lt;code&gt;anequalizer=c0 f=250 w=100 g=2 t=1|c0 f=700 w=500 g=-5 t=1|c0 f=2000 w=1000 g=2 t=1&lt;/code&gt; means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;at 250hz with a width of 100hz boost by 2 db, with Chebyshev type 1 filter on channel 0.&lt;/li&gt;
&lt;li&gt;at 700hz with a width of 500hz attenuate by 5 db, with Chebyshev type 1 filter on channel 0.&lt;/li&gt;
&lt;li&gt;at 2000hz with a width of 1000hz attenuate by 2 db, with Chebyshev type 1 filter on channel 0.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I agree. You might have used a friendlier equalizer in your life than this one:)&lt;/p&gt;
&lt;p&gt;Those values are based on experimentation and common recommendations for voice. Feel free to tune it for your own needs!&lt;/p&gt;
&lt;p&gt;Let’s compare the frequency plots before and after:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1463px) 1463px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1463&quot; height=&quot;386&quot; src=&quot;https://img.ly/_astro/img-33-a_eq_Z2gUDKL.webp&quot; srcset=&quot;/_astro/img-33-a_eq_Z1V1zyn.webp 640w, /_astro/img-33-a_eq_1bHq3R.webp 750w, /_astro/img-33-a_eq_Z15FmFs.webp 828w, /_astro/img-33-a_eq_Z1dDKHz.webp 1080w, /_astro/img-33-a_eq_rII8h.webp 1280w, /_astro/img-33-a_eq_Z2gUDKL.webp 1463w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Tip: To see the frequency plot in Audacity, open a file, select all, and choose Analyze → Plot spectrum!&lt;/p&gt;
&lt;h3 id=&quot;compression&quot;&gt;Compression&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#acompressor&quot;&gt;compressor&lt;/a&gt; filter applies &lt;a href=&quot;https://en.wikipedia.org/wiki/Dynamic_range_compression&quot;&gt;dynamic range compression&lt;/a&gt; on the incoming audio data. To simplify this, the compressor varies the attenuation based on the incoming signal level. Basically, when you watch a badly mastered movie, this is what you are doing. When it is way too loud in some action scene, you reach for the remote control or mouse to lower the volume, but in the next moment, you will not hear what your heroes are saying, so you increase it back again.&lt;/p&gt;
&lt;p&gt;Dynamic range compression roughly does the same. You may set it up in a way so that it would attenuate louder parts, therefore keeping the overall volume range relatively small.&lt;/p&gt;
&lt;p&gt;It often happens that performers on the stage use a high dynamic range. Many performers will shout at one moment and then whisper in the next to increase drama or keep the attention. If you want to avoid manually adjusting the volume in real-time (while blowing off your speakers and pulling your hair out), then a compressor will save you in these situations!&lt;/p&gt;
&lt;p&gt;This is why our example audio consists of different speaking strengths, so that we could see the dramatic effect of this filter.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;gate_eq.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;acompressor=level_in=6:threshold=0.025:ratio=20:makeup=6&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gate_eq_comp.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s hear it: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-1-gate-eq-comp.wav&quot;&gt;gate_eq_comp.wav&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And let’s compare the result of this with the original waveform!&lt;/p&gt;
&lt;p&gt;Original:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1920px) 1920px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1920&quot; height=&quot;400&quot; src=&quot;https://img.ly/_astro/img-34-voice_recording_Z29Di0o.webp&quot; srcset=&quot;/_astro/img-34-voice_recording_Z20VCWo.webp 640w, /_astro/img-34-voice_recording_22l4K9.webp 750w, /_astro/img-34-voice_recording_Z1gxOkv.webp 828w, /_astro/img-34-voice_recording_27WsEH.webp 1080w, /_astro/img-34-voice_recording_1sEU8h.webp 1280w, /_astro/img-34-voice_recording_Z1KEqTA.webp 1668w, /_astro/img-34-voice_recording_Z29Di0o.webp 1920w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Result:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1920px) 1920px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1920&quot; height=&quot;400&quot; src=&quot;https://img.ly/_astro/img-35-gate_eq_comp_Z2mmEkT.webp&quot; srcset=&quot;/_astro/img-35-gate_eq_comp_1tg7KR.webp 640w, /_astro/img-35-gate_eq_comp_2vyYBl.webp 750w, /_astro/img-35-gate_eq_comp_1xRkJE.webp 828w, /_astro/img-35-gate_eq_comp_tpybk.webp 1080w, /_astro/img-35-gate_eq_comp_1DreDv.webp 1280w, /_astro/img-35-gate_eq_comp_xv3Vx.webp 1668w, /_astro/img-35-gate_eq_comp_Z2mmEkT.webp 1920w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Quite dramatic, isn’t it?:)&lt;/p&gt;
&lt;p&gt;Let’s analyze this: &lt;code&gt;acompressor=level_in=6:threshold=0.025:ratio=20:makeup=6&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;First, &lt;code&gt;level_in=6&lt;/code&gt; sets the input gain. It is 1 by default, but since our example, audio is extremely silent at places, we boost up the whole thing before processing.&lt;/p&gt;
&lt;p&gt;Then &lt;code&gt;threshold=0.025&lt;/code&gt; defines that everything above 0.025 should be attenuated.&lt;/p&gt;
&lt;p&gt;Based on the image below, I’ve decided to cut at this point, as this is above most of the whispering, which cuts hard pops and “s”-es even in the “whisper zone”.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1916px) 1916px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1916&quot; height=&quot;455&quot; src=&quot;https://img.ly/_astro/img-36-eq_1D0n3V.webp&quot; srcset=&quot;/_astro/img-36-eq_25pidd.webp 640w, /_astro/img-36-eq_Z2b9iqi.webp 750w, /_astro/img-36-eq_1vTL83.webp 828w, /_astro/img-36-eq_WykcW.webp 1080w, /_astro/img-36-eq_UxPb5.webp 1280w, /_astro/img-36-eq_Z284TW8.webp 1668w, /_astro/img-36-eq_1D0n3V.webp 1916w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Then &lt;code&gt;ratio=20&lt;/code&gt; means 1:20 in attenuation ratio, which means that if the level rises 20 dB above the threshold, it will be only 1 dB above the line after the attenuation. Basically, this is a very strong compression ratio, it is almost a &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#alimiter&quot;&gt;limiter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This far, we boosted the signal, then turned down everything that was above our “whisper line” with a quite strong ratio, and now, everything is basically at the whisper level, even the parts that are shouting.&lt;/p&gt;
&lt;p&gt;Finally, with the &lt;code&gt;makeup=6&lt;/code&gt; we just bring back everything to the level where the “normal” parts were before.&lt;/p&gt;
&lt;p&gt;Let’s take a look back now, to understand why we used the gate and did the equalization before the compressor.&lt;/p&gt;
&lt;p&gt;Generally, you want to remove unneeded parts and frequencies before compression, as the compressor will likely increase those too! So by removing most of the noise in the gaps, we avoided &lt;code&gt;level_in=6&lt;/code&gt; to increase them too! And the same goes for the high- and lowpass filtering.&lt;/p&gt;
&lt;h3 id=&quot;changing-the-volume&quot;&gt;Changing the volume&lt;/h3&gt;
&lt;p&gt;Now, if we want to make the result a bit louder, we could increase the previous step’s &lt;code&gt;makeup&lt;/code&gt; argument, or leverage the volume &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#volume&quot;&gt;filter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While we are at it, let’s cut the first 4 seconds too with &lt;code&gt;-ss 4&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-ss &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt; -i&lt;/span&gt;&lt;span&gt; gate_eq_comp.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;volume=1.1&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gate_eq_volume_comp.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s hear it: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-2-gate_eq_volume_comp.wav&quot;&gt;gate_eq_volume_comp.wav&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;lets-make-audio-gate-again&quot;&gt;Let’s make audio gate again&lt;/h3&gt;
&lt;p&gt;Excuse me for that title:)&lt;/p&gt;
&lt;p&gt;So as I’ve described earlier, compression can amplify the noises, so you might want to run the result through a gate again:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;gate_eq_volume_comp.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;agate=threshold=0.1:attack=50:release=50:ratio=1.5:knee=4&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gate_eq_volume_comp_gate.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s hear it: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-3-gate_eq_volume_comp_gate.wav&quot;&gt;gate_eq_volume_comp_gate.wav&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this case, I’ve used a softer gate, with &lt;code&gt;ratio=1.5&lt;/code&gt;. Because of this, I could use shorter attack and release delays too, as the attenuation is not that strong, it isn’t causing hard dips in the audio.&lt;/p&gt;
&lt;h3 id=&quot;putting-it-all-together&quot;&gt;Putting it all together&lt;/h3&gt;
&lt;p&gt;Just a single command could have achieved all the steps above:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ffmpeg&lt;/span&gt;&lt;span&gt; -y&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-i &lt;/span&gt;&lt;span&gt;voice_recording.wav&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-filter_complex &lt;/span&gt;&lt;span&gt;&quot;agate=threshold=0.01:attack=80:release=840:makeup=1:ratio=3:knee=8 , highpass=f=100:width_type=q:width=0.5 , lowpass=f=10000 , anequalizer=c0 f=250 w=100 g=2 t=1|c0 f=700 w=500 g=-5 t=1|c0 f=2000 w=1000 g=2 t=1 , acompressor=level_in=6:threshold=0.025:ratio=20:makeup=6 , volume=1.1 , agate=threshold=0.1:attack=50:release=50:ratio=1.5:knee=4&quot;&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gate_eq_volume_comp_gate_together.wav&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I just copy-pasted all the filters right after each other with a comma between them.&lt;/p&gt;
&lt;p&gt;Isn’t it beautiful? Yeah, it isn’t, but it is very practical:)&lt;/p&gt;
&lt;p&gt;For the last time, check out the difference:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Original: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-4-voice_recording.wav&quot;&gt;voice_recording.wav&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Final: &lt;a href=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/ffmpeg-audio/audio-3-gate_eq_volume_comp_gate.wav&quot;&gt;gate_eq_volume_comp_gate.wav&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It has less noise, more clear voice, and a small volume range. Therefore it is easy on your ears!&lt;/p&gt;
&lt;h3 id=&quot;what-else-1&quot;&gt;What else?&lt;/h3&gt;
&lt;p&gt;You might want to check out a few more &lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#toc-Audio-Filters&quot;&gt;filters&lt;/a&gt; that I didn’t cover here.&lt;/p&gt;
&lt;p&gt;Here are just a few interesting ones:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#adeclick&quot;&gt;adeclick&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#adeclip&quot;&gt;adeclip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#aecho&quot;&gt;aecho&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#deesser&quot;&gt;deesser&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html#alimiter&quot;&gt;alimiter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;documentation&quot;&gt;Documentation&lt;/h2&gt;
&lt;p&gt;For your convenience, let me list the most important documentations that might be important for you! Most of these were already linked many times in this article.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg.html&quot;&gt;FFmpeg main documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki&quot;&gt;FFmpeg WIKI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki/CompilationGuide&quot;&gt;FFmpeg compilation guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-filters.html&quot;&gt;FFmpeg filters documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://ffmpeg.org/ffmpeg-formats.html&quot;&gt;FFmpeg formats documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.264&quot;&gt;H.264 Video Encoding Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trac.ffmpeg.org/wiki/Encode/H.265&quot;&gt;H.265 Video Encoding Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you got this far from top to bottom, then you are a true hero! I hope you enjoyed this, and I also hope that it inspired you to create something awesome with FFmpeg! Please consider &lt;a href=&quot;https://ffmpeg.org/donations.html&quot;&gt;donating&lt;/a&gt; to FFmpeg – they are fantastic.&lt;/p&gt;
&lt;p&gt;If you’re looking to take your creative projects to the next level, check out our products - &lt;a href=&quot;https://img.ly/products/creative-sdk/&quot;&gt;Creative Editor SDK&lt;/a&gt;, &lt;a href=&quot;https://img.ly/products/video-sdk/&quot;&gt;Video Editor SDK&lt;/a&gt;, and &lt;a href=&quot;https://img.ly/products/photo-sdk/&quot;&gt;Photo Editor SDK&lt;/a&gt;. These versatile tools empower you to bring your vision to life, whether you’re editing images, crafting stunning videos, or unleashing your artistic talents.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thanks for reading! Let us know what you think on&lt;/strong&gt; &lt;a href=&quot;https://twitter.com/imgly&quot;&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;! To stay in the loop, subscribe to our&lt;/strong&gt; &lt;a href=&quot;https://img.us13.list-manage.com/subscribe?u=dc9f652839dbb620d14d6d28d&amp;#x26;id=04a306e4b2&quot;&gt;&lt;strong&gt;Newsletter&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;</content:encoded><dc:creator>Csaba</dc:creator><media:content url="https://blog.img.ly/2022/11/FFmpeg_ultimate_guide.png" medium="image"/><category>FFmpeg</category><category>Video App</category><category>Audio</category><category>Tech</category><category>Tutorial</category></item><item><title>Time-Based Sprites for VE.SDK on iOS and Android</title><link>https://img.ly/blog/time-based-sprites-for-ve-sdk-on-ios-and-android/</link><guid isPermaLink="true">https://img.ly/blog/time-based-sprites-for-ve-sdk-on-ios-and-android/</guid><description>Time-Based Sprites allow basic keyframing by setting the duration of your Text and Stickers in Videos. </description><pubDate>Mon, 05 Sep 2022 07:06:05 GMT</pubDate><content:encoded>&lt;p&gt;We are happy to extend VideoEditor SDK with a highly-requested feature: &lt;strong&gt;Time-Based Sprites&lt;/strong&gt;. This new feature sets the &lt;strong&gt;duration of text&lt;/strong&gt; and &lt;strong&gt;stickers&lt;/strong&gt; in your video timeline. Users may now place fun stickers and text at the right moment, and give their videos a special touch.&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/basic-keyframe-video-editing.MP4&quot; controls autoplay muted loop playsinline&gt;&lt;/video&gt;&lt;/p&gt;
&lt;h2 id=&quot;time-based-sprites&quot;&gt;Time-Based Sprites&lt;/h2&gt;
&lt;p&gt;The popular feature known from TikTok and Instagram Reels is now available in VE.SDK: set the starting and end point of your text or sticker. Tap your text or sticker and select &lt;em&gt;Duration&lt;/em&gt; to determine the duration of your asset.&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://storage.googleapis.com/imgly-static-assets/static/blog/video-editor-sdk-white-label-edit.MOV&quot; controls autoplay muted loop playsinline&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;Unless you have specified a custom set of sticker or text actions, this feature is &lt;strong&gt;enabled by default&lt;/strong&gt; since VE.SDK v10.3.0 for Android and v11.3.0 for iOS. See the official &lt;a href=&quot;https://img.ly/docs/vesdk/ios/guides/trim/?utm_source=imgly&amp;#x26;utm_medium=blog&amp;#x26;utm_campaign=releasenotes&quot;&gt;documentation for iOS&lt;/a&gt; or &lt;a href=&quot;https://img.ly/docs/vesdk/android/guides/trim/?utm_source=imgly&amp;#x26;utm_medium=blog&amp;#x26;utm_campaign=releasenotes#trim-sprite-duration&quot;&gt;Android&lt;/a&gt; on Time-Based Sprites.&lt;/p&gt;
&lt;h3 id=&quot;why-is-video-important&quot;&gt;Why is Video Important?&lt;/h3&gt;
&lt;p&gt;Video content has become an essential medium for social media, marketing, sales, and support teams. According to marketing &lt;a href=&quot;https://www.wyzowl.com/video-marketing-statistics/&quot;&gt;statistics&lt;/a&gt;, people are watching an average of &lt;strong&gt;19 hours&lt;/strong&gt; of online video per week in 2022. &lt;strong&gt;88%&lt;/strong&gt; of people say that they felt convinced to buy a product or service by watching a brand’s video. The growing trend and preference of consumers are why businesses are shifting their attention toward including videos in their strategies and applications.&lt;/p&gt;
&lt;p&gt;We commit to extending our video editing features to help developers meet the demand, save resources and streamline the process of building great applications. Let us have a look at our &lt;strong&gt;previous VE.SDK releases&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Video Composition&lt;/strong&gt;&lt;br&gt;
Users may seamlessly edit their footage by trimming and adjusting video files with advanced filters. Finally, they can set the correct order of their video sequences to create a single composition.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Audio Support&lt;/strong&gt;&lt;br&gt;
Replace or add sound in videos by loading audio files. Users can trim their audio according to their footage. Developers can provide media libraries for audio and video files. That way, users may access media by choosing from labeled folders, such as genre, theme, or artist names.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Force Trim&lt;/strong&gt;&lt;br&gt;
The VE.SDK trim tool allows users to determine the start and end frame of a video clip and change the duration of their footage. Now you can enforce a &lt;strong&gt;minimum and maximum length&lt;/strong&gt; of videos. Force Trim will come in handy for use cases, such as social media stories and posts popularly limited to bite size 15 or 60 seconds by widely loved apps – see TikTok or Instagram. Adopting a ready-to-use solution like &lt;a href=&quot;https://img.ly/products/video-sdk/&quot;&gt;VE.SDK&lt;/a&gt; will set you on your path to creating equally beautiful apps.&lt;/p&gt;
&lt;p&gt;Thanks for reading! Let us know what you think on &lt;a href=&quot;https://twitter.com/imgly&quot;&gt;Twitter&lt;/a&gt; – or check out our &lt;a href=&quot;https://photoeditorsdk.us13.list-manage.com/subscribe?u=dc9f652839dbb620d14d6d28d&amp;#x26;id=04a306e4b2&quot;&gt;Newsletter&lt;/a&gt; for more accelerating updates.&lt;/p&gt;</content:encoded><dc:creator>Neslihan</dc:creator><media:content url="https://blog.img.ly/2022/08/video-editor-sdk-duration-trim-stickers-keyframes.png" medium="image"/><category>Release Notes</category><category>VE.SDK</category><category>Android</category><category>Android App Development</category><category>iOS</category><category>iOS App Development</category><category>Video Editing</category><category>Video App</category><category>Keyframe</category><category>Company</category></item></channel></rss>