mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-17 18:58:33 +00:00
all: initial clip scaffolding
This commit is contained in:
parent
6835bc4bdb
commit
24dcea3490
@ -18,6 +18,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
|||||||
|
|
||||||
if (r.isPhoto) action = "photo";
|
if (r.isPhoto) action = "photo";
|
||||||
else if (r.picker) action = "picker"
|
else if (r.picker) action = "picker"
|
||||||
|
else if (r.isClip) action = "clip"; // TODO: user-specified clips
|
||||||
else if (r.isGif && toGif) action = "gif";
|
else if (r.isGif && toGif) action = "gif";
|
||||||
else if (isAudioMuted) action = "muteVideo";
|
else if (isAudioMuted) action = "muteVideo";
|
||||||
else if (isAudioOnly) action = "audio";
|
else if (isAudioOnly) action = "audio";
|
||||||
@ -40,7 +41,11 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
|||||||
case "photo":
|
case "photo":
|
||||||
responseType = 1;
|
responseType = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "clip":
|
||||||
|
params = { type: "clip" }
|
||||||
|
break;
|
||||||
|
|
||||||
case "gif":
|
case "gif":
|
||||||
params = { type: "gif" }
|
params = { type: "gif" }
|
||||||
break;
|
break;
|
||||||
|
@ -34,6 +34,10 @@ export function createStream(obj) {
|
|||||||
isAudioOnly: !!obj.isAudioOnly,
|
isAudioOnly: !!obj.isAudioOnly,
|
||||||
audioFormat: obj.audioFormat,
|
audioFormat: obj.audioFormat,
|
||||||
time: obj.time ? obj.time : false,
|
time: obj.time ? obj.time : false,
|
||||||
|
clip: obj.clip ? {
|
||||||
|
start: parseFloat(obj.clip.start).toFixed(6),
|
||||||
|
end: parseFloat(obj.clip.end).toFixed(6),
|
||||||
|
} : false,
|
||||||
copy: !!obj.copy,
|
copy: !!obj.copy,
|
||||||
mute: !!obj.mute,
|
mute: !!obj.mute,
|
||||||
metadata: obj.fileMetadata ? obj.fileMetadata : false
|
metadata: obj.fileMetadata ? obj.fileMetadata : false
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly, convertToGif } from "./types.js";
|
import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly, streamClip, convertToGif } from "./types.js";
|
||||||
|
|
||||||
export default async function(res, streamInfo) {
|
export default async function(res, streamInfo) {
|
||||||
try {
|
try {
|
||||||
@ -17,6 +17,9 @@ export default async function(res, streamInfo) {
|
|||||||
case "mute":
|
case "mute":
|
||||||
streamVideoOnly(streamInfo, res);
|
streamVideoOnly(streamInfo, res);
|
||||||
break;
|
break;
|
||||||
|
case "clip":
|
||||||
|
streamClip(streamInfo, res);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
await streamDefault(streamInfo, res);
|
await streamDefault(streamInfo, res);
|
||||||
break;
|
break;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import ffmpeg from "ffmpeg-static";
|
import { request } from "undici"
|
||||||
import { ffmpegArgs, genericUserAgent } from "../config.js";
|
import ffmpeg from "ffmpeg-static"
|
||||||
import { spawn, pipe, killProcess } from "./shared.js";
|
|
||||||
import { metadataManager } from "../sub/utils.js";
|
|
||||||
import { request } from "undici";
|
|
||||||
import { create as contentDisposition } from "content-disposition-header";
|
|
||||||
import { AbortController } from "abort-controller"
|
import { AbortController } from "abort-controller"
|
||||||
|
import { create as contentDisposition } from "content-disposition-header"
|
||||||
|
|
||||||
|
import { makeCut } from "./cut.js"
|
||||||
|
import { metadataManager } from "../sub/utils.js"
|
||||||
|
import { spawn, pipe, killProcess } from "./shared.js"
|
||||||
|
import { ffmpegArgs, genericUserAgent } from "../config.js"
|
||||||
|
|
||||||
function closeRequest(controller) {
|
function closeRequest(controller) {
|
||||||
try { controller.abort() } catch {}
|
try { controller.abort() } catch {}
|
||||||
@ -226,3 +228,30 @@ export function convertToGif(streamInfo, res) {
|
|||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function streamClip(streamInfo, res) {
|
||||||
|
if (typeof streamInfo.urls === 'string')
|
||||||
|
streamInfo.urls = [streamInfo.urls];
|
||||||
|
|
||||||
|
const shutdown = () => (killProcess(process), closeResponse(res));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [ video, audio ] = streamInfo.urls;
|
||||||
|
const { start, end } = streamInfo.clip;
|
||||||
|
if (!start || !end || start === 'NaN' || end === 'NaN')
|
||||||
|
return shutdown();
|
||||||
|
|
||||||
|
const stream = await makeCut(video, { start, end }, audio);
|
||||||
|
process = stream.process;
|
||||||
|
|
||||||
|
res.setHeader('Connection', 'keep-alive');
|
||||||
|
res.setHeader('Content-Disposition', contentDisposition(streamInfo.filename));
|
||||||
|
|
||||||
|
pipe(stream, res, shutdown);
|
||||||
|
|
||||||
|
process.on('close', shutdown);
|
||||||
|
res.on('finish', shutdown);
|
||||||
|
} catch {
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user