忘れるのと、PC引っ越ししたらソース無くしそうなんでQiitaにメモ。
[前準備]
・brewからをffmpegインストール
brew install ffmpeg
・gemでsystemuを入れておく
[手順]
・ISOファイルをマウントする
・マウントしたイメージの「VIDEO_TS」フォルダ内の「.VOB」ファイルを結合して1ファイルにする
・結合したファイルをffmpegにてmp4に変換する
・変換後、結合したファイルを削除する
・ISOファイルをアンマウントする
上記を、Rubyのバッチで行う。
(シェルで書くのがメンドイ。。。)
[ソース]
require 'systemu'
require 'find'
raise "no arg(iso file path...)" if ARGV.size < 1
mountNm = nil
outVOBPath = nil
begin
isoFile = ARGV[0]
ext = File.extname(isoFile)
raise "wrong extension " unless ext.upcase == ".ISO"
raise "not found argment file" unless File.exists? isoFile
mountNm = "/Volumes/#{File.basename(isoFile, ext)}"
puts "[[[#{mountNm}]]]"
status, stdout, stderr = systemu( "hdiutil mount #{isoFile}" )
unless File.exists?(mountNm)
msg = "unexpected mount name...#{mountNm}"
mountNm = nl
raise msg
end
puts "* iso file mounted:#{mountNm}"
video_dir = "#{mountNm}/VIDEO_TS"
unless File.exists?(video_dir)
raise "wrong format iso file(VIDEO_TS FOLDER not exists...)"
end
# VOBファイルの列挙([_0.VOB] は、メニューらしいので除外する)+ path接続
vob_list = Dir.entries(video_dir).select {|item| item =~ /\.VOB$/i && !(item =~ /\_0\.VOB$/)}.map {|item| "#{video_dir}/#{it\
em}"}
raise "VOB File not exists..." if vob_list.empty?
puts "* VOB files found."
outDir = File.dirname(isoFile)
outVOB = "#{Time.now.strftime("%Y%m%d%H%M%S")}.VOB"
outVOBPath = "#{outDir}/#{outVOB}"
concat_cmd = "cat #{vob_list.join(" ")} > #{outVOBPath}"
status, stdout, stderr = systemu(concat_cmd)
puts "@@@[\n#{[ status, stdout, stderr ]}\n]@@@"
# TODO error check
# TODO Start Time store...
# TODO execute convert mp4 command
# TODO result check and show result
# TODO show proccess time
rescue => e
raise e
ensure
# TODO Remove concat VOB file
# if outVOBPath && File.exists?(outVOBPath)
# File.delete outVOBPath
# end
if mountNm
system( "hdiutil unmount #{mountNm}" )
puts "exists:#{mountNm}:#{File.exists?(mountNm)}"
end
end
・・・作成中・・・