【发布时间】:2018-09-20 06:28:08
【问题描述】:
我遇到ffmpeg 抛出错误的情况:
Invalid data found when processing input
我在这里查看了其他答案,但我的情况有所不同。我在Ruby 中生成一个带有输入文件列表的文本文件,我想将它们连接在一起形成一个大视频。
我在Ruby 中生成,用于bash 的命令,也是我手动复制的输出:
ffmpeg -y -f concat -safe 0 -i /Volumes/Dragon2/Yums/randoms.txt /Volumes/Dragon2/Yums/final.mp4
抛出错误:
/Volumes/Dragon2/Yums/randoms.txt: Invalid data found when processing input
这是那个文件:
file '/Volumes/Dragon2/Yums/0CEDC3CA-4571-4271-9938-A161EC2A887B.mov'
file '/Volumes/Dragon2/Yums/0D25D907-D053-443B-AFC6-9F12B1711BBF.mov'
file '/Volumes/Dragon2/Yums/6A272808-7706-435D-801E-ACE6B42EC749.mov'
file '/Volumes/Dragon2/Yums/6E9BA2F1-C5E7-4C1C-B290-D116105732FA.mov'
file '/Volumes/Dragon2/Yums/0A41C7B7-74CE-484E-B029-3AE57B8BB4EA.mov'
bash 运行它时,它会抱怨输入文件 randoms.txt 包含无效数据。当我在bash 中复制并粘贴相同的命令时,它工作正常。我很难理解这两者有何不同以及为什么ffmpeg 在shell 中启动时不高兴。
我怎样才能让它工作?我错过了什么?干杯
编辑:原始ruby 代码:
`clear`
require 'pathname'
require 'pp'
s = '/Volumes/Dragon2/Yums'
files = []
Dir.foreach(s) do |path|
files << "#{ s }/#{ path }"
end
result = files.sample(files.size) # randomizer
f = File.open("#{ s }/randoms.txt", 'w+')
result.each_with_index do |item, i|
pp "#{ i }: #{ item }" if item.include?('mov')
f << "file '#{ item }'\n" if item.include?('mov')
end
`echo `
File.delete("#{ s }/final.mp4") if File.exists?("#{ s }/final.mp4")
s = "ffmpeg -y -f concat -safe 0 -i #{ s }/randoms.txt #{ s }/final.mp4"
puts s
sleep 3
`#{ s }`
我也尝试过system s,但出现了同样的错误。语法生成良好,输出良好,手动操作良好。
【问题讨论】:
-
这里不清楚 Ruby 是如何影响的。你是从 Ruby 运行的吗?如果有,Ruby 代码在哪里?
-
我不明白
ruby是如何导致罪魁祸首的,因为它是来自ruby的系统调用,但我会编辑帖子。 -
如果这不是一个因素,那么删除标签会更安全。请记住,文件名中可以包含空格,因此在 Ruby 中,您在引入这些类型的参数时必须调用
shellescape。使用Open3 启动可能比真正的弱反引号方法更安全。这样您就可以专门指定参数,而不是让 shell 来解析它们。 -
好的,实现了
Shellwords.escape(item)的加法,但是示例文件没有空格。我仍然遇到同样的错误。 -
@tadman 也使用了
open3,但出现同样的错误。stderr是同样的报错。