FFmpeg transcoding¶
Sometimes you simply want to run a command with cloud resources. For instance, transcoding videos is a CPU intensive operation that would benefit from a large number of CPU cores, which might not be available locally. Fortunately, this is a straight forward task with o‑o.
To demonstrate, complete the o‑o installation
instructions. Then create a .ooconfig file with an
environment with a 32 core CPU. For our task, video transcoding, use a
docker image with FFmpeg installed:
First, let's transcode the video locally for comparison:
$ ffmpeg \
-i https://archive.org/download/ElephantsDream/ed_1024.avi \
-c:v libx265 \
ElephantsDream.mp4
...
frame=15691 fps= 14 q=36.0 Lsize= 81682kB time=00:10:53.80 bitrate=1023.5kbits/s speed=0.599x
video:49856kB audio:31390kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.536897%
x265 [info]: frame I: 150, Avg QP:25.35 kb/s: 4552.76
x265 [info]: frame P: 6763, Avg QP:28.43 kb/s: 965.42
x265 [info]: frame B: 8778, Avg QP:34.43 kb/s: 293.69
x265 [info]: Weighted P-Frames: Y:5.1% UV:2.1%
x265 [info]: consecutive B-frames: 53.6% 3.6% 10.3% 26.9% 5.5%
encoded 15691 frames in 1091.59s (14.37 fps), 623.93 kb/s, Avg QP:31.76
[aac @ 0x59c63861fd80] Qavg: 2275.715
On a typical 4 core laptop, this might take 15-20 minutes to transcode this 11 minute video. Now, let's use o‑o to run the same command on a bigger 32 core machine:
$ o-o run -m "test transcode" -- ffmpeg \
-i https://archive.org/download/ElephantsDream/ed_1024.avi \
-c:v libx265 \
o://output/ElephantsDream.mp4
...
frame=15691 fps=192 q=36.0 Lsize= 77548KiB time=00:10:53.82 bitrate= 971.6kbits/s speed=8.02x elapsed=0:01:21.56
x265 [info]: frame I: 148, Avg QP:25.33 kb/s: 4592.80
x265 [info]: frame P: 6747, Avg QP:28.43 kb/s: 966.31
x265 [info]: frame B: 8796, Avg QP:34.43 kb/s: 294.60
x265 [info]: Weighted P-Frames: Y:5.3% UV:2.1%
encoded 15691 frames in 81.54s (192.44 fps), 623.97 kb/s, Avg QP:31.77
[aac @ 0x563298fd0440] Qavg: 516.964
Thanks to o‑o, this tasks now takes about 3 minutes total, including
environment setup and tear-down. To retrieve the transcoded file, we simply
use the o-o cp command:
With just a simple modification to the command line, o‑o employed cloud compute to dramatically speed up our transcoding task.