Skip to content

Commit

Permalink
improve: ffmpeg, use 4 threads for less errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zenkyuv committed Feb 11, 2024
1 parent 3a17a1d commit 9527cde
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion s/context/controllers/video-export/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class VideoExport {
async #extract_frames_from_video(effect: VideoEffect) {
const file_result = await fetchFile(effect.file)
await this.ffmpeg.ffmpeg.writeFile(effect.file.name, file_result)
await this.ffmpeg.ffmpeg.exec(["-i", effect.file.name, `out${effect.id}_%d.png`])
await this.ffmpeg.ffmpeg.exec(["-threads", "4","-i", effect.file.name, `out${effect.id}_%d.png`])
this.decoded_effects.set(effect.id, effect.id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ export class FFmpegHelper {
await this.ffmpeg.createDir("/thumbnails")
await this.ffmpeg.createDir("/segments")
await this.ffmpeg.writeFile(file.name, result)
// remux to mkv container, which supports more variety of codecs
await this.ffmpeg.exec(["-i", file.name, "-c", "copy", "container.mkv"])
// split into 5 second segments, so user can get new filmstrips every 5 seconds
await this.ffmpeg.exec(["-i", "container.mkv", "-c", "copy", "-map", "0", "-reset_timestamps", "1", "-f", "segment", "-segment_time", "5", "segments/out%d.mkv"])
await this.ffmpeg.exec(["-threads", "4","-i", file.name, "-c", "copy", "-map", "0", "-reset_timestamps", "1", "-f", "segment", "-segment_time", "5", "segments/out%d.mp4"])
const segments = await this.ffmpeg.listDir("/segments")

for(const segment of segments) {
if(!segment.isDir) {
await this.ffmpeg.exec(["-i", `segments/${segment.name}`, "-filter_complex", `select='not(mod(n\,1))',scale=100:50`, "-an", "-c:v", "libwebp", `thumbnails/${segment_number}_out%d.webp`])
await this.ffmpeg.exec(["-threads", "4","-i", `segments/${segment.name}`, "-filter_complex", `scale=100:50`, "-an", "-c:v", "libwebp", "-preset","icon" ,`thumbnails/${segment_number}_out%d.webp`])
const frames = await this.ffmpeg.listDir("/thumbnails")
for(const frame of frames) {
if(!frame.isDir) {
Expand Down

0 comments on commit 9527cde

Please sign in to comment.