Skip to content

enhance(backend): fluent-ffmpegをnode-avに変更 - #17790

Draft
kakkokari-gtyih wants to merge 18 commits into
misskey-dev:developfrom
kakkokari-gtyih:enh-16529
Draft

enhance(backend): fluent-ffmpegをnode-avに変更#17790
kakkokari-gtyih wants to merge 18 commits into
misskey-dev:developfrom
kakkokari-gtyih:enh-16529

Conversation

@kakkokari-gtyih

@kakkokari-gtyih kakkokari-gtyih commented Jul 24, 2026

Copy link
Copy Markdown
Member

What

  • fluent-ffmpegをnode-avに変更
    • node-avはプレビルトバイナリとしてffmpegを読み込むため別途ffmpegのダウンロードが不要になる
    • 画像を実態のあるファイルを経由せずに直接JS内でSharpに流すなど、パフォーマンスが向上する(はず)
  • node-av経由のオペレーションにタイムアウトを追加

この変更により、Node v22では動作しなくなる (2026.7.0にはマージしない)

Why

Close #17638
Close #17633
Fix #16529
Fix #9172

Additional info (optional)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md リリース時期が確定したら埋める
  • (If possible) Add tests

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 24, 2026
@github-actions github-actions Bot added the packages/backend Server side specific issue/PR label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 26d10a81-1a1e-4bd8-8bc4-68a8c18b1d75

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

FFmpegを使用していた動画処理とセンシティブ判定をnode-avへ移行しました。Node.js要件、依存関係、ビルド設定、CIおよびコンテナ設定も更新しました。

Changes

node-av移行

Layer / File(s) Summary
node-av依存と実行環境の更新
.github/..., Dockerfile, packages/backend/package.json, packages/backend/rolldown.config.ts, packages/backend/src/misc/node-av-log.ts, pnpm-workspace.yaml
Node.js要件を更新し、node-avを追加しました。ビルド外部化、ログレベル設定、依存関係の整理を行いました。CIとコンテナからFFmpegの導入手順を削除しました。
センシティブ判定のフレーム抽出移行
packages/backend/src/core/FileInfoService.ts
動画およびAPNGのフレーム抽出と動画トラック確認をnode-avへ移行しました。タイムアウト、黒フレーム除外、Iフレームのサンプリング、PNG変換および判定結果の集約を追加しました。
動画サムネイル生成の移行
packages/backend/src/core/VideoProcessingService.ts
動画ストリームのデコード、シーク、フレーム変換をnode-avsharpで実行する方式へ変更しました。処理全体のタイムアウトとサムネイル位置を追加しました。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

センシティブ判定フロー

sequenceDiagram
  participant FileInfoService
  participant node-av
  participant SensitiveDetection
  FileInfoService->>node-av: 動画フレームをデコード
  node-av->>FileInfoService: PNGフレームを返却
  FileInfoService->>SensitiveDetection: detectSensitiveManyへ渡す
  SensitiveDetection->>FileInfoService: 判定結果を返却
Loading

動画サムネイル生成フロー

sequenceDiagram
  participant VideoProcessingService
  participant node-av
  participant sharp
  VideoProcessingService->>node-av: 映像ストリームを取得
  VideoProcessingService->>node-av: シークしてフレームをデコード
  node-av->>VideoProcessingService: フレームを返却
  VideoProcessingService->>sharp: フレームをWebPへ変換
  sharp->>VideoProcessingService: WebPを返却
Loading

Poem

FFmpegの処理を置き換え
node-avがフレームを読み
黒いフレームを選別し
sharpが画像を整えます
動画処理が新しく進みます 🎞️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed fluent-ffmpegの削除とnode-avへの移行で#16529を満たし、タイムアウト追加で#9172の要件にも対応しています。
Out of Scope Changes check ✅ Passed Node.js要件、FFmpegの削除、ビルド設定変更はnode-av移行に必要で、目的外の変更は確認できません。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed タイトルは、主要な変更であるfluent-ffmpegからnode-avへの移行を簡潔かつ明確に示しています。
Description check ✅ Passed What、Why、Additional info、Checklistの主要項目を記載しており、変更内容と目的を十分に説明しています。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 18.46154% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.08%. Comparing base (9eb9155) to head (7d8217c).
⚠️ Report is 14 commits behind head on develop.

Files with missing lines Patch % Lines
packages/backend/src/core/FileInfoService.ts 18.75% 30 Missing and 9 partials ⚠️
...ackages/backend/src/core/VideoProcessingService.ts 12.50% 11 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #17790      +/-   ##
===========================================
- Coverage    26.15%   26.08%   -0.08%     
===========================================
  Files         1175     1175              
  Lines        40137    40036     -101     
  Branches     11146    11122      -24     
===========================================
- Hits         10498    10442      -56     
+ Misses       23791    23744      -47     
- Partials      5848     5850       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/rolldown.config.ts`:
- Line 101: Update the external-module matching used by the Rolldown
configuration around externalModules so it externalizes node-av and every
node-av/* subpath, such as node-av/api and node-av/constants, using a
prefix-aware matcher rather than an exact-only entry.

In `@packages/backend/src/core/FileInfoService.ts`:
- Around line 292-311: Update the Fibonacci index transition in the
frame-selection loop so targetIndex advances monotonically after each accepted
frame. Adjust the nextIndex calculation using the current target and next
Fibonacci values, ensuring the sequence does not remain at 1 and continues
selecting later frames.

In `@pnpm-workspace.yaml`:
- Line 34: pnpm-workspace.yaml の node-av 設定を false から true に戻し、node-av の
build/postinstall script を実行可能にしてください。packages/backend の node-av/api 利用に必要な
FFmpeg バイナリとネイティブ資産がインストール時に準備される状態を維持してください。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4bdb9e75-1029-48f0-9b55-8d4ac51c7320

📥 Commits

Reviewing files that changed from the base of the PR and between 16ca5a7 and 250b565.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • .github/min.node-version
  • .github/workflows/test-backend.yml
  • .github/workflows/test-federation.yml
  • Dockerfile
  • packages/backend/package.json
  • packages/backend/rolldown.config.ts
  • packages/backend/src/core/FileInfoService.ts
  • packages/backend/src/core/VideoProcessingService.ts
  • packages/backend/src/misc/node-av-log.ts
  • pnpm-workspace.yaml
💤 Files with no reviewable changes (2)
  • .github/workflows/test-federation.yml
  • .github/workflows/test-backend.yml

Comment thread packages/backend/rolldown.config.ts Outdated
Comment thread packages/backend/src/core/FileInfoService.ts Outdated
Comment thread pnpm-workspace.yaml
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🖥 Frontend Diagnostics Report

(No significant changes)

View details

Requests by resource type
Type Requests Encoded bytes
Base Head Δ Base Head Δ
Document 2 2 0 33 KB 33 KB 0 B
Script 148 148 0 2.1 MB 2.1 MB 0 B
Stylesheet 58 58 0 288 KB 288 KB 0 B
Fetch 22 22 0 73 KB 73 KB 0 B
Image 11 11 0 254 KB 254 KB 0 B
Font 2 2 0 118 KB 118 KB 0 B
Other 9 9 0 421 KB 421 KB $\color{orange}{\text{+3 B}}$
V8 heap snapshot statistics
Metric @ Base @ Head Δ MAD
$\color{gray}{\rule{8pt}{8pt}}$ Total 11 MB
± 16 KB
11 MB
± 17 KB
$\text{-63 KB}$
$\text{-0.6\%}$
23 KB
$\color{orange}{\rule{8pt}{8pt}}$ Code 2.9 MB 2.9 MB $\text{+5.3 KB}$ 11 KB
$\color{red}{\rule{8pt}{8pt}}$ Strings 1.2 MB 1.2 MB $\text{+8 B}$ 137 B
$\color{cyan}{\rule{8pt}{8pt}}$ JS arrays 120 KB 120 KB 0 B 0 B
$\color{green}{\rule{8pt}{8pt}}$ Typed arrays 0 B 0 B 0 B 0 B
$\color{yellow}{\rule{8pt}{8pt}}$ System objects 0 B 0 B 0 B 0 B
$\color{violet}{\rule{8pt}{8pt}}$ Other JS objs 2.1 MB 2.1 MB $\text{-264 B}$ 423 B
$\color{pink}{\rule{8pt}{8pt}}$ Other non-JS objs 5.1 MB 5 MB $\text{-59 KB}$ 3 KB

Download representative heap snapshot: base / head

📦 Bundle Stats

Chunk size diff (0 updated, 0 added, 0 removed)
Chunk Base Head Δ Δ (%)
(total) 5.9 MB 5.9 MB 0 B 0%
(other generated chunks) 2 MB 2 MB 0 B 0%
Startup chunk size (0 updated, 0 added, 0 removed)
Chunk Base Head Δ Δ (%)
(total) 1 MB 1 MB 0 B 0%
(other generated chunks) 754 KB 754 KB 0 B 0%
(other) 280 KB 280 KB 0 B 0%

Startup chunks are the Vite entry for src/_boot_.ts and its static imports.

Bundles Modules Entries Imports Size
Static Dynamic Rendered Gzip Brotli
Base 468 2,861 21 10,704 332 10 MB 2.8 MB 2.4 MB
Head 468 2,861 21 10,704 332 10 MB 2.8 MB 2.4 MB
Δ 0 0 0 0 0 0 B $\text{-11 B}$ $\text{-46 B}$
Δ (%) 0% 0% 0% 0% 0% 0% $\text{-0\%}$ $\text{-0\%}$

Open treemap HTML

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

⚙️ Backend Diagnostics Report

Memory: After GC

Metric @ Base @ Head Δ MAD
HeapUsed 73.8 MB
± 0 MB
74.7 MB
± 0 MB
$\color{orange}{\text{+0.8~MB}}$
$\color{orange}{\text{+1.1\%}}$
0 MB
PSS 279.4 MB
± 5.2 MB
308.5 MB
± 1.5 MB
$\color{orange}{\text{+29.1~MB}}$
$\color{orange}{\text{+10.4\%}}$
5.4 MB
USS 262.9 MB
± 5.2 MB
292 MB
± 1.5 MB
$\color{orange}{\text{+29.1~MB}}$
$\color{orange}{\text{+11.1\%}}$
5.4 MB

Only metrics showing significant changes are displayed.

V8 Heap Snapshot Statistics

Metric @ Base @ Head Δ MAD
$\color{gray}{\rule{8pt}{8pt}}$ Total 87 MB
± 864 B
88 MB
± 16 KB
$\color{orange}{\text{+864 KB}}$
$\color{orange}{\text{+1\%}}$
16 KB
$\color{orange}{\rule{8pt}{8pt}}$ Code 25 MB 25 MB $\color{orange}{\text{+151 KB}}$ 14 KB
$\color{red}{\rule{8pt}{8pt}}$ Strings 30 MB 30 MB $\color{orange}{\text{+116 KB}}$ 336 B
$\color{cyan}{\rule{8pt}{8pt}}$ JS arrays 4.4 MB 4.4 MB $\text{+808 B}$ 0 B
$\color{green}{\rule{8pt}{8pt}}$ Typed arrays 566 KB 631 KB $\text{+66 KB}$ 0 B
$\color{yellow}{\rule{8pt}{8pt}}$ System objects 2.2 MB 2.4 MB $\color{orange}{\text{+143 KB}}$ 982 B
$\color{violet}{\rule{8pt}{8pt}}$ Other JS objs 25 MB 25 MB $\color{orange}{\text{+386 KB}}$ 190 B
$\color{pink}{\rule{8pt}{8pt}}$ Other non-JS objs 39 KB 39 KB $\text{+152 B}$ 0 B

Download representative heap snapshot: base / head

⚠️ Warning: Memory usage (PSS) has increased by more than 5% and exceeds the observed sample noise. Please verify this is not an unintended change.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 8, 2026
@syuilo

syuilo commented Aug 19, 2026

Copy link
Copy Markdown
Member

入れるか

@syuilo

syuilo commented Aug 19, 2026

Copy link
Copy Markdown
Member

メモリ使用量の増加はffmpegを埋め込んだから?

@kakkokari-gtyih

kakkokari-gtyih commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

それ以外にあんまり考えられる要素がない

それか実装が悪い?

@syuilo

syuilo commented Aug 19, 2026

Copy link
Copy Markdown
Member

明日ヒープスナップショット見てみるか

@syuilo

syuilo commented Aug 20, 2026

Copy link
Copy Markdown
Member

メモリ使用量の増加はffmpegを埋め込んだから?

ffmpegを埋め込んだからというよりはnode-av自体の実装が大きめという感じだった
あと全体的にソースコードにコメントが詳細に書かれていて、それがdist版でもminifyされずに残っていてそのままメモリに載っているのも使用量が比較的大きい一因だった

@kakkokari-gtyih

kakkokari-gtyih commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

あと全体的にソースコードにコメントが詳細に書かれていて、それがdist版でもminifyされずに残っていてそのままメモリに載っている

バンドルは試みたけど動かなかったので外部化している

@syuilo

syuilo commented Aug 20, 2026

Copy link
Copy Markdown
Member

ほむん

@kakkokari-gtyih

Copy link
Copy Markdown
Member Author

いけたかもしれない

@kakkokari-gtyih
kakkokari-gtyih marked this pull request as draft August 20, 2026 01:31
@kakkokari-gtyih

Copy link
Copy Markdown
Member Author

ちょっと確認したいことがあるのでいったんdraft

@kakkokari-gtyih

kakkokari-gtyih commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

コードのほうをバンドルするようにしたことでheap snapshotは落ち着いてそう

image

メモリ使用量はあんまり変わって無さそう

image image

@syuilo

syuilo commented Aug 20, 2026

Copy link
Copy Markdown
Member

PSSとUSSの増加は多分ffmpegのバイナリが入ったことによる増加の影響の方が大きそうだから想定内
HeapUsedはちゃんと減ってるから大丈夫そう

@kakkokari-gtyih

Copy link
Copy Markdown
Member Author

node-avの次のバージョンでメモリリークが治るなどの改善が入るみたいなので、それを待ってみたい感はある

@syuilo

syuilo commented Aug 20, 2026

Copy link
Copy Markdown
Member

ほむん

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages/backend Server side specific issue/PR size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

fluent-ffmpegやめる GenerateVideoThumbnail keeps ffmpeg running for a long time

2 participants