Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
94 lines (81 loc) · 2.49 KB
/
Copy pathutils.js
File metadata and controls
94 lines (81 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const fs = require('fs');
const path = require('path');
const request = require('request');
const { exec } = require('child_process');
// const AWS = require('aws-sdk');
// const BUCKET_NAME = 'vwaudioprocessor';
// const REGION = 'eu-west-1';
// const CLOUDFRONT_BASE_URL = process.env.CLOUDFRONT_URL;
// const s3 = new AWS.S3({
// signatureVersion: 'v4',
// region: REGION,
// accessKeyId: process.env.S3_ACCESS_KEY,
// secretAccessKey: process.env.S3_ACCESS_SECRET
// })
function burnAudioToVideo(videoPath, audioPath, callback) {
const fileExtension = videoPath.split('.').pop();
const targetPath = path.join('tmp', `burned-video-audio-${Date.now()}.${fileExtension}`);
exec(`ffmpeg -i ${videoPath} -i ${audioPath} -map "0:v?" -map "1:a?" -c:v copy ${targetPath}`, (err) => {
if (err) return callback(err);
console.log('done burning')
return callback(null, targetPath)
})
}
function convertToMp3(filePath, callback) {
const targetPath = path.join('tmp', `mp3-audio-${Date.now()}.mp3`);
exec(`ffmpeg -i ${filePath} ${targetPath}`, (err) => {
if (err) return callback(err);
return callback(null, targetPath)
})
}
function getRemoteFile(url, callback = () => {}) {
return new Promise((resolve, reject) => {
const filePath = path.join('tmp', `file-${parseInt(Date.now() + Math.random() * 1000000) + "." + url.split('.').pop()}`);
request
.get(url)
.on('error', (err) => {
callback(err)
reject(err)
})
.pipe(fs.createWriteStream(filePath))
.on('error', (err) => {
callback(err)
reject(err)
})
.on('finish', () => {
resolve(filePath)
callback(null, filePath)
})
})
}
// function uploadToS3(filePath, callback) {
// const fileName = filePath.split('/').pop();
// s3.upload({
// Bucket: BUCKET_NAME,
// Key: fileName,
// Body: fs.createReadStream(filePath),
// ContentDisposition: 'attachement',
// }, (err, res) => {
// if (err) {
// return callback(err);
// }
// const url = `//s3-${REGION}.amazonaws.com/${BUCKET_NAME}/${fileName}`;
// return callback(null, { url, ETag: res.ETag, Key: fileName });
// })
// }
// function deleteFromS3(key, callback = () => {}) {
// s3.deleteObject({
// Key: key,
// Bucket: BUCKET_NAME,
// }, (err, result) => {
// if (err) return callback(err);
// return callback(null, result);
// })
// }
module.exports = {
// uploadToS3,
// deleteFromS3,
getRemoteFile,
burnAudioToVideo,
convertToMp3
}