{"id":6834,"date":"2020-03-04T22:05:36","date_gmt":"2020-03-04T21:05:36","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=6834"},"modified":"2020-03-04T22:05:36","modified_gmt":"2020-03-04T21:05:36","slug":"useful-ffmpeg-commands-for-working-with-audio-and-video-files-digital-inspiration","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2020\/03\/04\/useful-ffmpeg-commands-for-working-with-audio-and-video-files-digital-inspiration\/","title":{"rendered":"Useful FFmpeg Commands for Working with Audio and Video Files &#8211; Digital Inspiration"},"content":{"rendered":"<p><em><a href=\"https:\/\/www.labnol.org\/internet\/useful-ffmpeg-commands\/28490\/\">Useful FFmpeg Commands for Working with Audio and Video Files &#8211; Digital Inspiration<\/a><\/em><\/p>\n<p><!--more--><!--nextpage--><\/p>\n<blockquote>\n<h2 id=\"useful-ffmpeg-commands\">Useful FFmpeg Commands<\/h2>\n<p>FFmpeg supports all popular audio and video formats. Or you can running the command <code class=\"\" data-line=\"\">.\/ffmpeg -formats<\/code> to get a list of every format that is supported by your FFmpeg installation. If you are just getting started, here are some commands that will give you good idea of the capabilities of this tool.<\/p>\n<h4 id=\"1-cut-video-file-into-a-smaller-clip\"><\/h4>\n<h4 id=\"1-cut-video-file-into-a-smaller-clip\">1. Cut video file into a smaller clip<\/h4>\n<p>You can use the time offset parameter (-ss) to specify the start time stamp in HH:MM:SS.ms format while the -t parameter is for specifying the actual duration of the clip in seconds.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.mp4 -ss 00:00:50.0 -codec copy -t 20 output.mp4<\/code><\/p>\n<h4 id=\"2-split-a-video-into-multiple-parts\"><\/h4>\n<h4 id=\"2-split-a-video-into-multiple-parts\">2. Split a video into multiple parts<\/h4>\n<p>If you want to split a large video into multiple smaller clips without re-encoding, ffmpeg can help. This command will split the source video into 2 parts &#8211; one ending at 50s from the start and the other beginning at 50s and ending at the end of the input video.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4<\/code><\/p>\n<h4 id=\"3-convert-video-from-one-format-to-another\"><\/h4>\n<h4 id=\"3-convert-video-from-one-format-to-another\">3. Convert video from one format to another<\/h4>\n<p>You can use the -vcodec parameter to specify the encoding format to be used for the output video. Encoding a video takes time but you can speed up the process by forcing a preset though it would degrade the quality of the output video.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i youtube.flv -c:v libx264 filename.mp4<\/code><\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.wmv -c:v libx264 -preset ultrafast video.mp4<\/code><\/p>\n<h4 id=\"4-join-concatenate-video-files\"><\/h4>\n<h4 id=\"4-join-concatenate-video-files\">4. Join (concatenate) video files<\/h4>\n<p>If you have multiple audio or video files encoded with the same codecs, you can join them into a single file using FFmpeg. Create a input file with a list of all <a href=\"https:\/\/ffmpeg.org\/trac\/ffmpeg\/wiki\/How%20to%20concatenate%20%28join,%20merge%29%20media%20files\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">source files<\/a> that you wish to concatenate and then run this command.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -f concat -i file-list.txt -c copy output.mp4<\/code><\/p>\n<h4 id=\"5-mute-a-video-remove-the-audio-component\"><\/h4>\n<h4 id=\"5-mute-a-video-remove-the-audio-component\">5. Mute a video (Remove the audio component)<\/h4>\n<p>Use the -an parameter to disable the audio portion of a video stream.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.mp4 -an mute-video.mp4<\/code><\/p>\n<h4 id=\"6-extract-the-audio-from-video\"><\/h4>\n<h4 id=\"6-extract-the-audio-from-video\">6. Extract the audio from video<\/h4>\n<p>The -vn switch extracts the audio portion from a video and we are using the -ab switch to save the audio as a 256kbps MP3 audio file.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.mp4 -vn -ab 256 audio.mp3<\/code><\/p>\n<h4 id=\"7-convert-a-video-into-animated-gif\"><\/h4>\n<h4 id=\"7-convert-a-video-into-animated-gif\">7. Convert a video into animated GIF<\/h4>\n<p>FFmpeg is an excellent tool for converting videos into <a href=\"https:\/\/www.labnol.org\/software\/video-demo-with-animated-gif\/28095\/\">animated GIFs<\/a> and the quality isn\u2019t bad either. Use the scale filter to specify the width of the GIF, the -t parameter specific the duration while -r specifies the frame rate (fps).<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.mp4 -vf scale=500:-1 -t 10 -r 10 image.gif<\/code><\/p>\n<h4 id=\"8-extract-image-frames-from-a-video\"><\/h4>\n<h4 id=\"8-extract-image-frames-from-a-video\">8. Extract image frames from a video<\/h4>\n<p>This command will extract the video frame at the 15s mark and saves it as a 800px wide JPEG image. You can also use the -s switch (like -s 400&#215;300) to specify the exact dimensions of the image file though it will probably create a stretched image if the image size doesn\u2019t follow the aspect ratio of the original video file.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -ss 00:00:15 -i video.mp4 -vf scale=800:-1 -vframes 1 image.jpg<\/code><\/p>\n<h4 id=\"9-convert-video-into-images\"><\/h4>\n<h4 id=\"9-convert-video-into-images\">9. Convert Video into Images<\/h4>\n<p>You can use FFmpeg to automatically <a href=\"https:\/\/www.labnol.org\/software\/extract-image-frames-from-video\/18137\/\">extract image frames<\/a> from a video every \u2018n\u2019 seconds and the images are saved in a sequence. This command saves image frame after every 4 seconds.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png<\/code><\/p>\n<h4 id=\"10-merge-an-audio-and-video-file\"><\/h4>\n<h4 id=\"10-merge-an-audio-and-video-file\">10. Merge an audio and video file<\/h4>\n<p>You can also specify the -shortest switch to finish the encoding when the shortest clip ends.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental output.mp4<\/code><\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental -shortest output.mp4<\/code><\/p>\n<h4 id=\"11-resize-a-video\"><\/h4>\n<h4 id=\"11-resize-a-video\">11. Resize a video<\/h4>\n<p>Use the size (-s) switch with ffmpeg to resize a video while maintaining the aspect ratio.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.mp4 -s 480x320 -c:a copy output.mp4<\/code><\/p>\n<h4 id=\"12-create-video-slideshow-from-images\"><\/h4>\n<h4 id=\"12-create-video-slideshow-from-images\">12. Create video slideshow from images<\/h4>\n<p>This command creates a <a href=\"https:\/\/www.labnol.org\/internet\/street-view-time-lapse\/20504\/\">video slideshow<\/a> using a series of images that are named as img001.png, img002.png, etc. Each image will have a duration of 5 seconds (-r 1\/5).<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -r 1\/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4<\/code><\/p>\n<h4 id=\"13-add-a-poster-image-to-audio\"><\/h4>\n<h4 id=\"13-add-a-poster-image-to-audio\">13. Add a poster image to audio<\/h4>\n<p>You can add a cover image to an audio file and the length of the output video will be the same as that of the input audio stream. This may come handy for uploading MP3s to YouTube.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4<\/code><\/p>\n<h4 id=\"14-convert-a-single-image-into-a-video\"><\/h4>\n<h4 id=\"14-convert-a-single-image-into-a-video\">14. Convert a single image into a video<\/h4>\n<p>Use the -t parameter to specify the duration of the video.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p video.mp4<\/code><\/p>\n<h4 id=\"15-add-subtitles-to-a-movie\"><\/h4>\n<h4 id=\"15-add-subtitles-to-a-movie\">15. Add subtitles to a movie<\/h4>\n<p>This will take the subtitles from the .srt file. FFmpeg can decode most common subtitle formats.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv<\/code><\/p>\n<h4 id=\"16-crop-an-audio-file\"><\/h4>\n<h4 id=\"16-crop-an-audio-file\">16. Crop an audio file<\/h4>\n<p>This will create a 30 second audio file starting at 90 seconds from the original audio file without transcoding.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -ss 00:01:30 -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3<\/code><\/p>\n<h4 id=\"17-change-the-audio-volume\"><\/h4>\n<h4 id=\"17-change-the-audio-volume\">17. Change the audio volume<\/h4>\n<p>You can use the volume filter to alter the volume of a media file using FFmpeg. This command will half the volume of the audio file.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.wav -af &#039;volume=0.5&#039; output.wav<\/code><\/p>\n<h4 id=\"18-rotate-a-video\"><\/h4>\n<h4 id=\"18-rotate-a-video\">18. Rotate a video<\/h4>\n<p>This command will <a href=\"https:\/\/www.labnol.org\/software\/tutorials\/rotate-video-vertical-clips-90-degrees-virtualdub\/2657\/\">rotate a video clip<\/a> 90\u00b0 clockwise. You can set transpose to 2 to rotate the video 90\u00b0 anti-clockwise.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.mp4 -filter:v &#039;transpose=1&#039; rotated-video.mp4<\/code><\/p>\n<p>This will rotate the video 180\u00b0 counter-clockwise.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.mp4 -filter:v &#039;transpose=2,transpose=2&#039; rotated-video.mp4<\/code><\/p>\n<h4 id=\"19-speed-up-or-slow-down-the-video\"><\/h4>\n<h4 id=\"19-speed-up-or-slow-down-the-video\">19. Speed up or Slow down the video<\/h4>\n<p>You can change the speed of your video using the setpts (set presentation time stamp) filter of FFmpeg. This command will make the video 8x (1\/8) faster or use <code class=\"\" data-line=\"\">setpts=4*PTS<\/code> to make the video 4x slower.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.mp4 -filter:v &quot;setpts=0.125*PTS&quot; output.mp4<\/code><\/p>\n<h4 id=\"20-speed-up-or-slow-down-the-audio\"><\/h4>\n<h4 id=\"20-speed-up-or-slow-down-the-audio\">20. Speed up or Slow down the audio<\/h4>\n<p>For changing the speed of audio, use the atempo audio filter. This command will double the speed of audio. You can use any value between 0.5 and 2.0 for audio.<\/p>\n<p><code class=\"\" data-line=\"\">ffmpeg -i input.mkv -filter:a &quot;atempo=2.0&quot; -vn output.mkv<\/code><\/p>\n<p>Stack Exchange has a <a href=\"http:\/\/blog.superuser.com\/2012\/02\/24\/ffmpeg-the-ultimate-video-and-audio-manipulation-tool\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">good overview<\/a> to get you started with FFmpeg. You should also check out the official documentation at <a href=\"http:\/\/ffmpeg.org\/ffmpeg.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ffmpeg.org<\/a> or the wiki at <a href=\"https:\/\/trac.ffmpeg.org\/wiki\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">trac.ffmpeg.org<\/a> to know about all the possible things you can do with FFmpeg.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Useful FFmpeg Commands for Working with Audio and Video Files &#8211; Digital Inspiration<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2020\/03\/04\/useful-ffmpeg-commands-for-working-with-audio-and-video-files-digital-inspiration\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"link","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[72],"tags":[268],"class_list":["post-6834","post","type-post","status-publish","format-link","hentry","category-documentations","tag-ffmpeg","post_format-post-format-link"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-1Me","jetpack-related-posts":[{"id":8990,"url":"https:\/\/monodes.com\/predaelli\/2021\/12\/19\/how-to-do-noise-reduction-using-ffmpeg-and-sox-articulating-ideas\/","url_meta":{"origin":6834,"position":0},"title":"How To Do Noise Reduction Using ffmpeg And sox &#8211; Articulating ideas","author":"Paolo Redaelli","date":"2021-12-19","format":"link","excerpt":"How To Do Noise Reduction Using ffmpeg And sox - Articulating ideas by Zohar Babin Need a quick, easy and free way of cleaning up a video\u2019s audio from background noise ? Follow the steps below to remove background audio from videos. First get and\u00a0install the tools: FFMPEG. SoX \u2013\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7993,"url":"https:\/\/monodes.com\/predaelli\/2021\/01\/03\/audio-how-to-transform-live-rtmp-video-to-live-mp3-icecast-stream-stack-overflow\/","url_meta":{"origin":6834,"position":1},"title":"audio &#8211; how to transform live RTMP video to live mp3 Icecast stream &#8211; Stack Overflow","author":"Paolo Redaelli","date":"2021-01-03","format":false,"excerpt":"Source: audio - how to transform live RTMP video to live mp3 Icecast stream - Stack Overflow I have RTMP live stream with video and audio. I can get ogg audio live stream from RTMP and translate it to Icecast2 and get it on my site using JPlayer. Now i\u2026","rel":"","context":"In &quot;Basilica's website&quot;","block_context":{"text":"Basilica's website","link":"https:\/\/monodes.com\/predaelli\/category\/basilicas-website\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13797,"url":"https:\/\/monodes.com\/predaelli\/2025\/07\/20\/13797\/","url_meta":{"origin":6834,"position":2},"title":"I visited Terence blog to\u2026","author":"Paolo Redaelli","date":"2025-07-20","format":false,"excerpt":"I visited Terence blog to read about some Easy ways to add watermarks to images and videos in Linux but I found a very nice and clean to take inspiration from! Mostly notes to myself :-) Here is a quick way to add watermarks to photos and videos. All Linux\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/shkspr.mobi\/blog\/wp-content\/litespeed\/avatar\/af6a5dd8373bf52386c67599d3a74158.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8347,"url":"https:\/\/monodes.com\/predaelli\/2021\/04\/11\/ffmpeg-to-youtube-live\/","url_meta":{"origin":6834,"position":3},"title":"FFMPEG to Youtube Live","author":"Paolo Redaelli","date":"2021-04-11","format":false,"excerpt":"video - FFMPEG to Youtube Live - Stack Overflow After a lot of trial and error the solution below works pretty much perfectly. To make sure it runs 24\/7 wrap it inside a service of some description. This is with an up to date version of FFMPEG to include -stream_loop\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4928,"url":"https:\/\/monodes.com\/predaelli\/2018\/11\/17\/green-recorder-a-simple-screen-recorder-for-linux-with-wayland-support-2daygeek-com\/","url_meta":{"origin":6834,"position":4},"title":"Green Recorder &#8211; A Simple Screen Recorder For Linux With Wayland Support | 2daygeek.com","author":"Paolo Redaelli","date":"2018-11-17","format":false,"excerpt":"Green recorder is a free, open source, simple desktop recorder for Linux systems and written using Python, GTK+3 and ffmpeg. It supports audio and video Source: Green Recorder - A Simple Screen Recorder For Linux With Wayland Support | 2daygeek.com","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7079,"url":"https:\/\/monodes.com\/predaelli\/2020\/06\/01\/cura-dimagrante\/","url_meta":{"origin":6834,"position":5},"title":"Cura dimagrante","author":"Paolo Redaelli","date":"2020-06-01","format":false,"excerpt":"ffmpeg -i Palme\\ 2020.mp4 -vcodec libx265 -crf 28 -vf scale=1280:-1 Domenica-delle-palme.mp4 Per far dimagrire un video da 402Mb a 9,9Mb. Ok, ok, chi si loda s'imbroda, tanto pi\u00f9 che fa tutto ffmpeg, mica io! Ma vediamo il perch\u00e9 dopo aver visto il percome: il video in origine era codificato in\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/6834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=6834"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/6834\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=6834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=6834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=6834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}