Skip to content

Commit

Permalink
Fix preview args and format
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagami committed Aug 22, 2018
1 parent 23c708c commit 58db712
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
11 changes: 8 additions & 3 deletions src/encoder/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
BigProgress,
} from "../theme";
import {
parseFrameRate, parseArgs,
getOpt, parseFrameRate, parseArgs,
showSize, showBitrate, showTime, quoteArgs,
} from "../util";

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -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(() => {
Expand Down
11 changes: 7 additions & 4 deletions src/ffmpeg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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;
},
Expand All @@ -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;
},
Expand Down
26 changes: 19 additions & 7 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 58db712

Please sign in to comment.