lib/scissor/writer.rb in scissor-0.1.1 vs lib/scissor/writer.rb in scissor-0.1.2
- old
+ new
@@ -35,36 +35,32 @@
if !index.zero? && (index % 28).zero?
run_command(cmd.join(' '))
cmd = %w/ecasound/
end
- if fragment_filename.extname.downcase == '.wav'
- fragment_outfile = fragment_filename
- else
- fragment_outfile = tmpdir + (Digest::MD5.hexdigest(fragment_filename.to_s) + '.wav')
- end
+ fragment_outfile = tmpdir + (Digest::MD5.hexdigest(fragment_filename.to_s) + '.wav')
unless fragment_outfile.exist?
- run_command("ffmpeg -i \"#{fragment_filename}\" \"#{fragment_outfile}\"")
+ run_command("ffmpeg -i \"#{fragment_filename}\" -ar 44100 \"#{fragment_outfile}\"")
end
cmd << "-a:#{index} -o:#{outfile} -y:#{position}"
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"
-
- run_command("ecasound " +
+
+ run_command("ecasound " +
"-i:" +
(fragment.reversed? ? 'reverse,' : '') +
"select,#{fragment.start},#{fragment.original_duration},\"#{fragment_outfile}\" -o:#{rubberband_temp} "
)
run_command("rubberband -T #{fragment.pitch.to_f/100} \"#{rubberband_temp}\" \"#{rubberband_out}\"")
cmd << "-i:\"#{rubberband_out}\""
else
- cmd <<
+ cmd <<
"-i:" +
(fragment.reversed? ? 'reverse,' : '') +
"select,#{fragment.start},#{fragment.original_duration},\"#{fragment_outfile}\" " +
(fragment.pitch.to_f == 100.0 ? "" : "-ei:#{fragment.pitch} ")
end
@@ -117,15 +113,11 @@
join_fragments(fragments, tmpfile, tmpdir)
end
mix_files(tmpfiles, final_tmpfile = tmpdir + 'tmp.wav')
- if filename.extname == '.wav'
- File.rename(final_tmpfile, full_filename)
- else
- run_command("ffmpeg -ab #{options[:bitrate]} -i \"#{final_tmpfile}\" \"#{full_filename}\"")
- end
+ run_command("ffmpeg -ab #{options[:bitrate]} -i \"#{final_tmpfile}\" -ar 44100 \"#{full_filename}\"")
end
end
def which(command)
run_command("which #{command}")
@@ -135,13 +127,20 @@
def run_command(cmd)
logger.debug("run_command: #{cmd}")
result, error = '', ''
- status = Open4.spawn cmd, 'stdout' => result, 'stderr' => error
- logger.debug(error)
- if status.exitstatus != 0
+ begin
+ status = Open4.spawn cmd, 'stdout' => result, 'stderr' => error
+ rescue Open4::SpawnError => e
+ raise CommandFailed.new(e.cmd)
+ ensure
+ logger.debug(result)
+ logger.debug(error)
+ end
+
+ if status && status.exitstatus != 0
raise CommandFailed.new(cmd)
end
return result
end