This commit is contained in:
+36
-2
@@ -14,6 +14,7 @@ import {
|
||||
generateOutputCommand,
|
||||
getAvailableCodecs,
|
||||
getLengthMicroseconds,
|
||||
getPixelFormats,
|
||||
playFile,
|
||||
videoFileExtensions,
|
||||
type CodecInfo,
|
||||
@@ -60,6 +61,8 @@ function App() {
|
||||
const [outputopts, setOutputopts] = createSignal("");
|
||||
const [audioCodec, setAudioCodec] = createSignal("copy");
|
||||
const [audioEncoder, setAudioEncoder] = createSignal("");
|
||||
const [pixelFormatList, setPixelFormatList] = createSignal([] as string[]);
|
||||
const [pixelFormat, setPixelFormat] = createSignal("");
|
||||
const logs: { [id: number]: string[] } = {};
|
||||
let supportedCodecs: CodecList = { vcodecs: [], acodecs: [] };
|
||||
let ffmpegParams: FFmpegParams = {
|
||||
@@ -139,6 +142,8 @@ function App() {
|
||||
ffmpegParams.encoder = firstCodec.encoders[0];
|
||||
setSelectedCodec(firstCodec);
|
||||
setSelectedEncoder(firstCodec.encoders[0]);
|
||||
|
||||
setPixelFormatList(await getPixelFormats());
|
||||
});
|
||||
|
||||
onCleanup(() => {
|
||||
@@ -231,7 +236,7 @@ function App() {
|
||||
|
||||
function getAudioEncoders() {
|
||||
const codec = audioCodec();
|
||||
const encoders = audioCodecList().find(
|
||||
let encoders = audioCodecList().find(
|
||||
(v) => v.shortName === codec,
|
||||
)?.encoders;
|
||||
|
||||
@@ -239,6 +244,10 @@ function App() {
|
||||
setAudioEncoder(encoders[0]);
|
||||
}
|
||||
|
||||
if (encoders instanceof Array && encoders.length === 0) {
|
||||
encoders = undefined;
|
||||
}
|
||||
|
||||
return encoders;
|
||||
}
|
||||
|
||||
@@ -265,10 +274,18 @@ function App() {
|
||||
encoder = undefined;
|
||||
}
|
||||
|
||||
let acodec = audioEncoder();
|
||||
|
||||
if (acodec === "") {
|
||||
acodec = audioCodec();
|
||||
}
|
||||
|
||||
const pixFmt = pixelFormat();
|
||||
|
||||
ffmpegParams = {
|
||||
vcodec: selectedCodec()?.shortName ?? "",
|
||||
encoder,
|
||||
acodec: audioCodec(),
|
||||
acodec,
|
||||
abitrate: ffmpegParams.abitrate,
|
||||
crf: ffmpegParams.crf,
|
||||
doNotUseAn: ffmpegParams.doNotUseAn,
|
||||
@@ -283,6 +300,7 @@ function App() {
|
||||
input: inputopts(),
|
||||
output: outputopts(),
|
||||
},
|
||||
pixelFormat: pixFmt === "" ? undefined : pixFmt,
|
||||
};
|
||||
|
||||
setOutputCommand(generateOutputCommand(ffmpegParams));
|
||||
@@ -542,6 +560,22 @@ function App() {
|
||||
</For>
|
||||
</select>
|
||||
</Show>
|
||||
<label for="pixelFormat">Pixel Format</label>
|
||||
<select
|
||||
name="pixelFormat"
|
||||
id="pixelFormat"
|
||||
class="k-dropdown"
|
||||
title="This option is here for the people who knows what they're doing. Not all encoders will support every pixel format."
|
||||
value={pixelFormat()}
|
||||
oninput={(e) => setPixelFormat(e.target.value)}
|
||||
>
|
||||
<option value="">Same as source</option>
|
||||
<For each={pixelFormatList()}>
|
||||
{(item, _) => (
|
||||
<option value={item}>{item}</option>
|
||||
)}
|
||||
</For>
|
||||
</select>
|
||||
</form>
|
||||
<Switch fallback={<div></div>}>
|
||||
<Match
|
||||
|
||||
@@ -74,6 +74,28 @@ export async function getAvailableCodecs(): Promise<CodecList> {
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPixelFormats(): Promise<string[]> {
|
||||
const seperator = "-----";
|
||||
const result = await Neutralino.os.execCommand("ffmpeg -pix_fmts");
|
||||
const rawFormatList = result.stdOut
|
||||
.substring(result.stdOut.indexOf(seperator) + seperator.length)
|
||||
.split("\n");
|
||||
let outputFormats = [];
|
||||
|
||||
for (let format of rawFormatList) {
|
||||
format = format.trim();
|
||||
const flags = format.substring(0, 5);
|
||||
|
||||
if (flags[1] !== "O") continue;
|
||||
|
||||
const parts = format.substring(6).split(/ +/);
|
||||
|
||||
outputFormats.push(parts[0]);
|
||||
}
|
||||
|
||||
return outputFormats;
|
||||
}
|
||||
|
||||
export function playFile(path: string) {
|
||||
Neutralino.os.execCommand(`ffplay "${path}"`);
|
||||
}
|
||||
@@ -114,6 +136,7 @@ export interface FFmpegParams {
|
||||
faststart?: boolean;
|
||||
doNotUseAn?: boolean;
|
||||
speed?: number;
|
||||
pixelFormat?: string;
|
||||
/**
|
||||
* Extra parameters defined by users
|
||||
*/
|
||||
@@ -156,8 +179,17 @@ export function generateOutputCommand(params: FFmpegParams) {
|
||||
globalopts += " " + params.useropts.global;
|
||||
}
|
||||
|
||||
if (params.pixelFormat) {
|
||||
if (params.outputopts === undefined) {
|
||||
params.outputopts = {};
|
||||
}
|
||||
|
||||
params.outputopts = {
|
||||
"pix_fmt": params.pixelFormat
|
||||
};
|
||||
}
|
||||
|
||||
if (params.outputopts !== undefined) {
|
||||
console.log(params.outputopts);
|
||||
for (const key of Object.keys(params.outputopts)) {
|
||||
outputopts += ` -${key} ${params.outputopts[key]}`.trimEnd();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user