Home LearnSoftware FFmpeg Commands Helpful with Audio and Video Files Working

FFmpeg Commands Helpful with Audio and Video Files Working

by Sagar Jain
127 views
ffmpeg commands

If you’re familiar with FFmpeg, hop over to the commands already, and if not, wait and check what wonders this software will do in a 2-minute introduction. 

FFmpeg is a free and open-source project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams. It can do many things like joining two video files, extracting the audio component from a video file, converting your video into an animated GIF, Converting your video to any other format, and much more.

It is available for free to Download on many Platforms. It’s a simple Command line tool and easy to operate; also, there is many GUI for this on the web; you can look for one as per your preferences.

FFmpeg Commands supports the most popular audio and video formats; alternatively, you can quickly get the full list by running this command ./ffmpeg -formats.

Without further ado, let’s take a look at some useful commands below-

A. If you need to split a big video into smaller clips without re-encoding, This command will split the source video into two parts – 

ffmpeg -i video.mp4 -t 00:00:30 -c copy small-1.mp4 -ss 00:00:30 -codec copy small-2.mp4

One clip will end in the 30s, and the next one will start at the beginning of the 30s.

B. To crop and audio file, the below command will create a 30-second audio file starting at 90 seconds from the original audio file without transcoding.

ffmpeg -ss 00:01:30 -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3

C. Change the volume; it’s easy to use volume filter to alter the volume of a media and compress the size.

ffmpeg -i input.wav -af ‘volume=0.5’ output.wav

D. Rotate the video clip 90° clockwise. To do it, set transpose to 2 to turn the video 90° anti-clockwise.

ffmpeg -i input.mp4 -filter:v ‘transpose=1’ rotated-video.mp4

E. Split video files into smaller clips like mini clips to do this use the time offset parameter (-ss) to specify the start time stamp in HH:MM: SS.ms format while the -t parameter is for determining the actual duration of the clip in seconds.

ffmpeg -i input.mp4 -ss 00:00:50.0 -codec copy -t 20 output.mp4

F. Combine multiple files into a single file.

FFmpeg -f concat -i file-list.txt -c copy output.mp4

G. Split the audio from video file with -vn switch extracts the audio portion from a video, and we are using the -ab switches to save the sound as a 256kbps MP3 file.

ffmpeg -i video.mp4 -vn -ab 256 audio.mp3

Change the audio output format per your preference.

H. Convert your video into a GIF (animated)m with the help of scale filter you can specify the width of the GIF and the -t parameter to specify the duration while -r specifies the fps.

FFmpeg -i video.mp4 -vf scale=500:-1 -t 10 -r 10 image.gif

I. Get Images from a video

FFmpeg -ss 00:00:45 -i video.mp4 -vf scale=800:-1 -vframes 1 image.jpg

J. Change video format from like Flv to mp4 to do that use the -vcode option to define the encoding format for the output file and adjust the video format from Flv to mp4. It takes time to encode a video so you can speed up the process by forcing a preset, although it reduces overall video quality.

ffmpeg -i youtube.flv -c:v libx264 filename.mp4

ffmpeg -i video.wmv -c:v libx264 -preset ultrafast video.mp4

K. Easily create slideshow from images using a 

collection of pictures called img001.png, img002.png, and so forth. 

Every picture will take 5 seconds to complete (-r 1/5).

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4

L. Add a poster image to audio, A cover image attached to an audio file, and the length of the output video would be the same as the input audio stream.

FFmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4

M. If you want to Convert Video into Images, use the command below to extract images from frames every ‘n’ seconds. This command saves image frames from the video after every 2 seconds.

FFmpeg -i movie.mp4 -r 0.50 frames_%04d.png

N. Mute a video (Remove the audio component)

Use the -an parameter to disable the audio portion of a video stream.

FFmpeg -I video.mp4 -an mute-video.mp4

O. To Merge an audio and video file, please specify the -shortest switch to finish the encoding when the shortest clip ends.

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental output.mp4

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental -shortest output.mp4

P. Resize a video with the size (-s) switch to resize a video while maintaining the aspect ratio.

FFmpeg -i input.mp4 -s 480×320 -c:a copy output.mp4

Use the -t parameter to specify the duration of the video.

FFmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p video.mp4

Q. Add subtitles to a movie.

ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv

ffmpeg -i input.mp4 -filter:v ‘transpose=2,transpose=2’ rotated-video.mp4

R. Speed up or Slow down the video

You can change your video’s speed using the steps (set presentation time stamp) filter of FFmpeg. This command will make the video 8x (1/8) faster or use setpts=4*PTS to make the video 4x slower.

FFmpeg -i input.mp4 -filter:v “setpts=0.125*PTS” output.mp4

S. Speed up or Slow down the audio

For changing the speed of audio, use the tempo audio filter. This command will double the speed of audio. You can use any value between 0.5 and 2.0 for sound.

FFmpeg -i input.mkv -filter:a “atempo=2.0” -vn output.mkv

If you would like to add more commands to this list, please comment below.

Source: https://github.com/hrsh2112/PHP-Video-Converter–Kit–ffmpeg

Related Posts

1 comment

Eric Izle July 25, 2020 - 12:45 PM

I just started my blog a few months ago and discovered this site just two weeks now, and wow…So grateful for you. Thanks for the post. awesome..

Reply

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More