This commit is contained in:
sim1222 2022-01-28 02:34:44 +09:00
parent 2ced35512b
commit 5a27a18fef

View File

@ -6,6 +6,7 @@ import { DriveFile } from 'misskey-js/built/entities';
import { fs } from 'fs'; import { fs } from 'fs';
import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg'; import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg';
function select(src: any, label: string | null, multiple: boolean): Promise<DriveFile | DriveFile[]> { function select(src: any, label: string | null, multiple: boolean): Promise<DriveFile | DriveFile[]> {
return new Promise((res, rej) => { return new Promise((res, rej) => {
@ -28,27 +29,34 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
} }
)); ));
const ffmpeg = createFFmpeg({ log: true });
const ffmpegconv = async ({ target: { files } }) => {
os.toast('Start const ffmpegconv');
var infilename = files[0].name; const ffmpeg = createFFmpeg({ log: true });
var outfilename = infilename.replace(/\.[^/.]+$/, '') + '.mp4'; async function ffmpegconv() {
os.toast('Start await beffile'); os.toast('Start const ffmpegconv');
const befFile = new Uint8Array(await readFromBlobOrFile(files[0])); var infilename = input.files[0].name;
os.toast('Loading FFmpeg.wasm') let video = null;
if (!ffmpeg.isLoaded()) { var outfilename = infilename.replace(/\.[^/.]+$/, '') + '.mp4';
os.toast('Loading FFmpeg.wasm-core') os.toast('Start await beffile');
await ffmpeg.load(); const befFile = new Uint8Array(await readFromBlobOrFile(input.files[0].name));
}
os.toast('Set ffmpeg files') os.toast('Loading FFmpeg.wasm')
ffmpeg.FS('writeFile', infilename, await fetchFile(befFile)); if (!ffmpeg.isLoaded()) {
os.toast('Converting') os.toast('Loading FFmpeg.wasm-core')
await ffmpeg.run(['-i', `video.avi`, '-c:v', 'copy', '-c:a', 'copy', `video.mp4`]); await ffmpeg.load();
os.toast('Converted') }
const aftFile = await ffmpeg.FS('readFile', outfilename); os.toast('Set ffmpeg files')
os.toast('Uploading') ffmpeg.FS('writeFile', infilename, await fetchFile(befFile));
os.upload(aftFile.buffer, defaultStore.state.uploadFolder).then(res).catch(e => { os.alert({ type: 'error', text: e }) }); os.toast('Converting')
}; await ffmpeg.run('-i', `video.avi`, '-c:v', 'copy', '-c:a', 'copy', `video.mp4`);
os.toast('Converted')
const aftFile = ffmpeg.FS('readFile', outfilename);
os.toast('Uploading')
video.value = URL.createObjectURL(new Blob([aftFile.buffer], { type: 'video/mp4' }));
os.upload(video, defaultStore.state.uploadFolder).then(res).catch(e => { os.alert({ type: 'error', text: e }) });
};
//const promises = Array.from(input.files).map(file => os.upload(file, defaultStore.state.uploadFolder)); //const promises = Array.from(input.files).map(file => os.upload(file, defaultStore.state.uploadFolder));