mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-01 02:41:30 +08:00
FFMPEG Binary support contain and cover generate method
This commit is contained in:
@@ -34,7 +34,7 @@ RUN cd ~ && \
|
||||
--disable-parsers --enable-parser=h264,png,gif \
|
||||
--disable-bsfs --enable-bsf=dts2pts,null \
|
||||
--disable-protocols --enable-protocol=async,concat,concatf,data,fd,file,md5,pipe,subfile \
|
||||
--disable-devices --disable-filters --enable-filter=scale && \
|
||||
--disable-devices --disable-filters --enable-filter=crop,pad,scale && \
|
||||
make -j$(grep -c ^processor /proc/cpuinfo) && make install && \
|
||||
cd ~ && rm -rf FFmpeg-n7.0.1 ffmpeg.tar.gz
|
||||
|
||||
|
||||
@@ -111,12 +111,13 @@ export const handler: Handlers = {
|
||||
return Response.redirect(`${get_host(req)}/api/file/${f.id}`);
|
||||
}
|
||||
}
|
||||
if (method === ThumbnailMethod.FFMPEG_BINARY) {
|
||||
cfg.method = ThumbnailGenMethod.Unknown;
|
||||
}
|
||||
const output = generate_filename(b, f, cfg);
|
||||
if (!(await exists(output))) {
|
||||
if (method === ThumbnailMethod.FFMPEG_BINARY) {
|
||||
cfg.input = {
|
||||
width: Number(f.width),
|
||||
height: Number(f.height),
|
||||
};
|
||||
const re = await fb_generate_thumbnail(
|
||||
m.cfg.ffmpeg_path,
|
||||
f.path,
|
||||
|
||||
@@ -23,6 +23,7 @@ export type ThumbnailConfig = {
|
||||
quality: number;
|
||||
method: ThumbnailGenMethod;
|
||||
align: ThumbnailAlign;
|
||||
input?: { width: number; height: number };
|
||||
};
|
||||
|
||||
export function gen_thumbnail_config_params(cfg: ThumbnailConfig) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ThumbnailConfig } from "./base.ts";
|
||||
import { ThumbnailAlign } from "./base.ts";
|
||||
import { type ThumbnailConfig, ThumbnailGenMethod } from "./base.ts";
|
||||
|
||||
export async function check_ffmpeg_binary(p: string) {
|
||||
const cmd = new Deno.Command(p, {
|
||||
@@ -45,18 +46,59 @@ export async function fb_generate_thumbnail(
|
||||
o: string,
|
||||
cfg: ThumbnailConfig,
|
||||
) {
|
||||
let add = "";
|
||||
if (cfg.method == ThumbnailGenMethod.Cover) {
|
||||
const size = cfg.input ?? await fb_get_size(i);
|
||||
if (!size) return false;
|
||||
const twidth = Math.floor(size.width * cfg.height / size.height);
|
||||
const frwidth = Math.floor(twidth > cfg.width ? twidth : cfg.width);
|
||||
const frheight = Math.floor(
|
||||
twidth > cfg.width
|
||||
? cfg.height
|
||||
: size.height * cfg.width / size.width,
|
||||
);
|
||||
const xy = cfg.align == ThumbnailAlign.Center
|
||||
? ""
|
||||
: cfg.align == ThumbnailAlign.Left
|
||||
? ":x=0:y=0"
|
||||
: `:x=${frwidth - cfg.width}:y=${frheight - cfg.height}`;
|
||||
add =
|
||||
`scale=${frwidth}x${frheight},crop=${cfg.width}:${cfg.height}${xy}`;
|
||||
} else if (cfg.method == ThumbnailGenMethod.Contain) {
|
||||
const size = cfg.input ?? await fb_get_size(i);
|
||||
if (!size) return false;
|
||||
const twidth = Math.floor(size.width * cfg.height / size.height);
|
||||
const frwidth = Math.floor(twidth > cfg.width ? cfg.width : twidth);
|
||||
const frheight = Math.floor(
|
||||
twidth > cfg.width
|
||||
? size.height * cfg.width / size.width
|
||||
: cfg.height,
|
||||
);
|
||||
const xy = cfg.align == ThumbnailAlign.Center
|
||||
? `:x=${Math.floor((cfg.width - frwidth) / 2)}:y=${
|
||||
Math.floor((cfg.height - frheight) / 2)
|
||||
}`
|
||||
: cfg.align == ThumbnailAlign.Left
|
||||
? ""
|
||||
: `:x=${cfg.width - frwidth}:y=${cfg.height - frheight}`;
|
||||
add =
|
||||
`scale=${frwidth}x${frheight},pad=${cfg.width}:${cfg.height}${xy}:color=white`;
|
||||
} else {
|
||||
add = `scale=${cfg.width}:${cfg.height}`;
|
||||
}
|
||||
const args = [
|
||||
"-n",
|
||||
"-i",
|
||||
i,
|
||||
"-vf",
|
||||
`scale=${cfg.width}:${cfg.height}`,
|
||||
add,
|
||||
"-qmin",
|
||||
`${cfg.quality}`,
|
||||
"-qmax",
|
||||
`${cfg.quality}`,
|
||||
o,
|
||||
];
|
||||
console.log(args);
|
||||
const cmd = new Deno.Command(p, { args, stdout: "null", stderr: "piped" });
|
||||
const c = cmd.spawn();
|
||||
const s = await c.output();
|
||||
|
||||
Reference in New Issue
Block a user