Tricks For Editing Videos


Posted on December 19, 2021


How to Split a Video
Let's say you have a 5-minute video and you want to chop off a 29-second section from it. We'll assume here that you want to chop off the section that begins after 10 seconds into the video, and that your video file is named "Thriller".

First install FFmpeg using these two commands:

sudo apt-get update
sudo apt-get install ffmpeg

You can extract a piece of the video by stating a point of entry with "-ss" (-ss 00:06:46) and specifying a time with "-t" (-t 00:01:00). Note that -ss and -t should be placed before the first input (-i). Here's the full command you'll use:

ffmpeg -ss 00:00:10 -t 00:00:29 -i Thriller.mp4 -c copy NewThriller.mp4
How to Create a Video From a Single Photo
Let's say you have a photo and you want to convert it into a video. We'll assume here that you want a 5-minute video, and that your photo file is named "Babyface" and the video file will be named "Thriller".

First install FFmpeg using these two commands:

sudo apt-get update
sudo apt-get install ffmpeg

You can now use the command below to create the video. The "-t 00:05:00" makes it 5 minutes long.

ffmpeg -loop 1 -i Babyface.jpg -t 00:05:00 Thriller.mp4

You can also use the more complicated command below to create the video. The -t 15 makes it 15 seconds long. The -vf scale=320:240 sets the width/height.

ffmpeg -loop 1 -i Babyface.jpg -c:v libx264 -t 00:05:00 \
            -pix_fmt yuv420p -vf scale=320:240 Thriller.mp4

If you need to specify the framerate (e.g. you want to concatenate the resulting video with another existing video and need them to match) you can add "-r 30" before output to specify 30 FPS.

ffmpeg -loop 1 -i Babyface.png -t 5 -r 30 Thriller.mp4
How to Create a Video From a Single Photo With Audio Included
Let's say you have a photo and you want to convert it into a video. We'll assume here that you want a 5-minute video, and that your photo file is named "Babyface", your audio file is named "Lovely", and the video file will be named "Thriller".

First install FFmpeg using these two commands:

sudo apt-get update
sudo apt-get install ffmpeg

You can now use the command below to create the video.

ffmpeg -loop 1 -i Babyface.jpg -i Lovely.mp3 -c:v libx264 \
            -tune stillimage -c:a aac -b:a 192k \
            -vf "scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p" \
            -shortest -movflags +faststart Thriller.mp4

The scale filter example is a fancy way of making the width and height to be divisible by 2 which is needed for this particular encoder when outputting YUV 4:2:0 (4:2:2 and 4:4:4 are not supported by most players, so that is why you see so many examples using yuv420p). A simpler method is to crop or scale like crop=550:764, but the above command will work with any input size.
How to Create a Video From Several Photos
Let's say you have several photos and you want to convert them into a video. We'll assume here that you want a 5-minute video, and that your photo file is named "Babyface" and the video file will be named "Thriller".

First install FFmpeg using these two commands:

sudo apt-get update
sudo apt-get install ffmpeg

You can now use the command below to create the video. The "-t 00:05:00" makes it 5 minutes long.

ffmpeg -loop 1 -i Babyface.jpg -t 00:05:00 Thriller.mp4

You can also insert varying intervals of time between the photos to create something similar to a slideshow.

ffmpeg -loop 1 -i Babyface.jpg -c:v libx264 -t 00:05:00 \
            -pix_fmt yuv420p -vf scale=320:240 Thriller.mp4
How to Add Sound to a Video
Let's say you have a photo of a certain width and height, and you want to slice off a section of it. For this example we'll assume that your photo has a width of 1,500 pixels and a height of 1,051 pixels, and you want to reduce its height to 1,000 pixels by slicing off a strip from the bottom. You'll have to specifiy the size of the cut out image and the offset from the upper left corner of the old image by choosing a size of 1500x1000 and an offset of 0+0.

First install Imagemagick using these commands:

sudo apt-get update
sudo apt-get install imagemagick

And then you can crop the photo using this command:

convert photo.jpg -crop 1500x1000+0+0 photo-cropped.jpg
How to Merge Two Videos to Create a Longer One
Let's say you have a photo of a certain width and height, and you want to slice off a section of it. For this example we'll assume that your photo has a width of 1,500 pixels and a height of 1,051 pixels, and you want to reduce its height to 1,000 pixels by slicing off a strip from the bottom. You'll have to specifiy the size of the cut out image and the offset from the upper left corner of the old image by choosing a size of 1500x1000 and an offset of 0+0.

First install Imagemagick using these commands:

sudo apt-get update
sudo apt-get install imagemagick

And then you can crop the photo using this command:

convert photo.jpg -crop 1500x1000+0+0 photo-cropped.jpg
How to Merge Two Videos to Share the Same Frame
Let's say you have a photo of a certain width and height, and you want to slice off a section of it. For this example we'll assume that your photo has a width of 1,500 pixels and a height of 1,051 pixels, and you want to reduce its height to 1,000 pixels by slicing off a strip from the bottom. You'll have to specifiy the size of the cut out image and the offset from the upper left corner of the old image by choosing a size of 1500x1000 and an offset of 0+0.

First install Imagemagick using these commands:

sudo apt-get update
sudo apt-get install imagemagick

And then you can crop the photo using this command:

convert photo.jpg -crop 1500x1000+0+0 photo-cropped.jpg
How to Add Permanent Subtitles to a Video
Let's say you have a photo of a certain width and height, and you want to slice off a section of it. For this example we'll assume that your photo has a width of 1,500 pixels and a height of 1,051 pixels, and you want to reduce its height to 1,000 pixels by slicing off a strip from the bottom. You'll have to specifiy the size of the cut out image and the offset from the upper left corner of the old image by choosing a size of 1500x1000 and an offset of 0+0.

First install Imagemagick using these commands:

sudo apt-get update
sudo apt-get install imagemagick

And then you can crop the photo using this command:

convert photo.jpg -crop 1500x1000+0+0 photo-cropped.jpg

  • If you have any questions or comments, you can contact me on Twitter: @patrickwayodi