Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no spawn ffmpeg #737

Merged
merged 4 commits into from
Jan 26, 2025
Merged

feat: no spawn ffmpeg #737

merged 4 commits into from
Jan 26, 2025

Conversation

MliKiowa
Copy link
Member

@MliKiowa MliKiowa commented Jan 26, 2025

Summary by Sourcery

使用 @ffmpeg.wasm/main 和 @ffmpeg.wasm/core-mt 替换原生 FFmpeg 调用,用于音频和视频处理。

新特性:

  • 提取视频缩略图。

测试:

  • 添加了从视频文件中提取缩略图的测试调用。
Original summary in English

Summary by Sourcery

Replace native FFmpeg calls with @ffmpeg.wasm/main and @ffmpeg.wasm/core-mt for audio and video processing.

New Features:

  • Extract video thumbnails.

Tests:

  • Added a test call to extract a thumbnail from a video file.

Copy link

sourcery-ai bot commented Jan 26, 2025

审阅者指南 by Sourcery

这个拉取请求使用 @ffmpeg.wasm/main 库替换了 node:child_process spawn 的使用,以处理音频转换。这一变更消除了对外部 ffmpeg 可执行文件的依赖,提高了可移植性并简化了构建过程。

音频文件转换的序列图

sequenceDiagram
    participant C as Client
    participant FS as FFmpegService
    participant FF as FFmpeg.wasm
    participant FSystem as FileSystem

    C->>FS: convert(filePath, pcmPath, logger)
    activate FS
    FS->>FSystem: Read input file
    FSystem-->>FS: Input file data
    FS->>FF: Write file to virtual FS
    FS->>FF: Run FFmpeg conversion
    FF-->>FS: Conversion complete
    FS->>FF: Read converted file
    FF-->>FS: Converted data
    FS->>FSystem: Write PCM file
    FS-->>C: Return Buffer
    deactivate FS
Loading

新 FFmpegService 的类图

classDiagram
    class FFmpegService {
        -ffmpegRef: FFmpeg
        +constructor(ffmpegRef: FFmpeg)
        +extractThumbnail(videoPath: string, thumbnailPath: string): Promise~void~
        +convertFile(inputFile: string, outputFile: string, format: string): Promise~void~
        +convert(filePath: string, pcmPath: string, logger: LogWrapper): Promise~Buffer~
    }
    note for FFmpegService "替换直接 ffmpeg spawn 调用
为 @ffmpeg.wasm/main 实现"
Loading

文件级别变更

变更 详情 文件
使用 @ffmpeg.wasm/main 库替换 node:child_process spawn 进行音频转换。
  • 移除了 node:child_process 中的 spawn 函数。
  • 移除了 FFMPEG_PATH 常量。
  • 引入 ffmpegService 处理音频转换。
  • 用 ffmpegService.convert 替换 convert 函数。
  • 用 ffmpegService.convertFile 替换 convertFile 函数。
src/common/audio.ts
src/onebot/action/file/GetRecord.ts
引入新的 ffmpeg 服务以封装 ffmpeg 功能。
  • 创建新的 FFmpegService 类。
  • 实现 convert、convertFile 和 extractThumbnail 方法。
  • 使用 @ffmpeg.wasm/main 初始化 FFmpeg 实例。
src/common/ffmpeg.ts
更新 package.json 和 vite.config.ts 以包含 @ffmpeg.wasm/main。
  • 添加 @ffmpeg.wasm/core-mt 和 @ffmpeg.wasm/main 作为依赖。
  • 在 vite.config.ts 的外部列表中添加 @ffmpeg.wasm/core-mt 和 @ffmpeg.wasm/main。
package.json
vite.config.ts
在 src/shell/base.ts 中添加对 ffmpegService.extractThumbnail 的测试调用。
  • 添加 try catch 块以调用 ffmpegService.extractThumbnail。
src/shell/base.ts

提示和命令

与 Sourcery 交互

  • 触发新审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub 问题: 通过回复审阅评论,要求 Sourcery 创建问题。您也可以用 @sourcery-ai issue 回复审阅评论来创建问题。
  • 生成拉取请求标题: 在拉取请求标题的任何位置写 @sourcery-ai 以随时生成标题。您也可以在拉取请求中评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何位置写 @sourcery-ai summary 以随时生成 PR 摘要。您也可以在拉取请求中评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide 以随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经处理了所有评论,不想再看到它们,这很有用。
  • 取消所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss 以取消所有现有的 Sourcery 审阅。特别适用于想要重新开始审阅的情况 - 别忘了评论 @sourcery-ai review 以触发新审阅!
  • 为问题生成行动计划: 在问题中评论 @sourcery-ai plan 以生成问题的行动计划。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审阅功能,如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request replaces the usage of the node:child_process spawn with the @ffmpeg.wasm/main library to handle audio conversions. This change eliminates the need to rely on an external ffmpeg executable, improving portability and simplifying the build process.

Sequence diagram for audio file conversion

sequenceDiagram
    participant C as Client
    participant FS as FFmpegService
    participant FF as FFmpeg.wasm
    participant FSystem as FileSystem

    C->>FS: convert(filePath, pcmPath, logger)
    activate FS
    FS->>FSystem: Read input file
    FSystem-->>FS: Input file data
    FS->>FF: Write file to virtual FS
    FS->>FF: Run FFmpeg conversion
    FF-->>FS: Conversion complete
    FS->>FF: Read converted file
    FF-->>FS: Converted data
    FS->>FSystem: Write PCM file
    FS-->>C: Return Buffer
    deactivate FS
Loading

Class diagram for the new FFmpegService

classDiagram
    class FFmpegService {
        -ffmpegRef: FFmpeg
        +constructor(ffmpegRef: FFmpeg)
        +extractThumbnail(videoPath: string, thumbnailPath: string): Promise~void~
        +convertFile(inputFile: string, outputFile: string, format: string): Promise~void~
        +convert(filePath: string, pcmPath: string, logger: LogWrapper): Promise~Buffer~
    }
    note for FFmpegService "Replaces direct ffmpeg spawn calls
with @ffmpeg.wasm/main implementation"
Loading

File-Level Changes

Change Details Files
Replaced the usage of node:child_process spawn with the @ffmpeg.wasm/main library for audio conversion.
  • Removed the spawn function from node:child_process.
  • Removed the FFMPEG_PATH constant.
  • Introduced the ffmpegService to handle audio conversions.
  • Replaced the convert function with ffmpegService.convert.
  • Replaced the convertFile function with ffmpegService.convertFile.
src/common/audio.ts
src/onebot/action/file/GetRecord.ts
Introduced a new ffmpeg service to encapsulate ffmpeg functionality.
  • Created a new FFmpegService class.
  • Implemented the convert, convertFile, and extractThumbnail methods.
  • Initialized the FFmpeg instance using @ffmpeg.wasm/main.
src/common/ffmpeg.ts
Updated package.json and vite.config.ts to include @ffmpeg.wasm/main.
  • Added @ffmpeg.wasm/core-mt and @ffmpeg.wasm/main as dependencies.
  • Added @ffmpeg.wasm/core-mt and @ffmpeg.wasm/main to the external list in vite.config.ts.
package.json
vite.config.ts
Added a test call to ffmpegService.extractThumbnail in src/shell/base.ts.
  • Added a try catch block to call ffmpegService.extractThumbnail.
src/shell/base.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@MliKiowa - 我已经审查了您的更改并发现了一些需要解决的问题。

阻塞性问题

  • FFmpeg 退出代码检查被反转,导致操作在成功时失败,反之亦然(链接

整体评论

  • FFmpegService 中的退出代码检查被反转 - 目前在成功时(代码 === 0)抛出错误,在失败时成功。需要通过将条件更改为 if (code !== 0) 来修复。
  • 从 NCoreInitShell 中删除 extractThumbnail 的调试测试代码 - 这似乎是不应该出现在生产环境中的开发测试代码。
以下是我在审查期间查看的内容
  • 🔴 一般性问题:1 个阻塞性问题,1 个其他问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果您喜欢我们的评论,请考虑分享 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用反馈来改进您的评论。
Original comment in English

Hey @MliKiowa - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • The FFmpeg exit code check is inverted, causing operations to fail when they succeed and vice versa (link)

Overall Comments:

  • The exit code checks in FFmpegService are inverted - currently throwing errors on success (code === 0) and succeeding on failure. This needs to be fixed by changing the condition to if (code !== 0).
  • Remove the debug test code for extractThumbnail from NCoreInitShell - this appears to be development testing code that shouldn't be in production.
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 1 other issue
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/common/ffmpeg.ts Outdated Show resolved Hide resolved
src/common/ffmpeg.ts Show resolved Hide resolved
@MliKiowa MliKiowa merged commit e7655e0 into main Jan 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant