added ruby script for concat videos

This commit is contained in:
Marco Calderon 2011-03-23 04:16:00 +00:00
parent 4e55a6e157
commit 58b0530f17
3 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,18 @@
README file
Scripts Description:
===============================================================
concat-videos.rb
The script can create a image video of T seconds taking the logo.jpg file, and can join several videos.
Receives N parameters which can be a video filename and/or integer T. Usage:
ruby concat-videos.rb video1.flv 25 video2.flv
output: a result.flv video (video1.flv+imageVideo.flv+video2.flv)
ruby concat-videos.rb video1.flv 25 video2.flv 60 video3.flv
output: a result.flv video (video1.flv+imageVideo.flv+video2.flv+imageVideo.flv+video3.flv)
NOTE: The videos to join should be in the same directory
===============================================================

View File

@ -0,0 +1,51 @@
class MediaFormatException < StandardError
end
class String
def is_i?
!!(self =~ /^[-+]?[0-9]+$/)
end
end
def executeFfmpeg(command)
IO.popen(command) do |pipe|
pipe.each("r") do |line|
puts line
end
end
raise MediaFormatException if $?.exitstatus != 0
end
def executeMencoder(videos)
command="mencoder -forceidx -of lavf -oac copy -ovc copy -o result.flv "
videos.each do|a|
command << "#{a} "
end
IO.popen(command) do |pipe|
pipe.each("r") do |line|
puts line
end
end
raise MediaFormatException if $?.exitstatus != 0
end
def execute(args)
videos = []
cont=0
args.each do|a|
if(a.include? ".flv")
puts "parsing flv video: #{a}..."
executeFfmpeg("ffmpeg -i #{a} -r 1 -y #{a}")
videos << a
elsif(a.is_i?)
puts "creating image video with duration: #{a} seconds..."
newImageVideo="tmp#{cont}.flv"
executeFfmpeg("ffmpeg -loop_input -t #{a} -i logo.jpg -r 1 #{newImageVideo}")
videos << newImageVideo
cont=cont+1
end
end
executeMencoder(videos)
end
execute(ARGV)

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB