-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (55 loc) · 1.96 KB
/
index.js
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
const express = require('express');
const app = express();
const port = 9999;
const path = require('path');
const ffmpegStatic = require('ffmpeg-static');
const ffmpeg = require('fluent-ffmpeg');
const crypto = require("crypto");
let uuid = crypto.randomUUID();
// Set the path to the ffmpeg binary
ffmpeg.setFfmpegPath(ffmpegStatic);
const inputUrl = 'https://campaign.salla.media/campaign_media/snapchat/21vFM1Q8AP1Jh5IMDs1Z7DQFPNsyxittSLzfvfqI.mp4';
const outputPath = path.join(__dirname, 'public', `output_${uuid}.mp4`);
app.get('/', async (req, res) => {
try {
// Download the video to a local file
// Process the video file
console.log('Processing video...');
ffmpeg(inputUrl)
.outputOptions('-threads 6') // Limit to 2 threads
.videoCodec('libx264')
.output(outputPath)
.on('start', (commandLine) => {
console.log('FFmpeg process started with command: ' + commandLine);
})
.on('progress', (progress) => {
console.log('Processing: % done',progress);
})
.on('error', (err) => {
console.log('An error occurred: ' + err.message);
})
.on('end', () => {
console.log('Processing finished');
})
.run();
// ffmpeg(inputUrl)
// .videoCodec('libx264')
// .audioCodec('aac')
// .output(outputPath)
// .on('end', () => {
// console.log('Processing complete.');
// res.send('Video processed successfully!');
// })
// .on('error', (err) => {
// console.error('Error processing video:', err.message);
// res.status(500).send('Error processing video.');
// })
// .run();
} catch (err) {
console.error('Error:', err.message);
res.status(500).send('Error during processing.');
}
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});