我收到了mp3格式的文件(2分钟/个),我想连接在一起并创建一个更大的文件。因此,我创建了我的模型,使用FMPEG1和IO.popen创建了一个函数来完成此任务
FileUtils.mkdir_p "#{Rails.root}/tmp/files"
imported_dir = "#{Rails.root}/tmp/files/#{SecureRandom.uuid}"
links.each_with_index do |link, index|
file_path = "#{imported_dir}_#{index}#{File.extname(link)}"
File.open(file_path, 'wb') do |file|
file.write open(link).read
end
concat_list << "file '#{file_path}'\n"
end
File.open("#{imported_dir}.txt", 'w'){ |f| f.write(concat_list)}
io = IO.popen("#{Rails.root}/lib/ffmpeg/ffmpeg -f concat -i #{imported_dir}.txt -c copy #{imported_dir}.mp3").readlines
if sound = Sound.create(user_id: user.id, file: File.open("#{imported_dir}.mp3"), lang: lang, title: title)
audio = FFMPEG::Movie.new("#{imported_dir}.mp3")
if !audio.valid?
puts "//_!_\\\\ Failed reading with ffmpeg (#{sound.id})#{sound.title} //_!_\\\\"
return false
end
end 问题是我的.txt文件包含文件路径
file '/home/test/apps/example/releases/20150305224026/tmp/files/4dbe9707-cfef-467b-ab2c-a5e1e1165953_0.mp3'也创建了文件,但没有创建最终文件,我得到了错误消息:
No such file or directory @ rb_sysopen - /home/test/apps/example/releases/20150305224026/tmp/files/4dbe9707-cfef-467b-ab2c-a5e1e1165953.mp3如果有人能帮我的话
发布于 2015-03-06 20:13:01
确保目标目录存在,并且可由运行应用程序的用户写入。
https://stackoverflow.com/questions/28897861
复制相似问题