-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# Tracking/Specifications issue | ||
|
||
https://github.com/Joystream/joystream/issues/4761 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as tus from 'tus-js-client' | ||
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/client.ts GitHub Actions / Run migrations
|
||
|
||
input.addEventListener('change', function (e) { | ||
// Get the selected file from the input element | ||
var file = e.target.files[0] | ||
|
||
// Create a new tus upload | ||
var upload = new tus.Upload(file, { | ||
// Endpoint is the upload creation URL from your tus server | ||
endpoint: 'http://localhost:1080/files/', | ||
// Retry delays will enable tus-js-client to automatically retry on errors | ||
retryDelays: [0, 3000, 5000, 10000, 20000], | ||
// Attach additional meta data about the file for the server | ||
metadata: { | ||
filename: file.name, | ||
filetype: file.type, | ||
}, | ||
// Callback for errors which cannot be fixed using retries | ||
onError: function (error) { | ||
console.log('Failed because: ' + error) | ||
}, | ||
// Callback for reporting upload progress | ||
onProgress: function (bytesUploaded, bytesTotal) { | ||
var percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2) | ||
console.log(bytesUploaded, bytesTotal, percentage + '%') | ||
}, | ||
// Callback for once the upload is completed | ||
onSuccess: function () { | ||
console.log('Download %s from %s', upload.file.name, upload.url) | ||
}, | ||
}) | ||
|
||
// Check if there are any previous uploads to continue. | ||
upload.findPreviousUploads().then(function (previousUploads) { | ||
// Found previous uploads so we select the first one. | ||
if (previousUploads.length) { | ||
upload.resumeFromPreviousUpload(previousUploads[0]) | ||
} | ||
|
||
// Start the upload | ||
upload.start() | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { S3Store } from '@tus/s3-store' | ||
Check failure on line 1 in src/upload-server/server.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/server.ts GitHub Actions / Run migrations
Check failure on line 1 in src/upload-server/server.ts GitHub Actions / Run migrations
|
||
import { Server } from '@tus/server' | ||
import express from 'express' | ||
|
||
const s3Store = new S3Store({ | ||
partSize: 8 * 1024 * 1024, // Each uploaded part will have ~8MiB, | ||
s3ClientConfig: { | ||
bucket: process.env.AWS_BUCKET || '', | ||
region: process.env.AWS_REGION || '', | ||
credentials: { | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID || '', | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || '', | ||
}, | ||
}, | ||
}) | ||
|
||
const host = '127.0.0.1' | ||
const port = 1080 | ||
const app = express() | ||
const uploadApp = express() | ||
|
||
const server = new Server({ | ||
path: '/uploads', | ||
datastore: s3Store, | ||
}) | ||
|
||
uploadApp.all('*', server.handle.bind(server)) | ||
app.use('/uploads', uploadApp) | ||
app.listen(port, host) | ||
console.log(`Server is running at http://${host}:${port}`) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' | ||
import path from 'path' | ||
|
||
// Define input and output file paths | ||
const inputFilePath: string = path.join(__dirname, 'input.mp4') | ||
const outputFilePath: string = path.join(__dirname, 'output.avi') | ||
|
||
// Interface for FFmpeg progress information | ||
interface FfmpegProgress { | ||
percent: number | ||
} | ||
|
||
// Function to transcode the video | ||
function transcodeVideo(input: string, output: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const command: FfmpegCommand = ffmpeg(input) | ||
.output(output) | ||
.on('start', (commandLine: string) => { | ||
console.log('Spawned FFmpeg with command: ' + commandLine) | ||
}) | ||
.on('progress', (progress: FfmpegProgress) => { | ||
console.log(`Processing: ${progress.percent.toFixed(2)}% done`) | ||
}) | ||
.on('error', (err: Error, stdout: string, stderr: string) => { | ||
console.log('Error occurred: ' + err.message) | ||
console.log('FFmpeg stderr: ' + stderr) | ||
reject(err) | ||
}) | ||
.on('end', () => { | ||
console.log('Transcoding finished successfully') | ||
resolve() | ||
}) | ||
|
||
// Run the command | ||
|
||
command | ||
.videoCodec('libx264') | ||
.audioCodec('aac') | ||
.videoBitrate('1000k') | ||
.audioBitrate('128k') | ||
.size('640x480') | ||
.run() | ||
}) | ||
} | ||
|
||
// Execute transcoding | ||
transcodeVideo(inputFilePath, outputFilePath) | ||
.then(() => { | ||
console.log('Transcoding completed successfully') | ||
}) | ||
.catch((error: Error) => { | ||
console.error('Error during transcoding:', error) | ||
}) |