Skip to content

Add --output option. #182

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Or this on Linux and macOS:

other-transcode /Rips/Movie.mkv

On completion that command creates two files in the current working directory:
On completion that command creates two files in the current working directory (unless you set a different path with `--output`):

Movie.mkv
Movie.mkv.log
Expand Down
39 changes: 38 additions & 1 deletion bin/other-transcode
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Input options:
def usage3
<<-HERE
Output options:
--output FILENAME|DIRECTORY
set output path and filename, or just path
(default: input filename with output format extension
in current working directory)
--debug increase diagnostic information
--scan print media information and exit
--preview-crop show commands to preview detected video crop and exit
Expand Down Expand Up @@ -333,6 +337,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
def initialize
@position = nil
@duration = nil
@output = nil
@debug = false
@scan = false
@detect = false
Expand Down Expand Up @@ -468,6 +473,21 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
@duration = resolve_time(arg)
end

opts.on '--output ARG' do |arg|
unless File.directory? arg
@format = case File.extname(arg)
when '.mkv'
:mkv # COMBAK: Already the default. Chop this block?
when '.mp4'
:mp4
else
fail UsageError, "unsupported filename extension: #{arg}"
end
end

@output = arg
end

opts.on '--debug' do
@debug = true
end
Expand Down Expand Up @@ -1161,11 +1181,28 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
$CHILD_STATUS.exitstatus == 0
end

def resolve_output(path)
output = File.basename(path, '.*') + '.' + @format.to_s

unless @output.nil?
abs_path = File.absolute_path(@output)

if File.directory? @output # COMBAK: or abs_path?
output = abs_path + File::SEPARATOR + output
else
output = abs_path
end
end

fail "output file exists: #{output}" if File.exist? output
output
end

def process_input(path)
seconds = Time.now.tv_sec

unless @scan or @detect
output_path = File.basename(path, '.*') + '.' + @format.to_s
output_path = resolve_output(path)
fail_or_warn "output file already exists: #{output_path}" if File.exist? output_path

log_path = output_path + '.log'
Expand Down