diff --git a/lib/ffmpeg/media.rb b/lib/ffmpeg/media.rb index 0ad5070..453f90d 100644 --- a/lib/ffmpeg/media.rb +++ b/lib/ffmpeg/media.rb @@ -195,6 +195,10 @@ def audio_only? audio? && !video? end + def audio_with_attached_pic? + audio? && streams.any?(&:attached_pic?) + end + def silent? !audio? end diff --git a/lib/ffmpeg/stream.rb b/lib/ffmpeg/stream.rb index 804f4be..96424f1 100644 --- a/lib/ffmpeg/stream.rb +++ b/lib/ffmpeg/stream.rb @@ -101,6 +101,14 @@ def audio? codec_type == CodecType::AUDIO end + def default? + metadata.dig(:disposition, :default) == 1 + end + + def attached_pic? + metadata.dig(:disposition, :attached_pic) == 1 + end + def width @rotation.nil? || @rotation == 180 ? @width : @height end diff --git a/spec/ffmpeg/media_spec.rb b/spec/ffmpeg/media_spec.rb index 2da6a01..9802648 100644 --- a/spec/ffmpeg/media_spec.rb +++ b/spec/ffmpeg/media_spec.rb @@ -247,6 +247,7 @@ module FFMPEG end it 'should return false if the media has video streams' do + subject = described_class.new("#{fixture_path}/sounds/napoleon.mp3") expect(subject.audio_only?).to be(false) end @@ -256,6 +257,22 @@ module FFMPEG end end + describe '#audio_with_attached_pic?' do + it 'should return true if the media has audio streams with attached pictures' do + subject = described_class.new("#{fixture_path}/sounds/napoleon.mp3") + expect(subject.audio_with_attached_pic?).to be(true) + end + + it 'should return false if the media does not have audio streams with attached pictures' do + expect(subject.audio_with_attached_pic?).to be(false) + end + + it 'should return false if the media does not have attached pictures' do + subject = described_class.new("#{fixture_path}/sounds/hello.wav") + expect(subject.audio_with_attached_pic?).to be(false) + end + end + %i[ index profile diff --git a/spec/ffmpeg/stream_spec.rb b/spec/ffmpeg/stream_spec.rb index 18b308b..fa84a76 100644 --- a/spec/ffmpeg/stream_spec.rb +++ b/spec/ffmpeg/stream_spec.rb @@ -62,6 +62,42 @@ module FFMPEG end end + describe '#default?' do + context 'when marked as default' do + let(:metadata) { { disposition: { default: 1 } } } + + it 'should return true' do + expect(subject.default?).to be(true) + end + end + + context 'when not marked as default' do + let(:metadata) { { disposition: { default: 0 } } } + + it 'should return false' do + expect(subject.default?).to be(false) + end + end + end + + describe '#attached_pic?' do + context 'when marked as an attached picture' do + let(:metadata) { { disposition: { attached_pic: 1 } } } + + it 'should return true' do + expect(subject.attached_pic?).to be(true) + end + end + + context 'when not marked as an attached picture' do + let(:metadata) { { disposition: { attached_pic: 0 } } } + + it 'should return false' do + expect(subject.attached_pic?).to be(false) + end + end + end + describe '#width' do context 'when the rotation is nil' do let(:metadata) { { width: 100, height: 200 } } diff --git a/spec/fixtures/sounds/napoleon.mp3 b/spec/fixtures/sounds/napoleon.mp3 index 2fccbf6..9cf7547 100644 Binary files a/spec/fixtures/sounds/napoleon.mp3 and b/spec/fixtures/sounds/napoleon.mp3 differ