How to resample video

I don’t take video, and I don’t know anything about video.  However, every once in a while I’ve had friends take video that I’ve actually wanted to keep.  File sizes can be huge so resampling is important.  I know from watching movies that 90 minutes can be good quality at 700MB file size.  Yet, if you shoot video on an iphone, you’ll reach 700MB in less than six minutes!!  What gives?

The preferred tool for video resampling seems to be ffmpeg  The ffmpeg options are endless (a 2000 line man page, of which I understand almost nothing) and difficult to understand for video non-experts.  There are a few important things to know.

  • Valid video seems to only exist at certain aspect ratios or actually, I believe, certain frame sizes unlike photos.  You can’t simply crop a video to whatever frame size you want like you can with photos.
  • Compression is much more complicated than with photos — no surprise here.
  • Your television may have stricter aspect requirements than general video rules.  (Our lg does anyway.)

ffmpeg has a couple options that I found quite useful.

    • -t seconds  This will restrict your output to the number of seconds you’ve specified.  This is quite useful since avconv take a long time to run.  You can check your results before processing your entire file.
    • -crf number  I think of this as a compression factor.  As this number goes up, file size goes down and quality goes down.  I ended up settling on 32 which worked out to about 9MB/min of video.  That works out to ~800MB for 90 minutes, not far off what the experts do!

So in the end these worked well for me:

ffmpeg -i 20160831_205939.mp4 -vf "yadif=1,scale=-1:720,transpose=1" -codec:v libx264 -crf 32 -preset slow -codec:a copy 20160831_205939_resampled_crf32.mp4
ffmpeg -i 20160831_235629.mp4 -s 1280x720 -codec:v libx264 -crf 32 -preset slow -codec:a copy 20160831_235629_resampled_crf32.mp4

Note that difference here is whether your original video is rotated or not.  The first video was taken vertically, the second horizontally.

Later I received a video from Marius that had a metadata tag of displaymatrix: rotation of -90.00 degrees.  The video displayed fine on the computer, but the tv didn’t like the displaymatrix metadata and/or the aspect ratio.  The solution ended up being:

ffmpeg -i Bryan_skiing_from_Marius.mp4 -metadata:s:v:0 rotate=0 -vf "scale=w=1920:h=1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -codec:v libx264 -crf 32 -preset slow -codec:a copy Bryan_skiing_from_Marius_crf32.mp4

which forces the video to be output at 1920×1080 pixels and fills out (pad) missing pixels (necessary since the video was taken portrait, but the tv needs landscape).  This page helped.

Good luck.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.