Module: MediaInfoParser

Defined in:
lib/media_info_parser.rb

Class Method Summary collapse

Class Method Details

.parse_with_convert_command(media_info, filename) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/media_info_parser.rb', line 2

def self.parse_with_convert_command media_info, filename
  video = audio = nil
  media_info.split("Track ID").each{ |section|
    section =~ /:(\W+)(\d+)/
    id = $2
    section =~  /Stream ID:   (\S+)/ # like V_MPEG-2
    stream_type = $1
    if stream_type
      raise unless id
      if section =~ /Frame rate/ && !video
        section =~ /Frame rate: ([\d\.]+)/
        fps = $1
        raise unless fps
        raise unless section =~ /lang: eng/ # expect...
        video = "#{stream_type}, \"#{filename}\", fps=#{fps}, track=#{id}, lang=eng"
      elsif section =~ /Channels:/ && !audio
        raise unless section =~ /lang: eng/ # hope english audio track comes first...
        # A_AC3, "G:\Video\Sintel_NTSC\title01.mkv", track=2, lang=eng
        audio = "#{stream_type}, \"#{filename}\", track=#{id}, lang=eng"
      end
    end
  }
  raise unless video && audio
  return "MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbr  --vbv-len=500\n#{video}\n#{audio}"
end