aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/ApiManagers/UploadManager.ts13
-rw-r--r--src/server/DashUploadUtils.ts43
2 files changed, 53 insertions, 3 deletions
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts
index e7b7056a1..217c88107 100644
--- a/src/server/ApiManagers/UploadManager.ts
+++ b/src/server/ApiManagers/UploadManager.ts
@@ -40,7 +40,16 @@ export function clientPathToFile(directory: Directory, filename: string) {
export default class UploadManager extends ApiManager {
- protected initialize(register: Registration): void {
+ protected initialize(register: Registration): void {
+
+ register({
+ method: Method.POST,
+ subscription: "/concatVideos",
+ secureHandler: async ({ req, res }) => {
+ // req.body contains the array of server paths to the videos
+ _success(res, await DashUploadUtils.concatVideos(req.body));
+ }
+ });
register({
method: Method.POST,
@@ -50,7 +59,7 @@ export default class UploadManager extends ApiManager {
form.keepExtensions = true;
form.uploadDir = pathToDirectory(Directory.parsed_files);
return new Promise<void>(resolve => {
- form.parse(req, async (_err, _fields, files) => {
+ form.parse(req, async (_err, _fields, files) => {
const results: Upload.FileResponse[] = [];
for (const key in files) {
const f = files[key];
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index 552ab57a5..df5888c5a 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -1,9 +1,9 @@
import { green, red } from 'colors';
import { ExifImage } from 'exif';
+import * as exifr from 'exifr';
import { File } from 'formidable';
import { createWriteStream, existsSync, readFileSync, rename, unlinkSync, writeFile } from 'fs';
import * as path from 'path';
-import * as exifr from 'exifr';
import { basename } from "path";
import * as sharp from 'sharp';
import { Stream } from 'stream';
@@ -17,9 +17,11 @@ 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");
+const fs = require("fs");
const requestImageSize = require("../client/util/request-image-size");
export enum SizeSuffix {
@@ -60,6 +62,43 @@ export namespace DashUploadUtils {
const type = "content-type";
const { imageFormats, videoFormats, applicationFormats, audioFormats } = AcceptableMedia; //TODO:glr
+
+ export async function concatVideos(filePaths: string[]): Promise<Upload.AccessPathInfo> {
+ // make a list of paths to create the ordered text file for ffmpeg
+ const inputListName = 'concat.txt';
+ 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');
+ // write the text file to the file system
+ writeFile(textFilePath, filePathsText, (err) => console.log(err));
+
+ // make output file name based on timestamp
+ const outputFileName = `output-${Utils.GenerateGuid()}.mp4`;
+ // create the output file path in the videos directory
+ const outputFilePath = path.join(pathToDirectory(Directory.videos), outputFileName);
+
+ // concatenate the videos
+ await new Promise((resolve, reject) => {
+ var merge = ffmpeg();
+ merge.input(textFilePath)
+ .inputOptions(['-f concat', '-safe 0'])
+ .outputOptions('-c copy')
+ //.videoCodec("copy")
+ .save(outputFilePath)
+ .on("error", reject)
+ .on("end", resolve);
+ })
+
+ // delete concat.txt from the file system
+ unlinkSync(textFilePath);
+ // delete the old segment videos from the server
+ filePaths.forEach(filePath => unlinkSync(filePath));
+
+ // return the path(s) to the output file
+ return {
+ accessPaths: getAccessPaths(Directory.videos, outputFileName)
+ }
+ }
export function uploadYoutube(videoId: string): Promise<Upload.FileResponse> {
console.log("UPLOAD " + videoId);
@@ -94,6 +133,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"))
@@ -220,6 +260,7 @@ export namespace DashUploadUtils {
}
let resolvedUrl: string;
/**
+ *
* At this point, we want to take whatever url we have and make sure it's requestable.
* Anything that's hosted by some other website already is, but if the url is a local file url
* (locates the file on this server machine), we have to resolve the client side url by cutting out the