-
Notifications
You must be signed in to change notification settings - Fork 1
Transforming Videos into Video Slides
Given a video from e.g., YouTube, how do we generate a video slide suitable for voteview.com?
We need to accomplish six goals:
- Get the video in a standard format suitable for web playback
- Remove audio from video
- Trim the video temporally
- Crop the video to the appropriate aspect ratio
- Scale the video if necessary
- Compress to be small enough
We are going to use the free tool ffmpeg
for this, and we are going to run the command in a single pass.
ffmpeg -i input.mp4 -ss 00:02:33 -to 00:02:46 -vcodec libx264 -an -filter:v "crop=1920:600:0:120, scale=1100:-1" output.mp4
Let's break down each of the sets of arguments in order:
ffmpeg
: Calls the ffmpeg encoder
-i input.mp4
: Specifies an input video file
-ss 00:02:33 -to 00:02:46
: Specifies the temporal trim. The time formats will be hh:mm:ss.ssss, so in this case we're trimming from 2 minutes 33 seconds to 2 minutes 46 seconds
-vcodec libx264
: Converts video format to H.264, which is a web standard video format
-an
: Removes audio entirely
-filter:v
: Specifies we will be using a filter to manipulate the video
"crop=1920:600:0:120, scale=1100:-1"
: Describes how we will manipulate the video, see below for details
output.mp4
: Specifies the output filename.
The filter formats for ffmpeg are describes on ffmpeg.org
In specific, we're using three filters here: crop
and scale
and fps
. I include them in that order, so I will crop first and then scale, and then reduce the framerate, but you can chain together filters however you like. Note that to chain multiple filters, we separate them by commas and quote them.
The format of crop is width:height:x:y
where width is how wide of a box you want to crop, height is how high, and x and y are the top left coordinate of where to start cropping, where 0:0 is the top left of the video. So 1920:640:0:120 starts at (0, 120) and extracts 1920x600 from the video.
The format of scale is width:height
where width is how wide and height is how tall you want the resulting video to be. Using -2 will allow you to keep the other dimension exact and maintain the aspect ratio, so 1100:-2
. The difference between -1 and -2 is that -2 will preserve the height to the nearest multiple of 2, which is a useful feature as most video codecs do not support odd height values. Since the above crop is a 1920x600 video, scaling this down to 1100 pixels wide will produce a 1100x366 video.
The format of fps is framerate
, a number referring to how many pictures per second make up the video. Films are typically 24 frames per second, television is typically 30 frames per second, and digital video is typically 30 or 60 frames per second. Reducing the fps will make motion in the video choppier, but reduce the file size. 20 fps is a good compromise to reduce the file size without ruining the image.
The desired output resolution is at least 1000 pixels wide by no more than 400 pixels tall, so this works well.