TSI-3418: fix(worker): 裸 -c copy 被静默改写为重新编码(HEVC→H264 有损转换) - #78
Conversation
Reviewer's GuideFixes silent lossy re-encoding of commands using bare Flow diagram for FFmpeg encoder argument classificationflowchart TD
A[FFmpeg arguments] --> B{Video-specific codec flag present?}
B -->|Yes| C[parseEncoderFromArgs]
B -->|No| D{General codec flag sets copy?}
D -->|Yes| E[Return encoder.EncoderFamily copy]
D -->|No| F[Return empty encoder family]
C --> G[Use video-specific encoder override]
E --> H[Preserve stream copy]
G --> I[Rewrite engine continues with classified encoder]
H --> I
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pkg/worker/rewrite_adapter.go" line_range="388-398" />
<code_context>
}
}
+
+ // General codec flag: bare "-c copy" sets every stream (video included)
+ // to stream-copy. Treat it as the "copy" passthrough encoder so the
+ // rewrite engine never injects a lossy re-encode.
+ for i, arg := range args {
+ if arg == "-c" || arg == "-codec" {
+ if i+1 < len(args) && args[i+1] == "copy" {
+ return encoder.EncoderFamily("copy")
+ }
+ }
+ if arg == "-c=copy" || arg == "-codec=copy" {
+ return encoder.EncoderFamily("copy")
+ }
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** When arguments contain an inline stream-specific option such as `-codec:v=h264_qsv` or `-vcodec=h264_qsv` together with `-c copy`, the first scan does not recognize that stream-specific form and the new general-option scan returns `copy`. The adapter therefore skips rewriting and leaves the explicitly requested video encoder unchanged, even when it is unavailable and should be handled by the rewrite or fallback path.
**Triggers:** When FFmpeg arguments combine general `-c copy` with inline `-codec:v=...` or `-vcodec=...`.
**Suggested fix:** Recognize `-codec:v=<encoder>` and `-vcodec=<encoder>` in the stream-specific scan before considering general codec flags.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the parser misclassifies a command, the worker could leave an output video in an unsupported codec instead of re-encoding it, or fail to apply a needed conversion. That incorrect media artifact outlives a revert, but it is bounded and can be regenerated after reverting the change.
Blocking findings: pkg/worker/rewrite_adapter.go:398
There was a problem hiding this comment.
审查规模:L1(93 行 / 2 文件),Bug 修复。修复方向正确:裸 -c copy 短路为 passthrough,端到端回归测试覆盖透传与 ResolveTargetEncoder 置空,点赞。
通过维度:代码质量 ✓ 安全 ✓ 架构 ✓ 规范 ✓ 性能 ✓ 并发 ✓ API 兼容 ✓。安全:纯参数解析,无新增依赖、无 shell 拼接、无敏感信息(显式检查)。
已纳入 sourcery-ai 审查反馈(COMMENTED,非 CHANGES_REQUESTED):其指出的内联 -codec:v=/-vcodec= 与 -c copy 组合误判已核实为真实缺陷,见内联评论 1;另见评论 2(注释语义与位置优先级)。
2b4fa23 to
5eb51c3
Compare
There was a problem hiding this comment.
复审提交 5eb51c3:2 个阻塞问题均已解决。
- 🔴
pkg/worker/rewrite_adapter.go(原 :392,现 :384-390)— 修复正确:首个扫描现通过strings.HasPrefix识别-c:v=/-codec:v=/-vcodec=三种内联形式(切片偏移 5/9/8 逐一核对正确),显式视频编码器优先于通用-c copy,不再误判为纯 copy 透传。 - 🟡
pkg/worker/rewrite_adapter.go:366-372注释 — 现准确表述:显式视频标志优先、且注明 ffmpeg 位置语义(later wins)与本解析器的取舍,不再绝对化。
测试补齐:rewrite_adapter_test.go 新增内联形式与「内联 -codec:v=/-vcodec= 覆盖通用 -c copy」用例,恰好覆盖 Sourcery 原始 bug_risk 场景;端到端回归测试(透传 + ResolveTargetEncoder 置空)保留。
安全维度已显式检查:仍为纯参数解析,无新增依赖(go.mod 未动)、无 shell 拼接、无敏感信息输出。并发/性能/API 兼容同前轮:parseEncoderFromArgs 无共享状态、O(n) 单趟、公共接口未变。
sourcery-ai 已同步转 APPROVED。零发现。
Closes TSI-3418
Summary by Sourcery
Prevent rewrite decisions from replacing FFmpeg stream-copy commands with unintended video re-encoding.
Bug Fixes:
Tests: