From 8a2b8e0321691ceab1c0c0c00c686d71cb065ae6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 9 Mar 2020 02:20:18 +0100 Subject: [PATCH] Change video uploads to always be converted to H264/MP4 (#13220) Even if the container format is the same (.mp4), the codec could be different and not playable in web browsers --- app/models/media_attachment.rb | 72 +++++++++++++++------------------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 49e2e5e27..7c9b4b909 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -57,47 +57,6 @@ class MediaAttachment < ApplicationRecord }, }.freeze - VIDEO_STYLES = { - small: { - convert_options: { - output: { - 'loglevel' => 'fatal', - vf: 'scale=\'min(400\, iw):min(400\, ih)\':force_original_aspect_ratio=decrease', - }, - }, - format: 'png', - time: 0, - file_geometry_parser: FastGeometryParser, - blurhash: BLURHASH_OPTIONS, - }, - - original: { - keep_same_format: true, - convert_options: { - output: { - 'loglevel' => 'fatal', - 'map_metadata' => '-1', - 'c:v' => 'copy', - 'c:a' => 'copy', - }, - }, - }, - }.freeze - - AUDIO_STYLES = { - original: { - format: 'mp3', - content_type: 'audio/mpeg', - convert_options: { - output: { - 'loglevel' => 'fatal', - 'map_metadata' => '-1', - 'q:a' => 2, - }, - }, - }, - }.freeze - VIDEO_FORMAT = { format: 'mp4', content_type: 'video/mp4', @@ -118,6 +77,37 @@ class MediaAttachment < ApplicationRecord }, }.freeze + VIDEO_STYLES = { + small: { + convert_options: { + output: { + 'loglevel' => 'fatal', + vf: 'scale=\'min(400\, iw):min(400\, ih)\':force_original_aspect_ratio=decrease', + }, + }, + format: 'png', + time: 0, + file_geometry_parser: FastGeometryParser, + blurhash: BLURHASH_OPTIONS, + }, + + original: VIDEO_FORMAT, + }.freeze + + AUDIO_STYLES = { + original: { + format: 'mp3', + content_type: 'audio/mpeg', + convert_options: { + output: { + 'loglevel' => 'fatal', + 'map_metadata' => '-1', + 'q:a' => 2, + }, + }, + }, + }.freeze + VIDEO_CONVERTED_STYLES = { small: VIDEO_STYLES[:small], original: VIDEO_FORMAT,