|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../../spec_helper' |
| 4 | + |
| 5 | +module FFMPEG |
| 6 | + class CommandArgs |
| 7 | + describe ColorSpaceInjection do |
| 8 | + let(:media) { instance_double(FFMPEG::Media) } |
| 9 | + |
| 10 | + subject(:args) do |
| 11 | + CommandArgs.compose(media) do |
| 12 | + use ColorSpaceInjection |
| 13 | + end.to_a |
| 14 | + end |
| 15 | + |
| 16 | + context 'when the media has no video streams' do |
| 17 | + before { allow(media).to receive(:video_streams?).and_return(false) } |
| 18 | + |
| 19 | + it 'does not apply color space injection arguments' do |
| 20 | + expect(args).to be_empty |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + context 'when the media video codec is not H.264 or HEVC' do |
| 25 | + before do |
| 26 | + allow(media).to receive(:video_streams?).and_return(true) |
| 27 | + allow(media).to receive(:video_codec_name).and_return('vp9') |
| 28 | + end |
| 29 | + |
| 30 | + it 'does not apply color space injection arguments' do |
| 31 | + expect(args).to be_empty |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + context 'when the media color space is not reserved' do |
| 36 | + before do |
| 37 | + allow(media).to receive(:video_streams?).and_return(true) |
| 38 | + allow(media).to receive(:video_codec_name).and_return('h264') |
| 39 | + allow(media).to receive(:color_space).and_return('bt709') |
| 40 | + end |
| 41 | + |
| 42 | + it 'does not apply color space injection arguments' do |
| 43 | + expect(args).to be_empty |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context 'when the media meets all conditions for color space injection' do |
| 48 | + before do |
| 49 | + allow(media).to receive(:video_streams?).and_return(true) |
| 50 | + allow(media).to receive(:video_codec_name).and_return('h264') |
| 51 | + allow(media).to receive(:color_space).and_return('reserved') |
| 52 | + end |
| 53 | + |
| 54 | + it 'applies color space injection arguments' do |
| 55 | + expect(args).to eq( |
| 56 | + %w[ |
| 57 | + -bsf:v |
| 58 | + h264_metadata=colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1 |
| 59 | + ] |
| 60 | + ) |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | +end |
0 commit comments