Reputation: 2056
I have a situation where ffmpeg
is throwing an error:
Invalid data found when processing input
I've reviewed other answers here, but my situation is different. I generate in Ruby
, a text file with a list of input files I want to concatenate together into one large video.
I generate in Ruby
, the command meant for bash
, which is also output for me to manually copy:
ffmpeg -y -f concat -safe 0 -i /Volumes/Dragon2/Yums/randoms.txt /Volumes/Dragon2/Yums/final.mp4
Throws an error:
/Volumes/Dragon2/Yums/randoms.txt: Invalid data found when processing input
Here is that file:
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'
When bash
runs it, it complains about the input file randoms.txt having invalid data. When I copy and paste the very same command in bash
, it works fine. I'm stumped as to how the two are different and why ffmpeg
is not happy when initiated in the shell
.
How can I get this to work? What am I missing? Cheers
EDIT: Original ruby
code:
`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 }`
I have also tried system s
as well with the same error. The syntax is generated fine, output fine, operates fine manually.
Upvotes: 1
Views: 7866
Reputation: 2056
I needed f.close
to write the file so ffmpeg
could read from it. But the shellwords
was also key. Thank you .
Upvotes: 3