Class: Dvdvrconv::Dvdvr
- Inherits:
-
Object
- Object
- Dvdvrconv::Dvdvr
- Defined in:
- lib/dvdvrconv/dvdvr.rb
Instance Attribute Summary collapse
-
#vrdisc ⇒ Object
Returns the value of attribute vrdisc.
Instance Method Summary collapse
-
#adjust_title ⇒ Object
Add sequence number to the duplicate title name.
-
#change_to_title_name ⇒ Object
Change the file name to the title name.
-
#concat_titles(concat_list) ⇒ Object
Concatenate Split Titles.
-
#customize_title(base_dst_name, number_list = []) ⇒ Object
customize the title of vob files.
- #debug_view_vrdisc ⇒ Object
-
#ffmeg_normal_cmd(file_name) ⇒ Object
File convert command, vob to mp4 for FFmpeg.
-
#ffmpeg_qsv_cmd(file_name) ⇒ Object
File convert command, vob to mp4 for FFmpeg.
-
#initialize ⇒ Dvdvr
constructor
A new instance of Dvdvr.
-
#make_concat_list ⇒ Object
Make a list of file names to concatenate.
-
#read_info ⇒ Object
Read video information from dvd-ram discs in dvd-vr format.
-
#rename_vob ⇒ Object
Rename vob file to a customized title name.
-
#str_concat_cmd(file_name, base_name) ⇒ Object
Make a concatenation command string for FFmpeg.
-
#str_convert_cmd(file_name) ⇒ Object
File convert command, vob to mp4 for FFmpeg.
-
#str_dvdvr_cmd ⇒ Object
Read VRO file from dvd-ram disc in dvd-vr format, and output vob files.
-
#view_info ⇒ Object
View video information from dvd-ram discs in dvd-vr format.
-
#vob2mp4 ⇒ Object
convert vob to mp4.
- #vrdisc_status ⇒ Object
-
#vro2vob ⇒ Object
Read VRO file from dvd-ram disc in dvd-vr format, and output vob files.
Constructor Details
#initialize ⇒ Dvdvr
Returns a new instance of Dvdvr.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dvdvrconv/dvdvr.rb', line 44 def initialize @vrdisc = Vrdisc.new(nil) if RUBY_PLATFORM =~ /mswin(?!ce)|mingw|cygwin/ @vrdisc.opts_ifo = Dvdvrconv::WIN_DRV_IFO @vrdisc.opts_vro = Dvdvrconv::WIN_DRV_VRO @vrdisc.cmd = Dvdvrconv::WIN_DRV_CMD else @vrdisc.opts_ifo = Dvdvrconv::DRV_IFO @vrdisc.opts_vro = Dvdvrconv::DRV_VRO @vrdisc.cmd = Dvdvrconv::DRV_CMD end @vrdisc.default_opts_ifo = @vrdisc.opts_ifo @vrdisc.default_opts_vro = @vrdisc.opts_vro @vrdisc.default_cmd = @vrdisc.cmd @vrdisc.concat_mode = Dvdvrconv::DEFAULT_CONCAT_MODE @vrdisc.hardware_encode = Dvdvrconv::DEFAULT_HARDWARE_ENCODE @vrdisc.global_quality = Dvdvrconv::DEFAULT_GLOBAL_QUALITY end |
Instance Attribute Details
#vrdisc ⇒ Object
Returns the value of attribute vrdisc.
42 43 44 |
# File 'lib/dvdvrconv/dvdvr.rb', line 42 def vrdisc @vrdisc end |
Instance Method Details
#adjust_title ⇒ Object
Add sequence number to the duplicate title name. Replace white space in the title with underscore.
required value:
@vrdisc.title
Output values:
=> @vrdisc.duplicate_name
=> @vrdisc.output_title
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/dvdvrconv/dvdvr.rb', line 155 def adjust_title output_title = [] duplicate_names = [] dup_counter = 0 # Extract duplicate names from title. dup = @vrdisc.title.select { |x| @vrdisc.title.count(x) > 1 } @vrdisc.title.each_index do |idx| # Replace white space in the title with underscore. new_name = @vrdisc.title[idx][0].gsub(/\s/, "_") # Add sequential numbers to duplicate name. if dup.include?(@vrdisc.title[idx]) dup_counter += 1 output_title << format('%s_%02d', new_name, dup_counter) duplicate_names << new_name else output_title << format('%s', new_name) end dup_counter = 0 if dup_counter == @vrdisc.title.count(@vrdisc.title[idx]) end @vrdisc.duplicate_name = duplicate_names.select do |x| duplicate_names.count(x) > 1 end.uniq @vrdisc.output_title = output_title end |
#change_to_title_name ⇒ Object
Change the file name to the title name
required value:
@vrdisc.title
Output values:
=> @vrdisc.vob_titles
202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/dvdvrconv/dvdvr.rb', line 202 def change_to_title_name vob_titles = [] @vrdisc.title.size.times do |x| src = format('%s#%03d', Dvdvrconv::BASE_NAME, x + 1) + '.vob' dst = @vrdisc.output_title[x] + '.vob' vob_titles << [src, dst] end @vrdisc.vob_titles = vob_titles end |
#concat_titles(concat_list) ⇒ Object
Concatenate Split Titles. This method uses FFmpeg's media file concatenation feature.
required Argument:
concat_list
concat_list is Array. Includes file_name, contents, base_name.
concat_list = [[file_name, contents, base_name], [file_name, contents, base_name]. .... ]
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/dvdvrconv/dvdvr.rb', line 337 def concat_titles(concat_list) puts '----- Concatenate Split Titles -----' concat_list.each do |list| file_name, contents, base_name = list File.write(file_name, contents) puts "concat list= #{file_name}" cmd = str_concat_cmd(file_name, base_name) puts '----- concat vob files -----' puts "run cmd:\n #{cmd.join(' ')}" system(*cmd) begin File.delete(file_name) rescue p $! end end end |
#customize_title(base_dst_name, number_list = []) ⇒ Object
customize the title of vob files.
If specify individual file names. Write "base_dst_name" as an Array.
base_dst_name = ["name_one", "name_two"]
number_list = []
=> ["name_one", "name_two"]
If add a sequence number to the file name. Write "base_dst_name" as String.
base_dst_name = "output_name_"
number_list = []
=> ["output_name_01", "output_name_02", ...]
If specify sequence numbers individually. Write "base_dst_name" as String and Write "number_list" as an Array.
base_dst_name = "output_name_"
number_list = [12, 13, 14, 15]
=> ["output_name_12", "output_name_13", "output_name_14", "output_name_15"]
required Argument, value:
base_dst_name, number_list,
@vrdisc.title
Output values:
=> @vrdisc.vob_titles
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/dvdvrconv/dvdvr.rb', line 242 def customize_title(base_dst_name, number_list = []) vob_titles = [] if @vrdisc.concat_mode == true titels = @vrdisc.title.uniq.flatten else titels = @vrdisc.output_title end titels.each_with_index do |title, idx| src = title.gsub(/\s/, '_') + '.vob' case base_dst_name when Array dst_name = base_dst_name[idx] when String if number_list.size.zero? dst_name = base_dst_name + format('_%02d', idx + 1) else case number_list[idx] when Numeric dst_name = base_dst_name + format('_%02d', number_list[idx]) when String dst_name = base_dst_name + format('_%s', number_list[idx]) end end end dst = dst_name + '.vob' vob_titles << [src, dst] end @vrdisc.vob_titles = vob_titles end |
#debug_view_vrdisc ⇒ Object
389 390 391 392 393 |
# File 'lib/dvdvrconv/dvdvr.rb', line 389 def debug_view_vrdisc @vrdisc.members.each do |member| puts "#{member} => #{@vrdisc[member]}" end end |
#ffmeg_normal_cmd(file_name) ⇒ Object
File convert command, vob to mp4 for FFmpeg.
- Change the aspect ratio to 16:9.
- Delete a closed caption.
78 79 80 |
# File 'lib/dvdvrconv/dvdvr.rb', line 78 def ffmeg_normal_cmd(file_name) Shellwords.shellsplit(%(ffmpeg -i "#{file_name}.vob" -filter:v "crop=704:474:0:0" -vcodec libx264 -b:v 500k -aspect 16:9 -acodec copy -bsf:v "filter_units=remove_types=6" "#{file_name}.mp4")) end |
#ffmpeg_qsv_cmd(file_name) ⇒ Object
File convert command, vob to mp4 for FFmpeg.
- FFmpeg with QSV(Intel Quick Sync Video)
- Change the aspect ratio to 16:9.
- Delete a closed caption.
86 87 88 |
# File 'lib/dvdvrconv/dvdvr.rb', line 86 def ffmpeg_qsv_cmd(file_name) Shellwords.shellsplit(%(ffmpeg -hwaccel qsv -hwaccel_output_format qsv -i "#{file_name}.vob" -filter:v "crop=704:474:0:0" -c:v h264_qsv -global_quality "#{@vrdisc.global_quality}" -look_ahead 1 -aspect 16:9 -acodec copy -bsf:v "filter_units=remove_types=6" "#{file_name}.mp4")) end |
#make_concat_list ⇒ Object
Make a list of file names to concatenate.
required values:
@vrdisc.duplicate_name, @vrdisc.output_title
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/dvdvrconv/dvdvr.rb', line 305 def make_concat_list concat_list = [] @vrdisc.duplicate_name.each do |base_name| contents = '' file_name = "concat_#{base_name}.txt" names = @vrdisc.output_title.select { |x| x.match(/#{base_name}_\d\d/) } names.each do |line| escaped_line = "#{line}.vob".gsub("'") {"'\\''"} contents += "file '#{escaped_line}'\n" end concat_list << [file_name, contents, base_name] end concat_list end |
#read_info ⇒ Object
Read video information from dvd-ram discs in dvd-vr format.
required values:
@vrdisc.cmd, @vrdisc.opts_ifo
Get values of the video information:
=> @vrdisc.header
=> @vrdisc.num
=> @vrdisc.title
=> @vrdisc.date
=> @vrdisc.size
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dvdvrconv/dvdvr.rb', line 113 def read_info out, err, status = Open3.capture3(@vrdisc.cmd, @vrdisc.opts_ifo) puts "File read error => #{err}" unless status.success? @vrdisc.header = out.scan(/^(.*?)Number/m) # Sets the captured information to @vrdisc. %w[num title date size].each do |item| str = format("%-5s", item) + ":" @vrdisc[item] = out.scan(/#{str}\s(.*?)$/) end out end |
#rename_vob ⇒ Object
Rename vob file to a customized title name.
required value:
@vrdisc.vob_titles
285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/dvdvrconv/dvdvr.rb', line 285 def rename_vob puts '----- output vob file -----' @vrdisc.vob_titles.each do |file_title| src, dst = file_title if File.exist?("#{dst}") puts "Skip => file #{dst} is exist." else File.rename(src, dst) puts " file name: #{dst}" end end end |
#str_concat_cmd(file_name, base_name) ⇒ Object
Make a concatenation command string for FFmpeg.
71 72 73 |
# File 'lib/dvdvrconv/dvdvr.rb', line 71 def str_concat_cmd(file_name, base_name) Shellwords.shellsplit(%(ffmpeg -f concat -safe 0 -i "#{file_name}" -c copy "#{base_name}.vob")) end |
#str_convert_cmd(file_name) ⇒ Object
File convert command, vob to mp4 for FFmpeg.
91 92 93 94 95 96 97 98 99 |
# File 'lib/dvdvrconv/dvdvr.rb', line 91 def str_convert_cmd(file_name) if @vrdisc.hardware_encode == 'qsv' ffmpeg_qsv_cmd(file_name) elsif @vrdisc.hardware_encode == 'normal' ffmeg_normal_cmd(file_name) else ffmeg_normal_cmd(file_name) end end |
#str_dvdvr_cmd ⇒ Object
Read VRO file from dvd-ram disc in dvd-vr format, and output vob files.
66 67 68 |
# File 'lib/dvdvrconv/dvdvr.rb', line 66 def str_dvdvr_cmd Shellwords.shellsplit(%("#{@vrdisc.cmd}" --name="#{Dvdvrconv::BASE_NAME}" "#{@vrdisc.opts_ifo}" "#{@vrdisc.opts_vro}")) end |
#view_info ⇒ Object
View video information from dvd-ram discs in dvd-vr format.
required values:
@vrdisc.header, @vrdisc.num, @vrdisc.title,
@vrdisc.date, @vrdisc.size
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/dvdvrconv/dvdvr.rb', line 133 def view_info puts '----- view dvd-vr info -----' puts @vrdisc.header [@vrdisc.num, @vrdisc.title, @vrdisc.date, @vrdisc.size].transpose.each do |x| %w[num title date size].each_with_index do |item, idx| line = format('%-5s', item) + ": #{x.flatten[idx]}\n" puts line end puts '-' end end |
#vob2mp4 ⇒ Object
convert vob to mp4.
required Values:
@vrdisc.vob_titles
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/dvdvrconv/dvdvr.rb', line 370 def vob2mp4 files = [] @vrdisc.vob_titles.each do |vob_title| files << vob_title[1].gsub(/.vob/, '') end files.each do |file_name| if File.exist?("#{file_name}.mp4") puts "Skip => file #{file_name}.mp4 is exist." else cmd = str_convert_cmd(file_name) puts "----- convert #{file_name}.vob to mp4 file -----" puts "run cmd:\n #{cmd.join(' ')}" system(*cmd) end end end |
#vrdisc_status ⇒ Object
357 358 359 360 361 362 363 |
# File 'lib/dvdvrconv/dvdvr.rb', line 357 def vrdisc_status puts "\n< < < < < @vrdisc status > > > > >" %w[num title output_title duplicate_name vob_titles concat_mode hardware_encode global_quality].each do |item| puts "#{item}=> #{@vrdisc[item]}" end puts "< < < < < @vrdisc status > > > > >\n" end |
#vro2vob ⇒ Object
Read VRO file from dvd-ram disc in dvd-vr format, and output vob files.
186 187 188 189 190 191 192 |
# File 'lib/dvdvrconv/dvdvr.rb', line 186 def vro2vob cmd = str_dvdvr_cmd puts '----- convert file VRO to VOB -----' puts "> cmd:\n #{cmd.join(' ')}" system(*cmd) puts '' end |