Commit 2c609912 authored by ThibG's avatar ThibG Committed by GitHub

Fix videos with unsupported colorspace not being transcoded (#13242)

parent abd83948
...@@ -78,8 +78,9 @@ class MediaAttachment < ApplicationRecord ...@@ -78,8 +78,9 @@ class MediaAttachment < ApplicationRecord
}.freeze }.freeze
VIDEO_PASSTHROUGH_OPTIONS = { VIDEO_PASSTHROUGH_OPTIONS = {
video_codec_whitelist: ['h264'], video_codecs: ['h264'],
audio_codec_whitelist: ['aac', nil], audio_codecs: ['aac', nil],
colorspaces: ['yuv420p'],
options: { options: {
format: 'mp4', format: 'mp4',
convert_options: { convert_options: {
......
...@@ -6,19 +6,21 @@ module Paperclip ...@@ -6,19 +6,21 @@ module Paperclip
class VideoTranscoder < Paperclip::Processor class VideoTranscoder < Paperclip::Processor
def make def make
movie = FFMPEG::Movie.new(@file.path) movie = FFMPEG::Movie.new(@file.path)
actual_options = options
passthrough_options = actual_options[:passthrough_options]
actual_options = passthrough_options[:options] if passthrough?(movie, passthrough_options)
attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec
Paperclip::Transcoder.make(file, actual_options, attachment) Paperclip::Transcoder.make(file, actual_options(movie), attachment)
end end
private private
def passthrough?(movie, options) def actual_options(movie)
options && options[:video_codec_whitelist].include?(movie.video_codec) && options[:audio_codec_whitelist].include?(movie.audio_codec) opts = options[:passthrough_options]
if opts && opts[:video_codecs].include?(movie.video_codec) && opts[:audio_codecs].include?(movie.audio_codec) && opts[:colorspaces].include?(movie.colorspace)
opts[:options]
else
options
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment