I want to create IGTV videos without any extra video editing, and with a few additional ffmpeg commands, and by creating a header image, I can do that.
A previous Talotics post covered ffmpeg to subtitles and formatting videos for Instagram, now I want to look at creating IGTV videos using ffmpeg. Again, these are using the same original base video and the same subtitles, so I’m not doing any video editing. I’m simply using ffmpeg to support syndicating the video on a different platform.
Instagram IGT video aspect ration is ‘9:16’ which is ‘width:height’ and it is basically a 720p video in portrait mode rather than landscape.
- if width is 720 then height is 1280
You can create videos natively using your mobile phone and edit them. But the common strategy I see for people re-purposing content is to create an image title at the top, embed a landscape video in the middle and have subtitles underneath, and that’s pretty easy to do with ffmpeg.
A basic command to create a portrait video from a landscape video is:
ffmpeg -i input.mp4 -vf "scale=w=720:h=1280:
force_original_aspect_ratio=1,pad=720:
1280:(ow-iw)/2:oh-ih"
output.mp4
if you typed this in, remember to have it all on one line, I formatted it on multiple lines for readability
The x, y position of the input video is controlled by the pad: pad=720:1280:(ow-iw)/2:oh-ih
720
- I want video to have720
width1280
- I want video to have1280
height(ow-iw)/2
- I want video to pad the input video(output width - input width)
and then divide this by 2, so I’m essentially centering the video in the width(oh-ih)
- I want to pad this video height by (output height - input height), essentially forcing the input video to the bottom
To add an image at the same time (for the header) I have to use overlay
and -filter_complex
because I have two input files:
ffmpeg -i input.mp4 -i headerimage.png -filter_complex
"scale=w=720:h=1280:
force_original_aspect_ratio=1,pad=720:1280:
(ow-iw)/2:oh-ih,overlay"
output.mp4
I experimented with a few image sizes and positions and eventually decided on creating an image that was 720x426
- 426
is about a 3rd of 1280.
Then a command link the following will create an IGTV video from a landscape video with a header image at the top:
remember, everthing on one line
ffmpeg -i instagram-subs.mp4 -i headerimage.png
-filter_complex
"scale=w=720:h=1280:
force_original_aspect_ratio=1,pad=720:1280:
(ow-iw)/2:426,overlay"
instagram-subs-igt.mp4
I have added the code for this to this gist to make it easier to copy and paste
The good thing about IGTV is that we can upload through the desktop so we don’t need to transfer the video to a mobile device.
This makes it easy to copy and paste the description from YouTube.
IGTV videos are 10 minutes long for most people, so you might need to trim the video into parts, but we covered how to do that in this post.
Useful Links:
- https://superuser.com/questions/991371/ffmpeg-scale-and-pad
- https://ffmpeg.org/ffmpeg-filters.html#overlay-1
- https://video.stackexchange.com/questions/12105/add-an-image-overlay-in-front-of-video-using-ffmpeg
You can find the commands in an easy to copy and past format in this gist page