From 4c6c19d0ae29cc89ecc0e502c136eb7b339595cb Mon Sep 17 00:00:00 2001 From: bajankristof Date: Wed, 1 Apr 2026 16:43:38 +0200 Subject: [PATCH 1/2] fix: detect more common file extensions correctly Co-Authored-By: Claude Opus 4.6 --- lib/ffmpeg/media.rb | 48 ++++++++++++++++++++++++++++++++++---- lib/ffmpeg/stream.rb | 7 ++++++ spec/ffmpeg/stream_spec.rb | 26 +++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/lib/ffmpeg/media.rb b/lib/ffmpeg/media.rb index 2ee8bfe..cb30c96 100644 --- a/lib/ffmpeg/media.rb +++ b/lib/ffmpeg/media.rb @@ -78,26 +78,50 @@ def initialize(message, output) when /\Adash\b/ then '.mpd' when /\bhls\b/ then '.m3u8' when /\bmpegts(raw)?\b/ then '.ts' - when /\bmpegvideo\b/ then '.mpg' - when /\blive_flv\b/ then '.flv' - when /\basf_o\b/ then '.asf' + when /\bmpeg(video\b|\z)/ then '.mpg' + when /\blive_flv\b/ then '.flv' + when /\basf\b/ + if video? + '.wmv' + elsif audio? + '.wma' + else + '.asf' + end when /\b(mov|mp4)\b/ case major_brand when nil, /\Aqt\b/i then '.mov' when /\Am4a\b/i then '.m4a' when /\Am4v\b/i then '.m4v' when /\Am4s\b/i then '.m4s' - else '.mp4' + when /\A3g2/i then '.3g2' + when /\A3gp/i then '.3gp' + when /\Af4v\b/i then '.f4v' + when /\Af4p\b/i then '.f4p' + when /\Af4a\b/i then '.f4a' + when /\Af4b\b/i then '.f4b' + when /\Aavi[fs]\b/i then '.avif' + else '.mp4' end when /\bmatroska\b/ if streams - .select { _1.video? || _1.audio? } + .select(&:av?) .reject(&:attached_pic?) .all? { WEBM_CODEC_NAMES.include?(_1.codec_name) } '.webm' else '.mkv' end + when /\bogg\b/ + if video_streams? + '.ogv' + elsif include_codec_name?('opus') + '.opus' + elsif include_codec_name?('speex') + '.spx' + else + '.ogg' + end else muxer = format_name @@ -238,6 +262,20 @@ def local? @valid end + # Whether the media contains any of the specified codec names. + # + # @return [Boolean] + autoload def include_codec_name?(*codec_names) + self.codec_names.any? { codec_names.include?(_1) } + end + + # Returns the set of all codec names used in the media's streams. + # + # @return [Set] + autoload def codec_names + @codec_names ||= streams.map(&:codec_name).compact.to_set + end + # Returns the major brand of the media (if any). autoload def major_brand tags&.fetch(:major_brand, nil)&.to_s&.strip diff --git a/lib/ffmpeg/stream.rb b/lib/ffmpeg/stream.rb index b0035a5..5f41d33 100644 --- a/lib/ffmpeg/stream.rb +++ b/lib/ffmpeg/stream.rb @@ -115,6 +115,13 @@ def audio? codec_type == :audio end + # Whether the stream is an audio or video stream. + # + # @return [Boolean] + def av? + video? || audio? + end + # Whether the stream is marked as default. # # @return [Boolean] diff --git a/spec/ffmpeg/stream_spec.rb b/spec/ffmpeg/stream_spec.rb index 9452af0..aa9f686 100644 --- a/spec/ffmpeg/stream_spec.rb +++ b/spec/ffmpeg/stream_spec.rb @@ -62,6 +62,32 @@ module FFMPEG end end + describe '#av?' do + context 'when the codec type is video' do + let(:metadata) { { codec_type: 'video' } } + + it 'returns true' do + expect(subject.av?).to be(true) + end + end + + context 'when the codec type is audio' do + let(:metadata) { { codec_type: 'audio' } } + + it 'returns true' do + expect(subject.av?).to be(true) + end + end + + context 'when the codec type is not video or audio' do + let(:metadata) { { codec_type: 'subtitle' } } + + it 'returns false' do + expect(subject.av?).to be(false) + end + end + end + describe '#default?' do context 'when marked as default' do let(:metadata) { { disposition: { default: 1 } } } From 3825ffc50a3f1b73834a0b28c07add72e2cfc9e3 Mon Sep 17 00:00:00 2001 From: bajankristof Date: Wed, 1 Apr 2026 16:49:04 +0200 Subject: [PATCH 2/2] chore: update version to 8.4.3 and document changes --- CHANGELOG | 5 +++++ lib/ffmpeg/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4f228f5..9d3733b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +== 8.4.3 2026-04-02 + +Fixes: +* Correctly detect 3gp and 3g2 file extensions (and some others). + == 8.4.2 2026-04-01 Fixes: diff --git a/lib/ffmpeg/version.rb b/lib/ffmpeg/version.rb index 1244a32..9f483af 100644 --- a/lib/ffmpeg/version.rb +++ b/lib/ffmpeg/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module FFMPEG - VERSION = '8.4.2' + VERSION = '8.4.3' end