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 { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg';
function select(src: any, label: string | null, multiple: boolean): Promise<DriveFile | DriveFile[]> {
return new Promise((res, rej) => {
@ -28,13 +29,18 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
}
));
const ffmpeg = createFFmpeg({ log: true });
const ffmpegconv = async ({ target: { files } }) => {
async function ffmpegconv() {
os.toast('Start const ffmpegconv');
var infilename = files[0].name;
var infilename = input.files[0].name;
let video = null;
var outfilename = infilename.replace(/\.[^/.]+$/, '') + '.mp4';
os.toast('Start await beffile');
const befFile = new Uint8Array(await readFromBlobOrFile(files[0]));
const befFile = new Uint8Array(await readFromBlobOrFile(input.files[0].name));
os.toast('Loading FFmpeg.wasm')
if (!ffmpeg.isLoaded()) {
os.toast('Loading FFmpeg.wasm-core')
@ -43,13 +49,15 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
os.toast('Set ffmpeg files')
ffmpeg.FS('writeFile', infilename, await fetchFile(befFile));
os.toast('Converting')
await ffmpeg.run(['-i', `video.avi`, '-c:v', 'copy', '-c:a', 'copy', `video.mp4`]);
await ffmpeg.run('-i', `video.avi`, '-c:v', 'copy', '-c:a', 'copy', `video.mp4`);
os.toast('Converted')
const aftFile = await ffmpeg.FS('readFile', outfilename);
const aftFile = ffmpeg.FS('readFile', outfilename);
os.toast('Uploading')
os.upload(aftFile.buffer, defaultStore.state.uploadFolder).then(res).catch(e => { os.alert({ type: 'error', text: e }) });
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));
//Promise.all(promises).then(driveFiles => {