{"id":2055,"date":"2014-06-10T19:08:39","date_gmt":"2014-06-10T17:08:39","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=2055"},"modified":"2025-10-02T10:38:40","modified_gmt":"2025-10-02T08:38:40","slug":"linux-some-ffmpeg-command-line-examples","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/linux-some-ffmpeg-command-line-examples\/","title":{"rendered":"Linux: Some ffmpeg command line examples"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_2055 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_2055')){$('.twoclick_social_bookmarks_post_2055').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Linux%3A%20Some%20ffmpeg%20command%20line%20examples\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Ahere%20are%20a%20list%20of%20some%20command%20line%20examples%20for%20converting%20audio%20and%20video%20files%20with%20ffmpeg.%20ffmpeg%20is%20part%20of%20the%20most%20linux%20distributions%20but%20there%20is%20also%20a%20Windows%20version%20available.%0D%0A%0D%0AConvert%20ogg%20to%20mp3%2C%20with%20-a%20you%20can%20specify%20some%20audio%20options%20here%20a%20bitrate%20of%20192k%0D%0Affmpeg%20-i%20input.ogg%20-ab%20192k%20output.mp3%0D%0ATo%20remove%20the%20embedded%20cover%28Cover%20is%20saved%20as%20Video%20Stream%29%0D%0A%0D%0Affmp%20...\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/linux-some-ffmpeg-command-line-examples\\\/\",\"post_id\":2055,\"post_title_referrer_track\":\"Linux%3A+Some+ffmpeg+command+line+examples\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>here are a list of some command line examples for converting audio and video files with ffmpeg. ffmpeg is part of the most linux distributions but there is also a <a title=\"ffmpeg for Windows\" href=\"http:\/\/ffmpeg.zeranoe.com\/builds\/\" target=\"_blank\" rel=\"noopener noreferrer\">Windows version<\/a> available.<\/p>\n<p>Convert ogg to mp3, with -a you can specify some audio options here a bitrate of 192k<\/p>\n<pre><code>ffmpeg -i input.ogg -ab 192k output.mp3<\/code><\/pre>\n<p>To remove the embedded cover(Cover is saved as Video Stream)<br \/>\n<!-- http:\/\/stackoverflow.com\/questions\/20193065\/how-to-remove-id3-audio-tag-image-with-ffmpeg --><\/p>\n<pre><code>ffmpeg -i input.mp3 -vn -ab 192k output.mp3<\/code><\/pre>\n<p>To remove cover and copy the audio stream, no remux is done =&gt; better quality<\/p>\n<pre><code>ffmpeg -i input.mp3  -y -map 0:a -codec:a copy -map_metadata -1  output.mp3<\/code><\/pre>\n<p>Covert a MKV container to avi. 2 Steps required.<\/p>\n<p>Step 1 (h264 -&gt; mpeg4)<\/p>\n<pre><code>ffmpeg -i video.mkv -qscale 0 -acodec copy temp.avi<\/code><\/pre>\n<p>and Step 2<\/p>\n<pre><code>ffmpeg -i temp.avi -vcodec mpeg4 -b 4000k -acodec mp2 -ab 320k output.avi<\/code><\/pre>\n<p>MPEG4 to xvid Bitrate 1200kb half resolution, AC3 to mp3 128kb<\/p>\n<pre><code>ffmpeg -i temp.avi\u00a0-vf scale=iw\/2:-1 -b 1200k -q:v 2 -q:a 2 -c:v libxvid\u00a0 -c:a libmp3lame -b:a 128k output.avi<\/code><\/pre>\n<p>Another simple way to xvid<\/p>\n<pre><code> ffmpeg -i input.avi -c:v mpeg4 -vtag xvid output.avi<\/code><\/pre>\n<p>MKV to xvid 4:3<\/p>\n<pre><code> ffmpeg -i input.mkv -sn -c:a libmp3lame -ar 48000 -ab 128k -ac 2 -c:v libxvid -crf 24 -vtag DIVX -vf scale=640:480 -aspect 4:3 -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 30 -vb 1500k output.avi<\/code><\/pre>\n<p>MKV to xvid 16:9<\/p>\n<pre><code> ffmpeg -i input.mkv -sn -c:a libmp3lame -ar 48000 -ab 128k -ac 2 -c:v libxvid -crf 24 -vtag DIVX -vf scale=720:480 -aspect 16:9 -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 30 -vb 1500k output.avi<\/code><\/pre>\n<p>Format to play on some DVD Player with SDCard (Medion for example)<\/p>\n<pre><code>ffmpeg -i input.mkv -f avi -c:v libxvid -qscale:v 2 -vf scale=512x280 -c:a libmp3lame -b:a 320k output.avi<\/code><\/pre>\n<p>and with a limited bitrate<\/p>\n<pre><code>ffmpeg -i input.mkv -f avi -c:v libxvid -b:v 1M -maxrate 1M -bufsize 1M -vf scale=512x280 -c:a libmp3lame -b:a 320k output.avi<\/code><\/pre>\n<p>Scale to a specific resolution and preserve aspect ration<\/p>\n<pre><code>ffmpeg -i temp.avi  -vf scale=320:-1 output_320.avi<\/code><\/pre>\n<p>Scale to the current resolution divided by 3<\/p>\n<pre><code>\r\nffmpeg -i output.mov -vcodec libx264 -acodec aac  -vf scale=iw\/3:ih\/3 test.mp4\r\n<\/code><\/pre>\n<p>MKV with DTS codec for a Panasonic TV<br \/>\n<code><\/p>\n<pre>\r\nffmpeg -i input.mkv-c:v copy -c:a ac3 -b:a 640k output.mkv\r\n<\/code><\/pre>\n<p>and for Dolby AC3. Map all audio streams into one<br \/>\n<!-- https:\/\/superuser.com\/questions\/1427570\/using-ffmpeg-to-convert-dts-audio-track-to-ac3-and-add-back-into-mkv\nhttps:\/\/superuser.com\/questions\/1219784\/making-ffmpeg-process-first-audio-stream-differently-than-all-others--><br \/>\n<code><\/p>\n<pre>\r\nffmpeg -i input.mkv -map 0:v -map 0:a:0 -map 0:a -map 0:s -c:v copy -c:a copy -c:s copy -c:a:0 ac3 -b:a:0 640k output.mkv\r\n<\/code><\/pre>\n<p>Concat 2 files with the same codec. Create a list of video files and write it to file<\/p>\n<pre><code>\r\ncat movlist.txt\r\nfile 'movPart1.avi'\r\nfile 'movPart2.avi'\r\nffmpeg -f concat -i movlist.txt -c copy mov.avi\r\n<\/code><\/pre>\n<p>Same but with mp3 files, Metadata are used from mp3File1.mp3<\/p>\n<pre><code>\r\nffmpeg -i \"concat:mp3File1.mp3|mp3File2.mp3\" -acodec copy mp3file.mp3\r\n<\/code><\/pre>\n<p>Export Metadata from an mp3 file<\/p>\n<pre><code>\r\nffmpeg -i mp3File1.mp3 -f ffmetadata mp3File1.metadata\r\n<\/code><\/pre>\n<p>With new metadata<\/p>\n<pre><code>\r\nffmpeg -i \"concat:mp3File1.mp3|mp3File2.mp3\" -metadata \"title=My Heavy Song\" -metadata \"artist=Metalartist\" -metadata \"album=Best Metal Album ever\" -acodec copy mp3file.mp3  -vn\r\n<\/code><\/pre>\n<p>To flip a video vertically<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i in.avi -vf vflip flipped.avi\r\n<\/pre>\n<p>To flip a video horizontally<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i in.avi -vf hflip flipped.avi\r\n<\/pre>\n<p>Rotate 90\u00b0 clockwise<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i in.avi -vf transpose=1 flipped.avi\r\n<\/pre>\n<p>Rotate 90\u00b0 counterclockwise<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i in.avi -vf transpose=2 -c:a flipped.avi\r\n<\/pre>\n<p>Transpose does a reencoding of the whole video. This simply rotates the video<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i christmas.mov  -metadata:s:v rotate=&quot;90&quot; -codec copy output.mov\r\n<\/pre>\n<p>To map the german audio channel as default. List channels<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i in.avi 2&gt;&amp;1 |grep Stream\r\n    Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709\/unknown\/unknown, progressive)1k tbn, 47.95 tbc (default)..\r\n    Stream #0:1(ger): Audio: ac3, 48000 Hz, stereo, fltp, 224 kb\/s (default) (forced)\r\n    Stream #0:2(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb\/s\r\n<\/pre>\n<p>To select the german Audio stream as default use -map 0:a:0, means 1st Audio stream (counted from 0)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i in.avi ... -map 0:v:0 -map 0:a:0 ...\r\n<\/pre>\n<p>Convert a Video to a Whatsapp compatible format<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">ffmpeg -i in.avi -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p out.mp4<\/pre>\n<p>Cut a video. From second 30 for a length of 10sec<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -ss 00:00:30.0 -i input.wmv -c copy -t 00:00:10.0 output.wmv\r\nffmpeg -ss 30 -i video.mp4 -c copy -t 10 video.mp4\r\n<\/pre>\n<p>Fade in, fade out<br \/>\n<!-- https:\/\/dev.to\/dak425\/add-fade-in-and-fade-out-effects-with-ffmpeg-2bj7 --><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i video.mp4 -vf &quot;fade=t=in:st=0:d=3&quot; -c:a copy out.mp4\r\nffmpeg -i video.mp4 -vf &quot;fade=t=out:st=10:d=5&quot; -c:a copy out.mp4\r\n<\/pre>\n<p>To be continued<\/p>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, here are a list of some command line examples for converting audio and video files with ffmpeg. ffmpeg is part of the most linux distributions but there is also a Windows version available. Convert ogg to mp3, with -a you can specify some audio options here a bitrate of 192k ffmpeg -i input.ogg -ab &hellip; <a href=\"https:\/\/michlstechblog.info\/blog\/linux-some-ffmpeg-command-line-examples\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux: Some ffmpeg command line examples<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[576,450,574,575,578,577],"class_list":["post-2055","post","type-post","status-publish","format-standard","hentry","category-linux","tag-avi","tag-convert","tag-ffmpeg","tag-mkv","tag-mp3","tag-ogg"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/2055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=2055"}],"version-history":[{"count":34,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/2055\/revisions"}],"predecessor-version":[{"id":10139,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/2055\/revisions\/10139"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=2055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=2055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=2055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}