# Creating Powerpoint Compatible videos with FFMPEG

This article introduces how to prepare power point compatible videos with the powerful ffmpeg.

## 1. The crux of the matter

Power point supports tons of video formats. However, it doesn’t mean all of them are equally supported inside. Actually, Microsoft offered reference about supported format and recommendations. Mp4 files encoded with H.264 video (a.k.a. MPEG-4 AVC) and AAC audio are favored format. Thus, we only need to re-encode videos using libx264.

## 2. Format converting

The first step is to install ffmpeg one can find tutorials for Windows here, and for Mac here. For windows user, if one doesn’t have administrator privilege, she/he can just unzip the package and cd the bin folder to run the program.

After installation, typing ffmpeg in the terminal, if she/he see the window looks like below, it means the package installed successfully!

Let’s convert a video with H.264, in ffmpeg it follows:

ffmpeg -i field.mp4 -c:v libx264 -crf 18 field_crf18.mp4

Comparing the quality:

Note here we set constant rate factor crf as 18. The range of the crf scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible. A lower value leads to higher quality, and a subjectively sane range is 17-28. Consider 17 or 18 to be visually lossless or nearly so. However, let’s compare the result when crf=45:

ffmpeg -i field.mp4 -c:v libx264 -crf 45 field_crf45.mp4

## 3. Scale, crop, and pad

If the video is wider or too short for presentation, we need ways to resize it. Herein, we introduce some common options should do the trick.

### 3.1 Scale

First, we have a video with original size as 1920\times1080. It can be resized following:

ffmpeg -i moon.mp4 -vf scale=640:480,setdar=4:3 moon_sc.mp4


The video has been distorted with another aspect ratio. We can set the width or height to -2 (computed value will be even) in order to let ffmpeg resize the video keeping the aspect ratio:

ffmpeg -i moon.mp4 -vf scale=-2:480 moon_sc_ar.mp4


### 3.2 Crop

The re-scaled video size from last section is 853\times480, it is bigger than expected 640\\times480. We can crop the video using:

ffmpeg -i moon_sc_ar.mp4 -vf "crop=640:in_h:(in_w-out_w)/2:0" moon_sc_ar_crp.mp4


In the definition of crop=out_w:out_h:x:y:

• out_w indicate the width of the output rectangle
• out_h indicate the height of the output rectangle
• x and y are the top left corner of the output rectangle

In the given example crop=640:in_h:(in_w-out_w)/2:0, the output rectangle has width=640, output height=input height, and will reserve the central area.

The last task is to pad the video. The process is similar to that of crop. Here we pad the last video back to original size 1920\times1080:

ffmpeg -i moon_sc_ar_crp.mp4 -vf "pad=1920:1080:(out_w-in_w)/2:(out_h-in_h)/2" moon_pad.mp4


The color of padding area can be changed into white following:

ffmpeg -i moon_sc_ar_crp.mp4 -vf "pad=1920:1080:(out_w-in_w)/2:(out_h-in_h)/2:white" moon_padwhite.mp4


## 4. Stack

Now, ffmpeg has provided hstack and vstack that we can use to stack videos.

For example, we have two videos:

We can stack videos horizontally:

ffmpeg -i relax.mp4 -i stream.mp4 -filter_complex hstack hComb.mp4


Or vertically:

ffmpeg -i relax.mp4 -i stream.mp4 -filter_complex vstack vComb.mp4


Let’s using hstack and vstack to create a 4\times4 video mosaic:

ffmpeg -i field.mp4 -i moon.mp4 -i relax.mp4 -i stream.mp4 \
-filter_complex "[0:v][1:v]hstack[h1];[2:v][3:v]hstack[h2];[h1][h2]vstack[v]" \
-map "[v]" -c:v libx264 -crf 18 combAll.mp4


Woohoo!!

(All sample videos are from https://videos.pexels.com/)