Created
May 12, 2023 08:12
-
-
Save codersidprogrammer/a6ee7c650021d77d0520f84bf7a8b297 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import ffmpeg from 'fluent-ffmpeg'; | |
@Injectable() | |
export class VideoSplitService { | |
splitVideo(inputPath: string, outputPath: string): void { | |
ffmpeg(inputPath, { | |
timeout: 4320000, | |
}) | |
.addOption([ | |
'-profile:v baseline', | |
'-level 3.0', | |
'-start_number 0', | |
'-hls_time 10', | |
'-hls_list_size 0', | |
'-f hls', | |
]) | |
.output(outputPath) | |
.on('end', () => console.log('success')) | |
.run(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { VideoSplitService } from './services/video-split.service'; | |
import { VideoProcessor } from './services/video.processor'; | |
import { VideoService } from './services/video.service'; | |
@Module({ | |
providers: [VideoSplitService, VideoProcessor, VideoService], | |
exports: [VideoService], | |
}) | |
export class VideoModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Process, Processor } from '@nestjs/bull'; | |
import { Job } from 'bull'; | |
import { VideoSplitService } from './video-split.service'; | |
import { VideoDto } from './video.service'; | |
@Processor('video-encoder') | |
export class VideoProcessor { | |
constructor(private readonly videoSplitService: VideoSplitService) {} | |
@Process('360') | |
handleVideoSplit(job: Job<VideoDto>): void { | |
this.videoSplitService.splitVideo(job.data.filePath, job.data.outputPath); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { InjectQueue } from '@nestjs/bull'; | |
import { Injectable } from '@nestjs/common'; | |
import { Queue } from 'bull'; | |
export interface VideoDto { | |
filePath: string; | |
outputPath: string; | |
} | |
@Injectable() | |
export class VideoService { | |
constructor( | |
@InjectQueue('video-encoder') | |
private readonly queue: Queue, | |
) {} | |
async registerVideoEncoding( | |
queueName: string, | |
data: VideoDto, | |
): Promise<void> { | |
await this.queue.add(queueName, data, { | |
delay: 100, | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment