Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse HandBrakeCLI JSON output (Fixes #234) #333

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions bin/convert-video
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HERE

opts.on '--ac3-encoder ARG' do |arg|
@ac3_encoder = case arg
when 'ac3', 'eac3'
when /ac3/i, /eac3/i
arg
else
fail UsageError, "invalid AC-3 audio encoder: #{arg}"
Expand All @@ -87,7 +87,6 @@ HERE
Console.debug media.info.inspect
output = resolve_output(media)
fail "no compatible video track: #{arg}" unless media.info[:h264] or media.info[:hevc]
fail "no video stream: #{arg}" unless media.info.has_key? :stream

if media.info[:mkv]
convert_to_mp4(media, output)
Expand Down Expand Up @@ -130,7 +129,7 @@ HERE
if @double and media.info[:audio][1][:channels] > 2.0
if track_order.size > 1 and
media.info[:audio][1][:language] == media.info[:audio][2][:language] and
media.info[:audio][2][:format] =~ /^AAC/ and
media.info[:audio][2][:format] =~ /^AAC/i and
media.info[:audio][2][:channels] <= 2.0
first = track_order[0]
track_order[0] = track_order[1]
Expand Down Expand Up @@ -161,7 +160,7 @@ HERE
"-b:a:#{stream}", '640k'
])
elsif media.info[:audio][track][:channels] <= 2.0 and
not media.info[:audio][track][:format] =~ /^AAC/ and
not media.info[:audio][track][:format] =~ /^AAC/i and
not ac3_format?(media.info[:audio][track][:format])
copy_options.concat([
"-ac:a:#{stream}", '2',
Expand All @@ -188,10 +187,10 @@ HERE
break unless media.info[:subtitle][track].has_key? :stream

subtitle_encoder = case media.info[:subtitle][track][:format]
when 'Text'
when /Text/i
'mov_text'
when 'Bitmap'
if media.info[:subtitle][track][:encoding] == 'VOBSUB'
when /Bitmap/i
if media.info[:subtitle][track][:encoding] =~ /VOBSUB/i
'copy'
else
nil
Expand Down Expand Up @@ -249,8 +248,8 @@ HERE
end

def ac3_format?(track_format)
if (@ac3_encoder == 'ac3' and track_format == 'AC3') or
(@ac3_encoder == 'eac3' and track_format =~ /^(?:E-)?AC3$/)
if (@ac3_encoder == 'ac3' and track_format =~ /AC3/i) or
(@ac3_encoder == 'eac3' and track_format =~ /^(?:E-)?AC3$/i)
true
else
false
Expand Down Expand Up @@ -294,7 +293,7 @@ HERE
if @double and
track_order.size > 1 and
media.info[:audio][1][:language] == media.info[:audio][2][:language] and
media.info[:audio][1][:format] =~ /^AAC/ and
media.info[:audio][1][:format] =~ /^AAC/i and
media.info[:audio][1][:channels] <= 2.0 and
media.info[:audio][2][:channels] > 2.0
first = track_order[0]
Expand Down Expand Up @@ -323,10 +322,10 @@ HERE

track_order.each do |track|
subtitle_encoder = case media.info[:subtitle][track][:format]
when 'Text'
when /Text/i
'text'
when 'Bitmap'
if media.info[:subtitle][track][:encoding] == 'VOBSUB'
when /Bitmap/i
if media.info[:subtitle][track][:encoding] =~ /VOBSUB/i
'dvdsub'
else
nil
Expand Down
12 changes: 6 additions & 6 deletions bin/transcode-video
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,10 @@ HERE

if copy or
(@surround_format == 'ac3' and
((@ac3_encoder == 'ac3' and info[:format] == 'AC3') or
(@ac3_encoder == 'eac3' and info[:format] =~ /^(?:E-)?AC3$/)) and
((@ac3_encoder == 'ac3' and info[:format] =~ /AC3/i) or
(@ac3_encoder == 'eac3' and info[:format] =~ /^(?:E-)?AC3$/i)) and
bitrate <= @pass_ac3_bitrate) or
(@surround_format == 'aac' and info[:format] =~ /^AAC/)
(@surround_format == 'aac' and info[:format] =~ /^AAC/i)
encoders << 'copy'
bitrates << ''
mixdowns << ''
Expand All @@ -1174,9 +1174,9 @@ HERE
add_stereo = ->(info, copy) do
if copy or
(info[:channels] <= 2.0 and
((@stereo_format == 'aac' and info[:format] =~ /^AAC/) or
(((@ac3_encoder == 'ac3' and info[:format] == 'AC3') or
(@ac3_encoder == 'eac3' and info[:format] =~ /^(?:E-)?AC3$/)) and
((@stereo_format == 'aac' and info[:format] =~ /^AAC/i) or
(((@ac3_encoder == 'ac3' and info[:format] =~ /AC3/i) or
(@ac3_encoder == 'eac3' and info[:format] =~ /^(?:E-)?AC3$/i)) and
(@keep_ac3_stereo or @stereo_format == 'ac3'))))
encoders << 'copy'
bitrates << ''
Expand Down
Loading