From 241b41ef216f9e5833816d20298eb77fdb49cbc4 Mon Sep 17 00:00:00 2001 From: Antonio Gurgel Date: Sun, 19 Mar 2023 15:06:28 -0700 Subject: [PATCH] Add `--output` option. --- README.md | 2 +- bin/other-transcode | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b39c18..3fa3d66 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/other-transcode b/bin/other-transcode index d34311f..4b22cf9 100755 --- a/bin/other-transcode +++ b/bin/other-transcode @@ -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 @@ -333,6 +337,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`. def initialize @position = nil @duration = nil + @output = nil @debug = false @scan = false @detect = false @@ -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 @@ -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'