Skip to content

Commit 7c107f6

Browse files
committed
test
1 parent ee1a37a commit 7c107f6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/ffmpeg/transcoder.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,14 @@ def pre_encode_if_necessary
160160

161161
def determine_audio_for_pre_encode(path)
162162
local_movie = Movie.new(path)
163-
# If there's a local audio stream, use that
164-
return '-map "0:a"' if local_movie.audio_streams.any?
163+
# If there's a local audio stream, use that. Map only decodable streams explicitly -
164+
# using -map "0:a" would include APAC (Apple Positional Audio Codec) from iPhone
165+
# spatial audio, which FFmpeg cannot decode. audio_streams already excludes these.
166+
if local_movie.audio_streams.any?
167+
puts "|| local_movie.audio_streams: #{local_movie.audio_streams}"
168+
puts "|| local_movie.audio_streams inspect: #{local_movie.audio_streams.inspect}"
169+
return local_movie.audio_streams.map { |s| "-map \"0:#{s[:index]}\"" }.join(' ')
170+
end
165171
# Otherwise, use a silent audio source
166172
# | aevalsrc=0 will generate a silent audio source
167173
# | -shortest will make sure that the output is the duration of the shortest input (meaning the real source input)

spec/ffmpeg/transcoder_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ module FFMPEG
348348
transcoder = Transcoder.new(movie_with_multiple_dimension_inputs, output_path, EncodingOptions.new)
349349

350350
expect(Open3).to receive(:popen3).exactly(2).times # prevent ffprobe calls from being evaluated (check_frame_resolutions)
351-
expect(Open3).to receive(:popen3).twice.with match(/.*\[0\:v\]scale\=854\:480.*pad\=854\:480\:\(ow\-iw\)\/2\:\(oh\-ih\)\/2\:color\=black.*\-map \"0\:a\".*/)
351+
# Maps decodable audio streams by index (excludes APAC); awesome_widescreen has 1 audio stream
352+
expect(Open3).to receive(:popen3).twice.with match(/.*\[0\:v\]scale\=854\:480.*pad\=854\:480\:\(ow\-iw\)\/2\:\(oh\-ih\)\/2\:color\=black.*\-map \"0\:\d+\".*/)
352353

353354
transcoder.send(:pre_encode_if_necessary)
354355
end
@@ -360,7 +361,8 @@ module FFMPEG
360361
# Match silent audio fill
361362
expect(Open3).to receive(:popen3).once.with match(/.*\[0\:v\]scale\=960\:540.*pad\=960\:540\:\(ow\-iw\)\/2\:\(oh\-ih\)\/2\:color\=black.*\-map \"\[a\]\".*/)
362363
# Retain "real" audio
363-
expect(Open3).to receive(:popen3).once.with match(/.*\[0\:v\]scale\=960\:540.*pad\=960\:540\:\(ow\-iw\)\/2\:\(oh\-ih\)\/2\:color\=black.*\-map \"0\:a\".*/)
364+
# Retain "real" audio - maps decodable audio streams by index
365+
expect(Open3).to receive(:popen3).once.with match(/.*\[0\:v\]scale\=960\:540.*pad\=960\:540\:\(ow\-iw\)\/2\:\(oh\-ih\)\/2\:color\=black.*\-map \"0\:\d+\".*/)
364366

365367
transcoder.send(:pre_encode_if_necessary)
366368
end

0 commit comments

Comments
 (0)