Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Presenting a fully automated DVD authoring rakefile

Reply
Thread Tools

Presenting a fully automated DVD authoring rakefile

 
 
Bira
Guest
Posts: n/a
 
      10-13-2006
As promised, here is the script I use to change a set of AVI files
into a DVD disc image. It uses Rake and rmovie along with a whole
bunch of Linux utilities, and doesn't require any aditional input from
the user beyond having the AVI files in the same directory as the
rakefile.

It goes through the following steps:

For each AVI file in the current directory:
- Use transcode to convert it into a M2V video file and an AC3 audio track.
- Use mplex to join these two files into a MPG file.

- Use dvdauthor to convert the MPGs to a DVD file structure.
- Use mkisofs to change the DVD file structure into a ISO image file,
ready for burning.
- Clean up by deleting everything except the AVI files, the ISO image
and the MPG files (which take the longest time to create, and are
useful if something goes wrong and I have to start over ).

It's probably too specific to be worth posting to Rubyforge or one of
its equivalents, so I'm sending it here in case someone else finds it
useful. There's probably a lot I can improve here, so I'd be thankful
to hear any suggestions or criticisms.

================================================== ===

require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rmovie'

OUTPUT_RATIO = 1.6



SOURCE_FILES = FileList['*.avi']
DESTINATION_FILES = SOURCE_FILES.gsub('avi','mpg')
CLEAN.include('*.xml','*.cfg','DVD')


def adjust_clip(x, y)

clip_size = -1* (((x.to_i / OUTPUT_RATIO) - y.to_i) / 2).abs
int_clip = clip_size.to_i
return int_clip if int_clip % 2 == 0

return int_clip - 1

end

def transcode(filename)
nome, extensao = filename.split('.')
movie = RMovie::Movie.new(filename)

clip_size = adjust_clip(movie.frame_width, movie.frame_height)

bit_rate = ( movie.bit_rate / 1000 ).ceil

ratio = movie.frame_width.to_f / movie.frame_height.to_f

if ratio == ( 4.0 / 3.0 )
aspect = 2
elsif ratio == ( 16.0 / 9.0 )
aspect = 3
end

sh <<-FIM
transcode -i "#{filename}" -y ffmpeg --export_prof dvd-ntsc
--export_asr #{aspect} --pre_clip=#{clip_size},#{clip_size} -w
#{bit_rate} -o #{nome} -D0 -b224 -N 0x2000 -s2 -m #{nome}.ac3 -J
modfps=clonetype=3 --export_fps 29.97
FIM
end

def mplex(basename)
nome = basename.split('.')[0]
sh "mplex -f 8 -o #{nome}.mpg #{nome}.m2v #{nome}.ac3"
end

def write_xml_header(xml)
xml.write <<-HEADER
<dvdauthor dest="DVD">
<vmgm />
<titleset>
<titles>
<pgc>
HEADER

end

def write_xml_footer(xml)
xml.write <<-FOOTER
</pgc>
</titles>
</titleset>
</dvdauthor>
FOOTER
end


rule '.mpg' => ['.avi'] do |t|
nome = t.name.split('.')[0]
transcode(t.prerequisites[0])
mplex( nome )
rm "#{nome}.m2v"
rm "#{nome}.ac3"
end

rule '.mpg' => ['.m2v', 'ac3'] do |t|
nome = t.name.split('.')[0]
mplex( nome )
rm "#{nome}.m2v"
rm "#{nome}.ac3"
end


file 'ffmpeg.cfg' do |t|
File.open(t.name, 'w') do |cfg|
cfg.write <<-FIM
[mpeg2video]
vrc_minrate=0
vrc_maxrate = 5000
vrc_buf_size = 1792
FIM
end
puts 'ffmpeg.cfg escrito'
end

file 'dvdauthor.xml' => DESTINATION_FILES do |t|
File.open(t.name, 'w') do |xml|
write_xml_header(xml)
DESTINATION_FILES.sort.each do |file|
xml.write <<-LINHA
<vob file="#{file}" />
LINHA
end
write_xml_footer(xml)
end
end


file 'DVD' => ['dvdauthor.xml'] do |t|
sh "dvdauthor -o #{t.name} -x #{t.prerequisites[0]}"
end


task 'dvd.iso' => ['DVD'] do |t|
sh "mkisofs -o #{t.name} -dvd-video #{t.prerequisites[0]}"
end


task :default =>['ffmpeg.cfg','dvd.iso', :clean]



================================================== =====



--
Bira
http://compexplicita.blogspot.com
http://sinfoniaferida.blogspot.com

 
Reply With Quote
 
 
 
 
Richard Conroy
Guest
Posts: n/a
 
      10-13-2006
On 10/13/06, Bira <(E-Mail Removed)> wrote:
> As promised, here is the script I use to change a set of AVI files
> into a DVD disc image. It uses Rake and rmovie along with a whole
> bunch of Linux utilities, and doesn't require any aditional input from
> the user beyond having the AVI files in the same directory as the
> rakefile.


Might be worth posting to http://www.doom9.org

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Presenting .doc, .ppt or .pdf on DVD player Trs80 DVD Video 2 01-24-2008 06:58 AM
Presenting pictures via DVD player on TV? trs80 DVD Video 9 04-09-2007 07:59 PM
rakefile help: rakefile calling a rakefile? John Gabriele Ruby 1 12-05-2006 08:04 PM
DVD Authoring program that treats each movie on a DVD as a serperate movie ? Son Of Sheep. DVD Video 0 07-10-2005 06:31 PM
Presenting photos on CD/DVD with transitions and sound? Agustin Digital Photography 1 05-20-2005 05:45 PM



Advertisments