Video Encoding

From TheBeard Science Project Wiki
Revision as of 17:03, 11 March 2020 by Beard (talk | contribs) (Timelapse From Image Files)

Jump to: navigation, search

Encoding in H.265

I've seen very good quality and significantly smaller file sizes in videos encoded with H.265.

ffmpeg -i infile.mp4 -c:v libx265 outfile.mp4

Deinterlacing

ffmpeg -i 000000.MTS -vf yadif -c:v libx265 outfile.mp4

Timelapse From Image Files

In the terminal, go into your folder full of images.

neuro@gamma:~/timelapse$ ls
DSC05145.JPG  DSC05163.JPG  DSC05181.JPG  DSC05199.JPG  DSC05217.JPG
DSC05146.JPG  DSC05164.JPG  DSC05182.JPG  DSC05200.JPG  DSC05218.JPG
DSC05147.JPG  DSC05165.JPG  DSC05183.JPG  DSC05201.JPG  DSC05219.JPG
DSC05148.JPG  DSC05166.JPG  DSC05184.JPG  DSC05202.JPG  DSC05220.JPG
...

Create a timelapse of all files, with a framerate of 20fps:

ffmpeg -r 20 -f image2 -pattern_type glob -i "*.JPG" -c:v libx265 ../out.mp4

Create a timelapse starting from file 05200, with a total of 30 frames:

ffmpeg -r 20 -f image2 -start_number 05200 -i DSC%05d.JPG -frames:v 30 -c:v libx265 ../out.mp4

Note: the "%05d" means zero-padded 5-digit number.

AV1 Codec Testing

Last updated 3/11/2020

AV1 is the newest emerging video coding format currently under development by AOMedia. I was interested in trying it out and seeing how it compares to my current favorite x265, and also the older x264. Keep in mind I'm doing this for my own purposes, so the following benchmarks are not comprehensive and are limited to my own intended use cases.

The AV! ligrary libaom-av1 is not currently available in ffmpeg by default. I found a good script someone made for compiling ffmpeg with support for AV1: https://gist.github.com/sparrc/026ed9958502072dda749ba4e5879ee3

I downloaded the script:

wget https://gist.githubusercontent.com/sparrc/026ed9958502072dda749ba4e5879ee3/raw/e22698ead1984cd86b943f3473bd4bfb98591808/install-ffmpeg.sh

Note: as always, never download and run a script without reading it yourself to determine that it dos not do anything malicious.

I ran the script:

sudo bash install-ffmpeg.sh

this script installs the custom ffmpeg into ~/bin/ffmpeg.

I chose a relatively small MTS file for testing:

du -h 00056.MTS
38M     00056.MTS

Runtime Benchmarks

In the following benchmarks, the relevant time is the "real" time. Also, the test file is video:h264 and audio:ac3. Each encoding process I do below uses all default for the format and encodes the audio to aac.

x264 benchmark

time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -c:v libx264 out_x264.mp4
real    0m28.159s
user    1m43.388s
sys     0m0.176s

x265 benchmark

time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -c:v libx265 out_x265.mp4
real    0m43.420s
user    2m40.852s
sys     0m0.304s

av1 benchmark

time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -c:v libaom-av1 -strict -2 out_av1.mp4
real    177m27.737s
user    413m16.620s
sys     0m6.688s

Note: The "-strict -2" parameter allows for the use of experimental codecs.

File Size Comparison

du -h out_*;du -h outd*
11M     out_av1.mp4
15M     out_x264.mp4
5.6M    out_x265.mp4
8.2M    outd_av1.mp4
13M     outd_x264.mp4
4.1M    outd_x265.mp4