ffmpeg.html 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. <!DOCTYPE html>
  2. </ul></div></nav></div></header><div class="site-inner"><div class="content-sidebar-wrap"><main class="content" id="genesis-content"><div class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">You are here: <span class="breadcrumb-link-wrap" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a class="breadcrumb-link" href="https://itsfoss.com/" itemprop="item"><span class="breadcrumb-link-text-wrap" itemprop="name">Home</span></a><meta itemprop="position" content="1"></span> <span aria-label="breadcrumb separator">/</span> <span class="breadcrumb-link-wrap" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a class="breadcrumb-link" href="https://itsfoss.com/category/how-to/" itemprop="item"><span class="breadcrumb-link-text-wrap" itemprop="name">How To</span></a><meta itemprop="position" content="2"></span> <span aria-label="breadcrumb separator">/</span> The Complete Guide for Using ffmpeg in Linux</div><article class="post-52828 post type-post status-publish format-standard has-post-thumbnail category-how-to tag-debian tag-editing tag-ffmpeg tag-guide tag-how-to tag-ubuntu entry" itemscope itemtype="https://schema.org/CreativeWork"><header class="entry-header"><h1 class="entry-title" itemprop="headline">The Complete Guide for Using ffmpeg in Linux</h1>
  3. <p class="entry-meta">Last updated <time class="entry-modified-time" itemprop="dateModified" datetime="2019-04-16T05:14:43+02:00">April 16, 2019</time> By <span class="entry-author" itemprop="author" itemscope itemtype="https://schema.org/Person"><a href="https://itsfoss.com/author/sergiu/" class="entry-author-link" itemprop="url" rel="author"><span class="entry-author-name" itemprop="name">Sergiu</span></a></span> <span class="entry-comments-link"><a href="https://itsfoss.com/ffmpeg/#comments">23 Comments</a></span> </p></header><div align="center" id="itsfoss_728x90_320x50_ATF">
  4. <script data-cfasync="false" type='text/javascript'>
  5. freestar.queue.push(function () { googletag.display('itsfoss_728x90_320x50_ATF'); });
  6. </script>
  7. </div>
  8. <div class="entry-content" itemprop="text">
  9. <p><strong><em>Brief: This detailed guide shows how to install ffmpeg in Ubuntu and other Linux distributions. It also demonstrates some useful ffmpeg commands for practical usage.</em></strong></p>
  10. <p><strong><a rel="noreferrer noopener nofollow" aria-label="ffmpeg (opens in a new tab)" href="https://ffmpeg.org/" target="_blank" class="external">ffmpeg</a></strong> is a CLI (command line based) utility for processing media files. It is a framework with a multitude of features and, because of it&#8217;s open source license, it is the base for many widespread apps such as VLC, YouTube, iTunes and many more. A number of <a rel="noreferrer noopener" aria-label="Linux video editors (opens in a new tab)" href="https://itsfoss.com/best-video-editing-software-linux/" target="_blank">Linux video editors</a> use ffmpeg underneath the GUI.</p>
  11. <p>What I love even more about <strong>ffmpeg</strong> is that it can be used on it&#8217;s own to accomplish many processing tasks in a very simple manner (with one or two commands). However, it&#8217;s a very powerful program that can be used in more complex ways and even replace an editing workflow.</p>
  12. <p>In this ffmpeg tutorial, I&#8217;ll show you how to install <strong>ffmpeg</strong> and I&#8217;ll be covering it&#8217;s different uses. I&#8217;ll even get into some more complex features.</p><div id="eaa_after_nth_p" class="eaa-wrapper eaa_after_nth_p eaa_desktop"><div class="eaa-ad " style=""><!-- code from sekindo - Itsfoss.com In-article - outstream -->
  13. <script type="text/javascript" language="javascript" src="https://live.sekindo.com/live/liveView.php?s=97824&vid_viewAction=player&cbuster=[CACHE_BUSTER]&x=500&y=280&vid_outPause=0"></script>
  14. <!-- code from sekindo --></div></div>
  15. <p>Here are the sections of this guide:</p>
  16. <ul><li><a href="#install">Installing ffmpeg</a></li><li><a href="#basic-usage">Basic Usage of ffmpeg</a></li><li><a href="#advanced-usage">Advanced Usage of ffmpeg</a></li><li><a href="#filters">Filter basics</a></li></ul>
  17. <p>I&#8217;ll be explaining everything in detail so you can understand what is going on even if you are new to the Linux world.</p>
  18. <p>I&#8217;ll be using <strong>Ubuntu 18.04</strong>, but these commands should work for other distributions too.</p>
  19. <p><strong>Note:</strong> <em>Although I&#8217;ve researched <strong>ffmpeg </strong>thoroughly and tested everything I&#8217;ll mention in this article, I don&#8217;t edit videos (or other media) on a daily basis. If you have any suggestions, tips or corrections, let me know in the comments!</em></p>
  20. <p>Let&#8217;s get for it!</p>
  21. <div class="wp-block-image"><figure class="aligncenter"><img src="https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-tutorial-800x450.png" alt="Complete guide for using ffmpeg on Linux" class="wp-image-53574" srcset="https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-tutorial.png 800w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-tutorial-300x169.png 300w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-tutorial-768x432.png 768w" sizes="(max-width: 800px) 100vw, 800px" /></figure></div>
  22. <h2 id="install">Installing ffmpeg on Ubuntu &amp; other Linux</h2>
  23. <p>Installing <strong>ffmpeg</strong> is a straightforward process. It&#8217;s a popular application and is available in most of the Linux distribution through the package manager.</p>
  24. <h3>Install ffmpeg in Ubuntu</h3>
  25. <p>In Ubuntu, ffmpeg is available in the Universe repository so make sure to <a rel="noreferrer noopener" aria-label="enable universe repository (opens in a new tab)" href="https://itsfoss.com/ubuntu-repositories/" target="_blank">enable universe repository</a>. and then update the packages list and install ffmpeg. You can do all these using the below commands in a terminal:</p>
  26. <pre class="wp-block-preformatted">sudo add-apt-repository universe<br>sudo apt update<br>sudo apt install ffmpeg</pre>
  27. <p>That should be it! You can verify the install with simply typing:</p>
  28. <pre class="wp-block-preformatted">ffmpeg</pre>
  29. <p>This should display some text describing your <strong>ffmpeg</strong> configuration (including <strong>version</strong>).</p>
  30. <div class="wp-block-image"><figure class="aligncenter"><img src="https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-e1553925476276-800x148.jpg" alt="ffmpeg version in Ubuntu" class="wp-image-52887" srcset="https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-e1553925476276.jpg 800w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-e1553925476276-300x56.jpg 300w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg-e1553925476276-768x142.jpg 768w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption>ffmpeg vversion</figcaption></figure></div>
  31. <p>As you can see from the screenshot above, the <strong>installed version</strong> is <strong>3.4.4</strong>. However, the <strong>latest version</strong> of <strong>ffmpeg</strong> at the moment of writing this article is <strong>4.1</strong>. To install any <strong>4.x</strong> version, you&#8217;ll have to use the <strong>ffmpeg ppa</strong>. Click to expand the next section to see the details of ffmpeg installation via PPA.</p>
  32. <div class="wp-block-atomic-blocks-ab-accordion ab-block-accordion ab-font-size-18"><details><summary class="ab-accordion-title">Install the latest ffmpeeg in Ubuntu-based distros with PPA</summary><div class="ab-accordion-text">
  33. <p>There is an unofficial <a href="https://itsfoss.com/ppa-guide/" target="_blank" rel="noreferrer noopener" aria-label="PPA (opens in a new tab)">PPA</a> that you can use to install the latest ffmpeg release. Simply use these commands:</p>
  34. <pre class="wp-block-preformatted">sudo add-apt-repository ppa:jonathonf/ffmpeg-4<br>sudo apt update<br>sudo apt install ffmpeg -y</pre>
  35. </div></details></div>
  36. <h3>Install ffmpeg in Arch-based distributions</h3>
  37. <p>To install ffmpeg in <a href="https://www.archlinux.org/" target="_blank" rel="noreferrer noopener nofollow" aria-label="Arch (opens in a new tab)" class="external">Arch</a>-based distributions, use the following command:</p>
  38. <pre class="wp-block-preformatted">sudo pacman -S ffmpeg</pre>
  39. <h3>Install ffmpeg in Fedora-based distributions</h3>
  40. <p>To install ffmpeg in <a href="https://itsfoss.com/best-fedora-linux-distributions/" target="_blank" rel="noreferrer noopener" aria-label="Fedora-based Linux distributions (opens in a new tab)">Fedora-based Linux distributions</a>, you can use this command:</p>
  41. <pre class="wp-block-preformatted">sudo dnf install ffmpeg</pre>
  42. <h2 id="basic-usage">How to use ffmpeg: The Basics</h2>
  43. <p>With <strong>ffmpeg</strong> installed, I&#8217;ll go over basic commands to get you started using this powerful tool.</p>
  44. <h3>0. ffmpeg Commands</h3>
  45. <p>The <strong>basic form</strong> a <strong>ffmpeg command</strong> is:</p>
  46. <pre class="wp-block-preformatted">ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...</pre>
  47. <p>You have to keep in mind that all file options apply only to the file that follows them (you&#8217;ll have to write them again for the next file).</p>
  48. <p>Any file not preceded by <strong>-i</strong> is considered an output file. <strong>Ffmpeg</strong> uses as many inputs and outputs as you provide. You can also use the same name for both an input and an output file, but you&#8217;ll have to add the <strong>-y</strong> tag before the output file name.</p>
  49. <div style="color:#32373c;background-color:#ff3860" class="wp-block-atomic-blocks-ab-notice ab-font-size-18 ab-block-notice" data-id="3b0649"><div class="ab-notice-title" style="color:#fff"><p>Note</p></div><div class="ab-notice-text" style="border-color:#ff3860"><p><em>You shouldn&#8217;t <strong>mix</strong> inputs and outputs; specify input files first, then specify output files.</em></p></div></div>
  50. <h3>1. Get media file information</h3>
  51. <p>The first use of <strong>ffmpeg</strong> is <strong>displaying information</strong> about a media file. This can be done by not entering any output files. Simply type:</p>
  52. <pre class="wp-block-preformatted">ffmpeg -i file_name</pre>
  53. <p>This works for both audio and video files:</p>
  54. <pre class="wp-block-preformatted">ffmpeg -i video_file.mp4 <br>ffmpeg -i audio_file.mp3</pre>
  55. <div class="wp-block-image"><figure class="aligncenter"><img src="https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information.jpg?fit=800%2C607&amp;ssl=1" alt="Display information about a media file with ffmpeg" class="wp-image-52956" srcset="https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information.jpg 800w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information-300x228.jpg 300w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information-768x583.jpg 768w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption>Display information about a media file with ffmpeg</figcaption></figure></div>
  56. <p>Although useful, this command will display way too much information that isn&#8217;t relevant to your file (information about ffmpeg). To omit that, add the <strong>-hide_banner</strong> flag:</p>
  57. <pre class="wp-block-preformatted">ffmpeg -i video_file.mp4 -hide_banner <br>ffmpeg -i audio_file.mp3 -hide_banner</pre>
  58. <div class="wp-block-image"><figure class="aligncenter"><img src="https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information_hide_banner.jpg?fit=800%2C276&amp;ssl=1" alt="Display relevant information about a media file with ffmpeg." class="wp-image-52958" srcset="https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information_hide_banner.jpg 800w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information_hide_banner-300x104.jpg 300w, https://itsfoss.com/wp-content/uploads/2019/03/ffmpeg_file_information_hide_banner-768x265.jpg 768w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption>Display info of a media file using ffmpeg</figcaption></figure></div>
  59. <p>As you can see, the command now outputs only details concerning the media file you specified (encoder, streams etc.).</p>
  60. <h3>2. Convert Media Files</h3>
  61. <p>Another very useful way to use <strong>ffmpeg</strong> is for hassle-free <strong>conversion</strong> between different media formats. You only have to specify input and output files, since <strong>ffmpeg</strong> will get the required format from the file extensions. This works for video-to-video and audio-to-audio conversions.</p>
  62. <p>Here are some examples:</p>
  63. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 video_output.avi <br>ffmpeg -i video_input.webm video_output.flv <br>ffmpeg -i audio_input.mp3 audio_output.ogg <br>ffmpeg -i audio_input.wav audio_output.flac</pre>
  64. <p>You can even specify more output files:</p>
  65. <pre class="wp-block-preformatted">ffmpeg -i audio_input.wav audio_output_1.mp3 audio_output_2.ogg</pre>
  66. <p>This will convert the input files to all specified formats.</p>
  67. <p>To see a list of all supported formats, use:</p>
  68. <pre class="wp-block-preformatted">ffmpeg -formats</pre>
  69. <p>Again, you can add <strong>-hide_banner</strong> to omit information about the app.</p>
  70. <p>You can specify the <strong>-qscale 0</strong> parameter before the output file to preserve the quality of a video file:</p>
  71. <pre class="wp-block-preformatted">ffmpeg -i video_input.wav -qscale 0 video_output.mp4</pre>
  72. <p>Additionally, you could specify <strong>codecs</strong> you want to use, adding <strong>-c:a</strong> (for <strong>audio</strong>) and <strong>-c:v</strong> (for <strong>video</strong>) followed by the name of the codecs, or <strong>copy</strong> if you want to use the same codecs as the original file:</p>
  73. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -c:v copy -c:a libvorbis video_output.avi</pre>
  74. <p><strong>Note:</strong> <em>this might make the file extension rather deceiving, so be careful.</em></p>
  75. <h3>3. Extract Audio from Video</h3>
  76. <p>To <strong>extract audio</strong> from a video file, you do a simple conversion and add the <strong>-vn</strong> flag:</p>
  77. <pre class="wp-block-preformatted">ffmpeg -i video.mp4 -vn audio.mp3</pre>
  78. <p>Note that this command will utilize the <strong>bit rate</strong> of the original file. It&#8217;s a good idea to set it yourself; you can use <strong>-ab</strong> (audio bit rate):</p>
  79. <pre class="wp-block-preformatted">ffmpeg -i video.mp4 -vn -ab 128k audio.mp3</pre>
  80. <p>Some <strong>common bit rates</strong> are 96k, 128k, 192k, 256k, 320k (highest bitrate supported by mp3).</p>
  81. <p>Other <strong>common options</strong> are <strong>-ar</strong> (<strong>audio frequency</strong>: 22050, 441000, 48000), <strong>-ac</strong> (number of <strong>audio channels</strong>), <strong>-f</strong> (<strong>audio format</strong>, although normally automatically detected). <strong>-ab</strong> can also be replaced by <strong>-b:a</strong>. For example:</p>
  82. <pre class="wp-block-preformatted">ffmpeg -i video.mov -vn -ar 44100 -ac 2 -b:a 128k -f mp3 audio.mp3</pre>
  83. <h3>4. Mute Audio in Video</h3>
  84. <p>Similar to the last task, to accomplish this we&#8217;ll add a simple tag: <strong>-an</strong> (instead of <strong>-vn</strong>).</p>
  85. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -an -video_output.mp4</pre>
  86. <p><strong>Note:</strong> <em>The <strong>-an</strong> tag will render all audio options for that output file useless, since there will be no audio in the result of the operation. </em></p>
  87. <h3>5. Extract Images from Video</h3>
  88. <p>This might come in handy for a lot of people. For example, you might have a series of images (e.g. a slideshow) and you want to get all images out of that. Simply enter:</p>
  89. <pre class="wp-block-preformatted">ffmpeg -i video.mp4 -r 1 -f image2 image-%3d.png</pre>
  90. <p>Let&#8217;s take that apart for a second.</p>
  91. <p><strong>-r</strong> specifies the frame rate (how many frames are extracted into images in one second, <strong>default</strong>: 25), <strong>-f</strong> specifies the output format (<strong>image2</strong> actually stands for image2 sequence.</p>
  92. <p>The last parameter (the output file) has a somewhat interesting naming: it uses <strong>%3d</strong> at the end. This simply numbers your images with 3 digits (000, 001, etc.). You can also use <strong>%2d</strong> (2 digit format) or even <strong>%4d</strong> (4 digit format) if you want. Feel free to experiment and use whatever works for you!</p>
  93. <p><strong>Note:</strong> <em>There is also a way to turn a set of images into a video/slideshow. I&#8217;ll cover that in the <strong>Advanced Usage</strong> section</em>.</p>
  94. <h3>6. Change Video Resolution or Aspect Ratio</h3>
  95. <p>Another simple task for <strong>ffmpeg</strong>. All you have to do to <strong>resize</strong> a video is specify a new resolution after the <strong>-s</strong> flag:</p>
  96. <pre class="wp-block-preformatted">ffmpeg -i video_input.mov -s 1024x576 video_output.mp4</pre>
  97. <p>Additionally, you might want to specify <strong>-c:a</strong> to make sure the audio codecs of the output file is the right one:</p>
  98. <pre class="wp-block-preformatted">ffmpeg -i video_input.h264 -s 640x480 -c:a video_output.mov</pre>
  99. <p>You can also change the <strong>aspect ratio</strong> using <strong>-aspect</strong>:</p>
  100. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -aspect 4:3 video_output.mp4</pre>
  101. <p><strong>Note:</strong> <em>Once again, another slightly more powerful method will be mentioned in the <strong>Advanced Usage</strong> section.</em></p>
  102. <h3>7. Add Poster Image to Audio</h3>
  103. <p>This is a great way to <strong>turn audio into video</strong>, using a single photo (such as a album cover) for the audio. This is a very useful feature when you want to upload audio files to sites that don&#8217;t allow anything other than video/images (YouTube and Facebook are two examples of such sites).</p>
  104. <div style="clear:both; margin-top:0em; margin-bottom:1em;"><a href="https://itsfoss.com/fix-empty-trash-ubuntu/" target="_blank" class="ufb4baeef01d52cc1620e10dcbdfbcb4e"><!-- INLINE RELATED POSTS 1/2 //--><style> .ufb4baeef01d52cc1620e10dcbdfbcb4e { padding:0px; margin: 0; padding-top:1em!important; padding-bottom:1em!important; width:100%; display: block; font-weight:bold; background-color:#eaeaea; border:0!important; border-left:4px solid #34495E!important; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); text-decoration:none; } .ufb4baeef01d52cc1620e10dcbdfbcb4e:active, .ufb4baeef01d52cc1620e10dcbdfbcb4e:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; text-decoration:none; } .ufb4baeef01d52cc1620e10dcbdfbcb4e { transition: background-color 250ms; webkit-transition: background-color 250ms; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; } .ufb4baeef01d52cc1620e10dcbdfbcb4e .ctaText { font-weight:bold; color:inherit; text-decoration:none; font-size: 16px; } .ufb4baeef01d52cc1620e10dcbdfbcb4e .postTitle { color:#000000; text-decoration: underline!important; font-size: 16px; } .ufb4baeef01d52cc1620e10dcbdfbcb4e:hover .postTitle { text-decoration: underline!important; } </style><div style="padding-left:1em; padding-right:1em;"><span class="ctaText">Suggested read</span>&nbsp; <span class="postTitle">Fix Cannot Empty Trash In Ubuntu 14.04 [Quick Tip]</span></div></a></div><p>Here is an example:</p>
  105. <pre class="wp-block-preformatted">ffmpeg -loop 1 -i image.jpg -i audio.wav -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4</pre>
  106. <p>Just change the <strong>codecs</strong> (<strong>-c:v</strong> specifies <strong>video</strong> codecs, <strong>-c:a</strong> specifies <strong>audio</strong> codecs) and the <strong>names</strong> of your files.</p>
  107. <p><strong>Note:</strong> <em>You don&#8217;t have to use <strong>-strict experimental</strong> if you are using a newer version (<strong>4.x</strong>).</em></p>
  108. <h3>8. Add Subtitles to Video</h3>
  109. <p>Equally as useful and as simple to do with <strong>ffmpeg</strong> is to <strong>add subtitles</strong> to a video (for example a movie). Enter the following:</p>
  110. <pre class="wp-block-preformatted">ffmpeg -i video.mp4 -i subtitles.srt -c:v copy -c:a copy -preset veryfast -c:s mov_text -map 0 -map 1 output.mp4</pre>
  111. <p>Of course, you can specify any codecs that you want (and any other additional options related to audio/video). You can read this article about <a rel="noreferrer noopener" aria-label="editing subtitles in Linux (opens in a new tab)" href="https://itsfoss.com/editing-subtitles/" target="_blank">editing subtitles in Linux</a>, graphically.</p>
  112. <h3>9. Compress Media Files</h3>
  113. <p><strong>Compressing</strong> files greatly reduces file size, saving you a lot of space. This can be important for transferring files. With <strong>ffmpeg</strong>, there are multiple methods to reduce file size.</p>
  114. <p><strong>Note:</strong> <em>Compressing files too much will noticeably reduce the quality of the resulting file.</em></p>
  115. <p>First of all, for <strong>audio</strong> files, simply <strong>reduce</strong> the <strong>bit rate</strong> (using <strong>-b:a</strong> or <strong>-ab</strong>):</p>
  116. <pre class="wp-block-preformatted">ffmpeg -i audio_input.mp3 -ab 128k audio_output.mp3
  117. ffmpeg -i audio_input.mp3 -b:a 192k audio_output.mp3</pre>
  118. <p>Again, some different bit rate values are: 96k, 112k, 128k, 160k, 192k, 256k, 320k. The higher the bit rate, the higher the file size and the quality.</p>
  119. <p>For <strong>video</strong> files, you have more options. One way would be to reduce the <strong>video bit rate</strong> (using <strong>-b:v</strong>):</p>
  120. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -b:v 1000k -bufsize 1000k video_output.mp4</pre>
  121. <p><strong>Note:</strong> <em>Video bit rates are <strong>different</strong> from audio bit rates (much higher values).</em></p>
  122. <p>You could set the <strong>-crf</strong> flag (<strong>Constant Rate Factor</strong>). A lower <strong>crf</strong> means a higher bit rate. Also, using <strong>libx264</strong> as <strong>video codec</strong> helps. Here&#8217;s a very efficient size reduction with very small reduction in quality:</p>
  123. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -c:v libx264 -crf 28 video_output.mp4</pre>
  124. <p>A <strong>crf</strong> of 20 to 30 is common, but feel free to play around with the specific value.</p>
  125. <p>Reducing the <strong>frame rate</strong> might work in some cases (although it might very easily make the video feel sluggish):</p>
  126. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -r 24 video_output.mp4</pre>
  127. <p><strong>-r</strong> specifies the <strong>frame rate</strong> (in this case <strong>24</strong>).</p>
  128. <p>You could also try reducing the <strong>size </strong>of the video (already explained how do to that). An additional tip is to<strong> compress</strong> the <strong>audio</strong> too, making it <strong>stereo </strong>and reducing the <strong>bit rate</strong>. For example:</p>
  129. <pre class="wp-block-preformatted">ffmpeg -i video_input.mp4 -c:v libx264 -ac 2 -c:a aac -strict -2 -b:a 128k -crf 28 video_output.mp4</pre>
  130. <p><strong>Note:</strong> <em><strong>-strict -2</strong> and <strong>-ac 2</strong> take care of the stereo part. I already covered the part that reduces the <strong>bit rate</strong></em>.</p>
  131. <h3>10. Cut Media Files (Basic)</h3>
  132. <p>To <strong>trim</strong> files from the <strong>beginning</strong> you have to specify a <strong>duration</strong> using <strong>-t</strong>:</p>
  133. <pre class="wp-block-preformatted">ffmpeg -i input_video.mp4 -t 5 output_video.mp4 <br>ffmpeg -i input_audio.wav -t 00:00:05 output_audio.wav</pre>
  134. <p>As you can see, this works for both <strong>video</strong> and <strong>audio</strong> files. Both of the commands above do the same thing: save the first 5 seconds of the input file to the output file. I have used to different ways of inputting the <strong>duration</strong>: a single number (number of seconds) and <strong>HH:MM:SS</strong> (hours, minutes, seconds). The second version acts more like an <strong>end time</strong>.</p>
  135. <p>You can go even further by specifying a <strong>start time</strong> with <strong>-ss</strong>, and even an <strong>end time</strong> with <strong>-to</strong>:</p>
  136. <pre class="wp-block-preformatted">ffmpeg -i input_audio.mp3 -ss 00:01:14 output_audio.mp3<br>ffmpeg -i input_audio.wav -ss 00:00:30 -t 10 output_audio.wav <br>ffmpeg -i input_video.h264 -ss 00:01:30 -to 00:01:40 output_video.h264 <br>ffmpeg -i input_audio.ogg -ss 5 output_audio.ogg</pre>
  137. <p>You can see <strong>start time</strong> (<strong>-ss HH:MM:SS</strong>), <strong>duration</strong> (<strong>-t duration</strong>) in seconds, <strong>end time</strong> (<strong>-to HH:MM:SS</strong>), and <strong>start time</strong> (<strong>-s duration</strong>) in seconds (starting after <strong>duration</strong> seconds).</p>
  138. <p>All these are valid commands and you can work with any part of a media file using them.</p>
  139. <h2 id="advanced-usage">How to use ffmpeg: Advanced Usage</h2>
  140. <p>I&#8217;ll now cover slightly more advanced features (such as screen casting, using devices etc.). Let&#8217;s get right to the first point!</p>
  141. <h3>1. Split Media Files</h3>
  142. <p>I already covered <strong>trimming</strong> files. What you have to do to <strong>split</strong> a file <strong>into multiple parts</strong> is to specify multiple <strong>trims</strong> (specifying <strong>start times</strong>, <strong>end times</strong> or <strong>duration</strong> before each output files).</p>
  143. <p>Observe this example:</p>
  144. <pre class="wp-block-preformatted">ffmpeg -i video.mp4 -t 00:00:30 video_1.mp4 -ss 00:00:30 video_2.mp4</pre>
  145. <p>The syntax is quite simple. I specified <strong>-t 00:00:30</strong> as <strong>duration</strong> for the first part (the first part will consist of the first 30 seconds of the original video). Next, I specified that I&#8217;d like the rest to be part of a second video (starting from the end of the last part, <strong>00:00:30</strong>).</p>
  146. <p>This can be done for as many parts as you want! Have fun playing with this feature, since it is very powerful. Keep in mind that it works with audio too.</p>
  147. <h3>2. Concatenate Media Files</h3>
  148. <p><strong>ffmpeg</strong> can also do the opposite process: putting multiple parts together.</p>
  149. <p>To do so, you&#8217;ll have to <strong>create</strong> a new <strong>text file</strong> and start <strong>editing</strong> it using your preferred editor.</p>
  150. <p>Since I like using the terminal, I&#8217;ll use <strong>touch</strong> and <strong>vim</strong>. It doesn&#8217;t matter what you call this file. I&#8217;ll call mine <strong>join.txt</strong> and create the file using <strong>touch</strong>:</p>
  151. <pre class="wp-block-preformatted">touch videos_to_join.txt</pre>
  152. <p>Now, I&#8217;ll edit it using <strong>vim</strong>:</p>
  153. <pre class="wp-block-preformatted">vim videos_to_join.txt</pre>
  154. <p>You can use whatever tools you want (nano, gedit, etc.), this is just what it&#8217;s the easiest for me to use.</p>
  155. <p>Here, enter the <strong>full paths</strong> to all the files you wish to <strong>join</strong> (they will be joined in the order you write them here), one per line. Make sure they have the same extension (e.g. <strong>mp4</strong>). Here&#8217;s mine:</p>
  156. <pre class="wp-block-preformatted">/home/ubuntu/Desktop/video_1.mp4<br>/home/ubuntu/Desktop/video_2.mp4<br>/home/ubuntu/Desktop/video_3.mp4</pre>
  157. <p>Save the file you just edited. This method works for any audio or video files.</p>
  158. <p>Now enter the following:</p>
  159. <pre class="wp-block-preformatted">ffmpeg -f concat -i join.txt output.mp4</pre>
  160. <p><strong>Note:</strong> <em>My output file is <strong>output.mp4</strong>, but that&#8217;s because all my input files have the <strong>mp4</strong> extension<strong>.</strong></em></p>
  161. <p>This should <strong>join</strong> all the files you wrote down in <strong>join.txt</strong> (or however you named that file) into one single output file.</p>
  162. <h3>3. Join Images into a Video</h3>
  163. <p>This is how you can put together a <strong>slideshow</strong> or anything similar. I&#8217;ll show you how to add <strong>audio</strong> too.</p>
  164. <p>The first thing I recommend doing is making sure the photos you want to put together are located in the same directory. I&#8217;ll put mine in a directory called <strong>my_photos</strong>. The <strong>extensions</strong> recommended for the pictures are <strong>.png</strong> and <strong>.jpg</strong>. Whichever you choose, make sure all images have the same extension (otherwise, using <strong>ffmpeg</strong> might have unintended effects). You could simply <strong>convert</strong> the <strong>.png</strong> files to <strong>.jpg</strong> or vice-versa (see <strong>Basic Usage</strong>).</p>
  165. <p>The <strong>format</strong> (<strong>-f</strong>) of our conversion should be <strong>image2pipe</strong>. For the input, you&#8217;ll have to provide a <strong>hyphen</strong> (<strong>&#8211;</strong>). What <strong>image2pipe</strong> allows you to do is <strong>pipe</strong> (using <strong>|</strong> in the terminal)the results of a command such as <strong>cat</strong> into <strong>ffmpeg</strong> instead of inputting all names one by one. That&#8217;s exactly what I&#8217;ll do. For this to work, we&#8217;ll also have to mention that we want the <strong>video codecs</strong> to be <strong>copied</strong> (<strong>-c:v copy</strong>) (to properly use the images):</p>
  166. <pre class="wp-block-preformatted">cat my_photos/* | ffmpeg -f image2pipe -i - -c:v copy video.mkv</pre>
  167. <p>If you play this file, you might think only some pictures were added to the slideshow. Actually, all of your pictures have been added, but <strong>ffmpeg</strong> cycles through them as fast as possible. This means 1 frame per photo; <strong>ffmpeg</strong> (by default) runs at around <strong>23 fps</strong>.</p>
  168. <p>To change that, you&#8217;ll have to specify the <strong>frame rate</strong> (<strong>-framerate</strong>) you want:</p>
  169. <pre class="wp-block-preformatted">cat my_photos/* | ffmpeg -framerate 1 -f image2pipe -i - -c:v copy video.mkv </pre>
  170. <p>In my example, I set the <strong>frame rate</strong> to <strong>1</strong>, that means that each frame (that also means each images) appears for <strong>1 second</strong>.</p>
  171. <p>To add <strong>audio</strong>, such as a background song, we&#8217;ll have to specify the <strong>audio file</strong> as <strong>input file</strong> (<strong>-i audo_file</strong>) and <strong>copy</strong> the <strong>audio codecs</strong> (<strong>-c:a copy</strong>). For the <strong>codecs</strong>, you could copy both audio and video codecs at the same time with <strong>-c copy</strong>. Make sure you set the codecs right before specifying the output file. You could also set the <strong>frame rate</strong> so that all of your pictures synchronize with the duration of the audio you want to use. To get that, <strong>divide</strong> the <strong>number of pictures</strong> by the <strong>duration of the audio (in seconds)</strong>. For my example, I have a 22 seconds long audio file and 9 images. 9 / 22 is approximately 0.40, so that&#8217;s what I&#8217;ll use for my frame rate:</p>
  172. <pre class="wp-block-preformatted">cat my_photos/* | ffmpeg -framerate 0.40 -f image2pipe -i - -i audio.wav -c copy video.mkv</pre>
  173. <h3>4. Record Your Screen</h3>
  174. <p><strong>Screencasting</strong> with <strong>ffmpeg</strong> is not a hard job. The <strong>format</strong> (<strong>-f</strong>) you need to use is <strong>x11grab</strong>. This will capture your <strong>XSERVER</strong>. As <strong>input</strong> you&#8217;ll have to specify your <strong>screen display number</strong> (main screen should normally be <strong>0:0</strong>). However, this will only capture a <strong>top-left portion</strong> of the screen. You should add a <strong>screen size</strong> (<strong>-s</strong>). Mine is <strong>1920&#215;1080</strong>. The <strong>screen size</strong> should be mentioned <strong>before</strong> the <strong>input</strong>:</p>
  175. <pre class="wp-block-preformatted">ffmpeg -f x11grab -s 1920x1080 -i :0.0 output.mp4</pre>
  176. <p>Press <strong>q</strong> or <strong>CTRL+C</strong> at any time to <strong>stop</strong> the <strong>screencast</strong>.</p>
  177. <div style="clear:both; margin-top:0em; margin-bottom:1em;"><a href="https://itsfoss.com/upgrade-ubuntu-14-04-to-14-10/" target="_blank" class="u1af35dcea294fbc7423b0873bad98d41"><!-- INLINE RELATED POSTS 2/2 //--><style> .u1af35dcea294fbc7423b0873bad98d41 { padding:0px; margin: 0; padding-top:1em!important; padding-bottom:1em!important; width:100%; display: block; font-weight:bold; background-color:#eaeaea; border:0!important; border-left:4px solid #34495E!important; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); text-decoration:none; } .u1af35dcea294fbc7423b0873bad98d41:active, .u1af35dcea294fbc7423b0873bad98d41:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; text-decoration:none; } .u1af35dcea294fbc7423b0873bad98d41 { transition: background-color 250ms; webkit-transition: background-color 250ms; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; } .u1af35dcea294fbc7423b0873bad98d41 .ctaText { font-weight:bold; color:inherit; text-decoration:none; font-size: 16px; } .u1af35dcea294fbc7423b0873bad98d41 .postTitle { color:#000000; text-decoration: underline!important; font-size: 16px; } .u1af35dcea294fbc7423b0873bad98d41:hover .postTitle { text-decoration: underline!important; } </style><div style="padding-left:1em; padding-right:1em;"><span class="ctaText">Suggested read</span>&nbsp; <span class="postTitle">How To Upgrade Ubuntu 14.04 To Ubuntu 14.10</span></div></a></div><p><strong>Bonus trick:</strong> You can make the size of the output file <strong>fullscreen</strong> with inputting this after for the <strong>size</strong> (instead of 1920&#215;1080 or any other set resolution):</p>
  178. <pre class="wp-block-preformatted">-s $(xdpyinfo | grep dimensions | awk '{print $2;}')</pre>
  179. <p>Here&#8217;s the full command:</p>
  180. <pre class="wp-block-preformatted">ffmpeg -f x11grab -s $(xdpyinfo | grep dimensions | awk '{print $2;}') -i :0.0 output.mp4</pre>
  181. <h3>5. Record Your Webcam</h3>
  182. <p><strong>Recording input</strong> from your <strong>webcam</strong> (or another device, such an usb camera) is even easier. In Linux, <strong>devices</strong> are stores in <strong>/dev</strong> as <strong>/dev/video0, /dev/video1, etc.</strong>:</p>
  183. <pre class="wp-block-preformatted">ffmpeg -i /dev/video0 output.mkv</pre>
  184. <p>Again, <strong>q</strong> or <strong>CTRL+C</strong> to <strong>stop recording</strong>.</p>
  185. <h3>6. Record Your Audio</h3>
  186. <p>Linux handles audio mainly through <strong>ALSA</strong> and <strong>pulseaudio</strong>. <strong>ffmpeg</strong> can <strong>record</strong> both, but I&#8217;ll cover <strong>pulseaudio</strong>, since Debian-based distributions include it by default. The syntax is a little different for the two methods.</p>
  187. <p>For <strong>pulseaudio</strong>, you have to <strong>force</strong> (<strong>-f</strong>) <strong>alsa</strong> and specify <strong>default</strong> as <strong>input</strong> (<strong>-i default</strong>):</p>
  188. <pre class="wp-block-preformatted">ffmpeg -f alsa -i default output.mp3</pre>
  189. <p><strong>Note:</strong> <em>In your distribution sound settings, make sure the <strong>default recording device</strong> is the one you want to record.</em></p>
  190. <p>I play guitar quite a lot and I have an audio interface so I can record it. I had a pleasant surprise when <strong>ffmpeg</strong> recorded my guitar with no problems.</p>
  191. <h3>Bonus Tips on Recording </h3>
  192. <p>For any type of recording you can also specify <strong>codecs</strong>, of course (already covered). You can choose a specific <strong>frame rate</strong> (<strong>-r</strong>). You can <strong>combine</strong> recording audio with webcam/screen recording too!</p>
  193. <pre class="wp-block-preformatted">ffmpeg -i /dev/video0 -f alsa -i default -c:v libx264 -c:a flac -r 30 output.mkv</pre>
  194. <p>Instead of recording audio, you can just as easily <strong>add</strong> an <strong>audio file</strong> as input to be recorded on top of your screencast/webcam:</p>
  195. <pre class="wp-block-preformatted">ffmpeg -f x11grab -s $(xdpyinfo | grep dimensions | awk '{print $2;}') -i :0.0 -i audio.wav -c:a copy output.mp4</pre>
  196. <p><strong>Note: </strong><em><strong>ffmpeg</strong> records in small pieces, so a really small recording might not get saved. I recommend recording just a little longer and cutting it afterwards (if you only want a few seconds), just to make sure the file will actually be written to your disk.</em></p>
  197. <h2 id="filters">Basic usage of Filters in ffmpeg</h2>
  198. <p><strong>Filters</strong> are an incredibly powerful feature of <strong>ffmpeg</strong>. There is a crazy amount of <strong>filters</strong> available for you to use, making <strong>ffmpeg</strong> completely capable of handling any <strong>editing </strong>needs. Since there are so many filters and this article is already comprehensive, I&#8217;ll only cover some simple filters.</p>
  199. <p>The <strong>basic structure</strong> for using a <strong>filter</strong> is:</p>
  200. <pre class="wp-block-preformatted">ffmpeg -i input.mp4 -vf "filter=setting_1=value_1:setting_2=value_2,etc" output.mp4
  201. ffmpeg -i input.wav -af "filter=setting_1=value_1:setting_2=value_2,etc" output.wav</pre>
  202. <p>As you can see, I am specifying <strong>video filters</strong> (<strong>-vf</strong>, short for <strong>-filter:v</strong>) and <strong>audio filters</strong> (<strong>-af</strong>, short for <strong>-filter:a</strong>). The actual filters are written inside <strong>double quotes</strong> (<strong>&#8220;</strong>) and can be chained by separating them with <strong>commas</strong> (<strong>,</strong>). You can specify as many filters as you want (I&#8217;ve written <strong>etc</strong> to note additional filters, it isn&#8217;t actually part of the command).</p>
  203. <p>The <strong>general form</strong> of a <strong>filter</strong> is:</p>
  204. <pre class="wp-block-preformatted">filter=setting_2=value_2:setting_2=value_2</pre>
  205. <p>The different <strong>filter settings</strong> and their <strong>values</strong> are separated by <strong>colons</strong>.</p>
  206. <p>You can also execute <strong>mathematical operations</strong> as <strong>values</strong> for the different <strong>settings</strong>.</p>
  207. <p><strong>Note:</strong> <em>More detailed coverage of different constants to be used in expressions and different settings can be found in the official </em><strong><em><a href="https://ffmpeg.org/ffmpeg-filters.html" target="_blank" rel="noreferrer noopener nofollow" aria-label=" (opens in a new tab)" class="external">ffmpeg filter documentation</a></em></strong><em><a href="https://ffmpeg.org/ffmpeg-filters.html" target="_blank" rel="noreferrer noopener nofollow" aria-label=" (opens in a new tab)" class="external">.</a></em></p>
  208. <p>I&#8217;ll cover both <strong>video</strong> and <strong>audio</strong> filters. Let&#8217;s see some examples!</p>
  209. <h3>1. Video Scaling</h3>
  210. <p>This is a very simple filter. The only <strong>settings</strong> are <strong>width</strong> and <strong>height</strong>:</p>
  211. <pre class="wp-block-preformatted">ffmpeg -i input.mp4 -vf "scale=w=800:h=600" output.mp4</pre>
  212. <p>I mentioned that you can use <strong>mathematical operations</strong> for <strong>values</strong> too:</p>
  213. <pre class="wp-block-preformatted">ffmpeg -i input.mkv -vf "scale=w=1/2*in_w:h=1/2*in_h" output.mkv</pre>
  214. <p>This command sets the <strong>output size</strong> to <strong>half</strong> (<strong>1/2</strong>) of the <strong>input size</strong> (<strong>in_w</strong>, <strong>in_h</strong>).</p>
  215. <h3>2. Video Cropping</h3>
  216. <p>As for the <strong>scaling filter</strong>, the <strong>settings</strong> are the <strong>width</strong> and <strong>height</strong> of the resulting file. Optionally, you can specify coordinates for the <strong>top-left corner</strong> of the cut (<strong>default:</strong> center of the input video):</p>
  217. <pre class="wp-block-preformatted">ffmpeg -i input.mp4 -vf "crop=w=1280:h=720:x=0:y=0" output.mp4 <br>ffmpeg -i input.mkv -vf "crop=w=400:h=400" output.mkv</pre>
  218. <p>As noted, the second cut will cut in the center of the input file (since I haven&#8217;t specified <strong>x</strong> and <strong>y</strong> coordinates for the top-left corner). The first command will cut from the top-left corner (<strong>x=0:y=0</strong>).</p>
  219. <p>Here is an example that uses <strong>mathematical expressions</strong> as <strong>values</strong>:</p>
  220. <pre class="wp-block-preformatted">ffmpeg -i input.mkv -vf "crop=w=3/4*in_w:h=3/4*in_h" output.mkv</pre>
  221. <p>This command sets the <strong>output size</strong> to <strong>3/4</strong> of the <strong>input size</strong> (<strong>in_w</strong>, <strong>in_h</strong>).</p>
  222. <h3>3. Video Rotation</h3>
  223. <p>You can also <strong>rotate</strong> a video <strong>clockwise</strong> by a <strong>value</strong> (<strong>in radians</strong>). To make things easier, you can specify a value in <strong>degrees</strong> and convert it to <strong>radians</strong> by <strong>multiplying</strong> that value with <strong>PI/180</strong>:</p>
  224. <pre class="wp-block-preformatted">ffmpeg -i input.avi -vf "rotate=90*PI/180" <br>ffmpeg -i input.mp4 -vf "rotate=PI"</pre>
  225. <p>The first command will <strong>rotate</strong> the video <strong>clockwise 90 degrees</strong>. The second command will <strong>turn</strong> the video <strong>upside-down</strong> (PI rad = 180 degrees).</p>
  226. <h3>4. Audio Channel Remapping</h3>
  227. <p>This can be helpful if you somehow only get <strong>audio</strong> in the <strong>right ear</strong> or anything similar. You can make the <strong>audio</strong> audible from both ears (in this particular case) like this:</p>
  228. <pre class="wp-block-preformatted">ffmpeg -i input.mp3 -af "channelmap=1-0|1-1" output.mp3</pre>
  229. <p>This <strong>maps</strong> the <strong>right</strong> (<strong>1</strong>) audio channel to both the <strong>left</strong> (<strong></strong>) and the <strong>right</strong> (<strong>1</strong>) audio channel. (the <strong>left number</strong> represents <strong>input</strong>, the <strong>right number</strong> represents <strong>output</strong>).</p>
  230. <h3>5. Audio Volume Multiplying</h3>
  231. <p>You can <strong>multiply</strong> the <strong>audio volume</strong> by any <strong>real</strong> number (integer or not). You only need to specify the <strong>multiplier</strong>:</p>
  232. <pre class="wp-block-preformatted">ffmpeg -i input.wav -af "volume=1.5" output.wav <br>ffmpeg -i input.ogg -af "volume=0.75" output.ogg</pre>
  233. <p>The first command <strong>amplifies</strong> the volume <strong>1.5</strong> times. The second command makes the audio <strong>1/4</strong> (0.25) times <strong>quieter</strong>.</p>
  234. <h3>Bonus Tip: Playback Speed Adjustments</h3>
  235. <p>I&#8217;ll include both the <strong>video</strong> (doesn&#8217;t affect audio) and <strong>audio</strong> filters for this task.</p>
  236. <p><strong>1. Video</strong></p>
  237. <p>The filter for <strong>video</strong> is <strong>setpts</strong> (PTS = presentation time stamp). This works in a somewhat interesting manner. Since we actually modify the <strong>PTS</strong>, a <strong>bigger coefficient</strong> means a <strong>slower result</strong> and vice-versa:</p>
  238. <pre class="wp-block-preformatted">ffmpeg -i input.mkv -vf "setpts=0.5*PTS" output.mkv <br>ffmpeg -i input.mp4 -vf "setpts=2*PTS" output,mp4</pre>
  239. <p>As I just explained, the first command <strong>doubles</strong> the <strong>playback speed</strong> and the second command <strong>slows</strong> the <strong>video</strong> to <strong>1/2</strong> of the <strong>speed</strong>.<strong>A</strong></p>
  240. <p><strong>2. Audio</strong></p>
  241. <p>The filter for this is <strong>atempo</strong>. There&#8217;s one little caveat: it can only take values between <strong>0.5</strong> (half the speed) and <strong>2</strong> (double the speed). To get around that, you can chain <strong>atempo</strong> filters:</p>
  242. <pre class="wp-block-preformatted">ffmpeg -i input.wav -af "atempo=0.75" output.wav <br>ffmpeg -i input.mp3 -af "atempo=2.0,atempo=2.0" ouutput.mp3</pre>
  243. <p>The first command <strong>slows</strong> the audio by <strong>1/4</strong> of the original speed. The second command <strong>speeds</strong> up the audio <strong>4</strong> times (2*2).</p>
  244. <p><strong>Note:</strong> <em>For changing video and audio playback speed with the same command you&#8217;ll have to look into <strong><a href="https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-description" class="external" rel="nofollow" target="_blank">filtergraphs</a></strong>.</em></p>
  245. <p class="has-large-font-size"><strong>Wrapping Up</strong></p>
  246. <p>In this comprehensive guide I covered the installation, basic usage, advanced usage and basics of filters.</p>
  247. <p>I hope that this can be a helpful resource for anyone looking to <strong>try out</strong> <strong>ffmpeg</strong>, for someone that wants to use <strong>ffmpeg</strong> for <strong>multiple tasks</strong> or even just for someone who is willing to get more familiar with the <strong>extensive features</strong> of this amazing utility.</p>
  248. <p>Let us know if you found this article useful in the comments below and tell us what are <strong>you</strong> using <strong>ffmpeg</strong> for! We look forward to any additions of any kind. Thanks for reading our blog and keep an eye out for an article covering more <strong>complex filtering</strong>. Enjoy!</p>