From 58db712b6a074dd6979b2deb5064e81336923244 Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Wed, 22 Aug 2018 16:46:41 +0300 Subject: [PATCH] Fix preview args and format --- src/encoder/encode.js | 11 ++++++++--- src/ffmpeg/index.js | 11 +++++++---- src/util/index.js | 26 +++++++++++++++++++------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/encoder/encode.js b/src/encoder/encode.js index 60db818..6dea673 100644 --- a/src/encoder/encode.js +++ b/src/encoder/encode.js @@ -17,7 +17,7 @@ import { BigProgress, } from "../theme"; import { - parseFrameRate, parseArgs, + getOpt, parseFrameRate, parseArgs, showSize, showBitrate, showTime, quoteArgs, } from "../util"; @@ -248,6 +248,7 @@ export default class extends React.PureComponent { const {preview, target} = this.state; const title = this.refs.title.getValue().trim(); const baseArgs = parseArgs(this.props.rawArgs); + const outfmt = getOpt(baseArgs, "-f", "webm", {last: true}); const frameParser = this.createFrameParser(); const startTime = this.now(); @@ -287,7 +288,7 @@ export default class extends React.PureComponent { inpath, time, vcodec, width, height, sar, strfps, - outpath, + outfmt, outpath, })); }).then(() => { const inpath = this.tmpTestName; @@ -297,7 +298,11 @@ export default class extends React.PureComponent { FFmpeg.writeConcat({inpath, prevpath, outpath}); outpath = target; handleLog(this.sep()); - return run(FFmpeg.getConcatArgs({inpath, listpath, fps, outpath})); + return run(FFmpeg.getConcatArgs({ + inpath, listpath, + fps, + outfmt, outpath, + })); }); } videop.then(() => { diff --git a/src/ffmpeg/index.js b/src/ffmpeg/index.js index a45515d..0864a8e 100644 --- a/src/ffmpeg/index.js +++ b/src/ffmpeg/index.js @@ -360,7 +360,8 @@ export default makeRunner("ffmpeg", { } return args; }, - getPreviewArgs({inpath, time, vcodec, width, height, sar, strfps, outpath}) { + getPreviewArgs({inpath, time, vcodec, width, height, sar, strfps, + outfmt, outpath}) { width = sar > 1 ? Math.round(width * sar) : width; height = sar < 1 ? Math.round(height / sar) : height; const color = [ @@ -403,7 +404,8 @@ export default makeRunner("ffmpeg", { "-an", "-sn", "-dn", "-frames:v", "1", "-pix_fmt", "yuv420p", - "-f", "webm", this._escapeFilename(outpath) + "-strict", "experimental", + "-f", outfmt, this._escapeFilename(outpath) ); return args; }, @@ -413,14 +415,15 @@ export default makeRunner("ffmpeg", { this._escapeConcatArg(inpath), ].join("\n")); }, - getConcatArgs({inpath, listpath, fps, outpath}) { + getConcatArgs({inpath, listpath, fps, outfmt, outpath}) { const args = this._getCommonArgs(); args.push( "-f", "concat", "-safe", "0", "-i", this._escapeFilename(listpath), "-itsoffset", ceilFixed(1 / fps, 3), "-i", this._escapeFilename(inpath), "-map", "0:v:0", "-map", "1:a:0?", "-c", "copy", - "-f", "webm", this._escapeFilename(outpath) + "-strict", "experimental", + "-f", outfmt, this._escapeFilename(outpath) ); return args; }, diff --git a/src/util/index.js b/src/util/index.js index bdbf246..c71f3b6 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -154,15 +154,27 @@ export function quoteArgs(args) { }).join(" "); } -export function getOpt(arr, key, def) { +export function getOpt(arr, key, def, opts = {}) { + let res = null; let prev = false; - const res = arr.find(v => { - if (prev) { - return true; - } else if (v === key) { - prev = true; + if (opts.last) { + for (let i = arr.length; i >= 0; i--) { + if (arr[i] === key) { + if (i < arr.length - 1) { + res = arr[i + 1]; + } + break; + } } - }); + } else { + res = arr.find(v => { + if (prev) { + return true; + } else if (v === key) { + prev = true; + } + }); + } return res == null ? def : res; }