From ef68b29493c58333a9c432fb188b97d83697dba1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu>
Date: Mon, 4 Feb 2019 11:15:57 +0100
Subject: [PATCH] Create Video: always pad video to even sizes

H.264 requires that the width and height of the video frame are
multiples of the chroma block size. When using the default yuv420 pixel
format this means the dimensions should be even (e.g. multiples of 2).
The video filter added in this commit ensures this by padding out the
frame with black pixels.
---
 flamenco_worker/commands.py         | 1 +
 tests/test_commands_create_video.py | 1 +
 2 files changed, 2 insertions(+)

diff --git a/flamenco_worker/commands.py b/flamenco_worker/commands.py
index 4e05797f..e859e383 100644
--- a/flamenco_worker/commands.py
+++ b/flamenco_worker/commands.py
@@ -1239,6 +1239,7 @@ class CreateVideoCommand(AbstractFFmpegCommand):
             '-c:v', self.codec_video,
             '-crf', str(self.constant_rate_factor),
             '-g', str(self.keyframe_interval),
+            '-vf', 'pad=ceil(iw/2)*2:ceil(ih/2)*2',
             '-y',
         ]
         if self.max_b_frames is not None:
diff --git a/tests/test_commands_create_video.py b/tests/test_commands_create_video.py
index 8668c8ab..f5c02e19 100644
--- a/tests/test_commands_create_video.py
+++ b/tests/test_commands_create_video.py
@@ -67,6 +67,7 @@ class CreateVideoTest(AbstractCommandTest):
             '-c:v', 'h264',
             '-crf', '23',
             '-g', '18',
+            '-vf', 'pad=ceil(iw/2)*2:ceil(ih/2)*2',
             '-y',
             '-bf', '0',
             '/tmp/merged.mkv',
-- 
GitLab