{"id":31,"date":"2023-04-23T16:45:45","date_gmt":"2023-04-24T00:45:45","guid":{"rendered":"https:\/\/fyro.net\/blog\/?p=31"},"modified":"2023-04-23T16:46:56","modified_gmt":"2023-04-24T00:46:56","slug":"using-ffmpeg-to-convert-file-types","status":"publish","type":"post","link":"https:\/\/fyro.net\/blog\/using-ffmpeg-to-convert-file-types\/","title":{"rendered":"Using FFMPEG to convert file types"},"content":{"rendered":"<p>FFmpeg is a powerful command-line tool that can be used to convert media files from one format to another. Here&#8217;s how FFmpeg works to convert a picture to a different format:<\/p>\n<ol>\n<li>Input file: The first step is to specify the input file using the -i option, followed by the file path of the picture you want to convert.<\/li>\n<li>Codec: Next, you need to specify the codec to use for the output file. FFmpeg supports a wide range of codecs for different media formats. For example, to convert a PNG image to a JPEG image, you can use the -c:v option followed by the codec name &#8220;libjpeg&#8221;.<\/li>\n<li>Output file: Finally, you need to specify the output file using the -o option, followed by the file path of the new image you want to create. You can also specify additional options such as the output file format using the -f option.<\/li>\n<\/ol>\n<p>Here&#8217;s an example command to convert a PNG image to a JPEG image using FFmpeg:<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-css\">ffmpeg -<span class=\"hljs-selector-tag\">i<\/span> <span class=\"hljs-selector-tag\">input<\/span><span class=\"hljs-selector-class\">.png<\/span> -c:v libjpeg output.jpg<\/code><\/div>\n<\/div>\n<p>In this example, FFmpeg reads the input file &#8220;input.png&#8221;, uses the &#8220;libjpeg&#8221; codec to convert the image to a JPEG format, and saves the output file as &#8220;output.jpg&#8221;.<\/p>\n<p>The <a href=\"https:\/\/fyro.net\/fileconverter\/\">Fyro File Converter<\/a> provides a handy web interface to do a lot of common file type conversions. But it doesn&#8217;t just do image file conversions &#8211; you can also do video conversions as well!<\/p>\n<p>In the example below, FFmpeg is used to convert an input video file &#8220;input.mp4&#8221; to an output video file &#8220;output.mkv&#8221; using the H.264 video codec (libx264) and the AAC audio codec (-c:v and -c:a options, respectively). The options -preset and -crf are used to control the quality of the output video: &#8220;slow&#8221; is the encoding preset, and &#8220;22&#8221; is the Constant Rate Factor (CRF) value, which controls the trade-off between quality and file size.<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-less\"><span class=\"hljs-selector-tag\">ffmpeg<\/span> <span class=\"hljs-selector-tag\">-i<\/span> <span class=\"hljs-selector-tag\">input<\/span><span class=\"hljs-selector-class\">.mp4<\/span> <span class=\"hljs-selector-tag\">-c<\/span>:<span class=\"hljs-selector-tag\">v<\/span> <span class=\"hljs-selector-tag\">libx264<\/span> <span class=\"hljs-selector-tag\">-preset<\/span> <span class=\"hljs-selector-tag\">slow<\/span> <span class=\"hljs-selector-tag\">-crf<\/span> <span class=\"hljs-number\">22<\/span> <span class=\"hljs-selector-tag\">-c<\/span>:<span class=\"hljs-selector-tag\">a<\/span> <span class=\"hljs-selector-tag\">aac<\/span> <span class=\"hljs-selector-tag\">-b<\/span>:<span class=\"hljs-selector-tag\">a<\/span> <span class=\"hljs-number\">128<\/span><span class=\"hljs-selector-tag\">k<\/span> <span class=\"hljs-selector-tag\">output<\/span><span class=\"hljs-selector-class\">.mkv<\/span><\/code><\/div>\n<\/div>\n<p>Here&#8217;s a breakdown of the options used in this example:<\/p>\n<ul>\n<li><code>-i input.mp4<\/code>: Specifies the input video file.<\/li>\n<li><code>-c:v libx264<\/code>: Specifies the H.264 video codec for the output file.<\/li>\n<li><code>-preset slow<\/code>: Specifies the encoding preset to use for the output file.<\/li>\n<li><code>-crf 22<\/code>: Specifies the CRF value for the output file (lower values result in higher quality but larger file sizes).<\/li>\n<li><code>-c:a aac<\/code>: Specifies the AAC audio codec for the output file.<\/li>\n<li><code>-b:a 128k<\/code>: Specifies the audio bitrate for the output file.<\/li>\n<li><code>output.mkv<\/code>: Specifies the output file name and format.<\/li>\n<\/ul>\n<p>Basically, this command would convert the input video file from MP4 format to Matroska (MKV) format using the specified video and audio codecs, with a slow encoding preset and a CRF value of 22 for the video.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FFmpeg is a powerful command-line tool that can be used to convert media files from one format to another. Here&#8217;s how FFmpeg works to convert a picture to a different format: Input file: The first step is to specify the input file using the -i option, followed by the file path of the picture you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,16],"tags":[13,12,6,18,17],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-file-converter","category-video-streaming","tag-ffmpeg","tag-file-converter","tag-internet-protocol","tag-streaming","tag-video"],"_links":{"self":[{"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":2,"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fyro.net\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}