diff options
Diffstat (limited to 'src/server/DashUploadUtils.ts')
-rw-r--r-- | src/server/DashUploadUtils.ts | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index 6a7c8543d..148b0df65 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -17,6 +17,7 @@ import { resolvedServerUrl } from "./server_Initialization"; import { AcceptableMedia, Upload } from './SharedMediaTypes'; import request = require('request-promise'); import formidable = require('formidable'); +import { file } from 'jszip'; const { exec } = require("child_process"); const parse = require('pdf-parse'); const ffmpeg = require("fluent-ffmpeg"); @@ -62,19 +63,31 @@ export namespace DashUploadUtils { const { imageFormats, videoFormats, applicationFormats, audioFormats } = AcceptableMedia; //TODO:glr - export async function concatenateVideos(videoFiles: File[]): Promise<Upload.FileResponse> { + export async function concatenateVideos(filePaths: string[]): Promise<Upload.FileResponse> { // make a list of paths to create the ordered text file for ffmpeg - const filePaths = videoFiles.map(file => file.path); + //const filePaths = videoFiles.map(file => file.path); // write the text file to the file system const inputListName = 'concat.txt'; - const textFilePath = path.join(filesDirectory, "concat.txt"); - writeFile(textFilePath, filePaths.join("\n"), (err) => console.log(err)); - + const textFilePath = path.join(filesDirectory, inputListName); + // make a list of paths to create the ordered text file for ffmpeg + const filePathsText = filePaths.map(filePath => `file '${filePath}'`).join('\n'); + writeFile(textFilePath, filePathsText, (err) => console.log(err)); + console.log(filePathsText) // make output file name based on timestamp - const outputFileName = `output-${Utils.GenerateGuid()}.mp4`; + const outputFileName = `output-${Utils.GenerateGuid()}.mkv`; + // create the output file path in the parsed_file directory + const outputFilePath = path.join(filesDirectory, outputFileName); + + // concatenate the videos await new Promise((resolve, reject) => { - ffmpeg(inputListName).inputOptions(['-f concat', '-safe 0']).outputOptions('-c copy').save(outputFileName) + console.log('concatenating videos'); + var merge = ffmpeg(); + merge.input(textFilePath) + .inputOptions(['-f concat', '-safe 0']) + .outputOptions('-c copy') + //.videoCodec("copy") + .save(outputFilePath) .on("error", reject) .on("end", resolve); }) @@ -83,10 +96,41 @@ export namespace DashUploadUtils { unlinkSync(textFilePath); // read the output file from the file system - const outputFile = fs.readFileSync(outputFileName); - console.log('outputFile', outputFile); - // move only the output file to the videos directory - return MoveParsedFile(outputFile, Directory.videos) + // const outputFile = fs.readFileSync(outputFilePath); + + // make a new blob object with the output file buffer + // const outputFileBlob = new Blob([outputFile.buffer], { type: 'x-matroska/mkv' }); + + // TODO: make with toJSON() + + // make a data object + const outputFileObject: formidable.File = { + size: 0, + name: outputFileName, + path: outputFilePath, + // size: outputFileBlob.size, + type: 'video/x-matroska;codecs=avc1,opus', + lastModifiedDate: new Date(), + + toJSON: () => ({ ...outputFileObject, filename: outputFilePath.replace(/.*\//, ""), mtime: null, length: 0, mime: "", toJson: () => undefined as any }) + } + + // const file = { ...outputFileObject, toJSON: () => ({ ...outputFileObject, filename: outputFilePath.replace(/.*\//, ""), mtime: null, length: 0, mime: "", toJson: () => undefined as any }) }; + + // this will convert it to mp4 and save it to the server + //return await MoveParsedFile(outputFileObject, Directory.videos); + + return await upload(outputFileObject); + + // // return only the output (first) file to the videos directory + // return { + // source: file, result: { + // accessPaths: { + // agnostic: getAccessPaths(Directory.videos, outputFileName) + // }, + // rawText: undefined + // } + // } } export function uploadYoutube(videoId: string): Promise<Upload.FileResponse> { @@ -122,6 +166,7 @@ export namespace DashUploadUtils { } case "video": if (format.includes("x-matroska")) { + console.log("case video"); await new Promise(res => ffmpeg(file.path) .videoCodec("copy") // this will copy the data instead of reencode it .save(file.path.replace(".mkv", ".mp4")) |