lib/scissor/writer.rb in scissor-0.2.9 vs lib/scissor/writer.rb in scissor-0.3.0
- old
+ new
@@ -26,14 +26,17 @@
end
def join_fragments(fragments, outfile, tmpdir)
position = 0.0
cmd = %w/ecasound/
+ is_mono = {}
fragments.each_with_index do |fragment, index|
fragment_filename = fragment.filename
+ is_mono[fragment_filename] ||= mono?(fragment_filename)
+
if !index.zero? && (index % 28).zero?
run_command(cmd.join(' '))
cmd = %w/ecasound/
end
@@ -42,11 +45,11 @@
unless fragment_outfile.exist?
movie = FFMPEG::Movie.new(fragment_filename.to_s)
movie.transcode(fragment_outfile.to_s, :audio_sample_rate => 44100)
end
- cmd << "-a:#{index} -o:#{outfile} -y:#{position}"
+ cmd << "-a:#{index} -o:#{outfile} -y:#{position}#{is_mono[fragment_filename] ? ' -chcopy:1,2' : ''}"
if fragment.stretched? && fragment.pitch.to_f != 100.0
rubberband_out = tmpdir + (Digest::MD5.hexdigest(fragment_filename.to_s) + "rubberband_#{index}.wav")
rubberband_temp = tmpdir + "_rubberband.wav"
@@ -144,8 +147,14 @@
if status && status.exitstatus != 0
raise CommandFailed.new(cmd)
end
return result
+ end
+
+ private
+
+ def mono?(filename)
+ SoundFile.new_from_filename(filename).mono?
end
end
end