Add portable avatar animation asset skill and silent media audit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
---
|
||||
name: avatar-animation-assets
|
||||
description: 根据人物肖像或全身参考,按需制作虚拟人的 idle、TALK 嘴层、过渡桥和无声 action 候选,完成时序、绑定、资源预算与交付检查。适用于具备参考图生图/生视频及本地媒体处理能力的资产生产 agent;生成工具、预算和运行格式按当前任务核对。
|
||||
---
|
||||
|
||||
# 虚拟人动画资产生产
|
||||
|
||||
把用户参考和需求转换成可审核的动画资产及可复现交付。默认新素材720×1280/24fps:idle、TALK底层和桥无声;action无音轨、不讲话,但允许自然笑容、露齿和张嘴。
|
||||
|
||||
本skill是工具无关的生产流程,不自带生成服务、视频模型或已验证的嘴层生成器。使用环境实际可用且已获授权的image/video工具与本地处理工具。只具备图像/视频生成能力可以做媒体小样;完整TALK运行包还需要逐帧跟踪、五档RGBA加工、元数据导出和生产parser验证。
|
||||
|
||||
## 输入与能力检查
|
||||
|
||||
接受自然语言需求;用 [production-brief.md](references/production-brief.md) 整理现有信息,无需让用户机械填写表格。
|
||||
|
||||
- 获取本次参考图、要制作的类别/种类/数量、保留的形象要素、输出目录和本次生成授权/预算;复用已有答案和已审核样本。
|
||||
- 单张全身参考可作为起点;若只有脸部肖像,不能假定用户已认可凭空补出的服装/全身造型。可先在授权范围内做全身anchor候选并明确新增设计。背面/侧面不可见内容属于生成候选,不声称真实还原。
|
||||
- 核实image工具是否支持参考图编辑,video工具是否支持参考图生视频及起止约束。不能只有“同名工具”就假定具备这些功能,也不能把口头prompt保证当作接缝验证。
|
||||
- 核实文件读写、Python、ffmpeg/ffprobe,以及跟踪/patch导出能力。工具缺失时继续可完成的规划、样本或媒体检查,交出具体缺口;不得用静态重复帧、伪嘴层或伪manifest补齐。
|
||||
- 已有费用账本则继承;授权总上限不是新增额度。付费额度不明确时先完成非付费brief/工具检查,费用相关调用等授权明确后执行。按实际job记录提交、失败和未知费用,不为重试自动切provider或模型。
|
||||
|
||||
## 选择生产路径
|
||||
|
||||
按需读取 [production-workflow.md](references/production-workflow.md):其中包含构图、样本顺序、idle/TALK/桥/action制作及视觉验收。
|
||||
|
||||
1. **只要动作或视频样本**:交付实际无声媒体、预览、测量和内容审核状态。未要求的TALK、情绪包、APK或部署不扩入。
|
||||
2. **完整会话资产包**:先验证neutral代表样本,再做所需表情/idle和双向桥,每段最终body独立N×5嘴层;读取 [baji-runtime-profile.md](references/baji-runtime-profile.md) 导出目标格式。
|
||||
3. **扩充已有角色**:以已冻结fallback与actual frame/PTS为锚点,只制作请求的变体及必要桥。已有媒体只读,改动输出新revision和diff。
|
||||
|
||||
在用户既有授权和明确预算内自主推进。小样需人类视觉决定时,先交具体预览与问题;若当前任务已认可该样本或授权按明确标准继续,不重复索要同一审批。生成失败或质量拒绝时先定位原因,重试次数受本次任务剩余额度与可验证的改进理由约束;无新证据、工具能力不足或预算耗尽时停止相关生成并交付阶段结果。
|
||||
|
||||
## 不可丢失的生产约束
|
||||
|
||||
- 最终视频加工在先,测量N/actual PTS/SHA在后,嘴层绑定最后。body被重编码后重新核验所有绑定。
|
||||
- 每个body及非native会话桥使用自己逐帧的五档嘴层。patch按实际显示body帧选择;嘴状态曲线有自己的clock,不拿body N覆盖state N。
|
||||
- 必须有实际loop与合法enter/return;同名A锚点不能证明像素、姿态或运动连续。起止图约束不代替原速接缝审核。
|
||||
- 新action是一个完整的“进入→动作→返回”无声H264视频。视频内自然张嘴允许,模拟讲话不允许;`mouthAllowed:false`禁止外叠TALK,不要求源视频全程闭嘴。
|
||||
- 先预算解码RGBA。baji profile每张patch≤128×128、单runtime≤8,000,000 bytes、整包会话+桥≤32,000,000 bytes,不用PNG磁盘大小代替。
|
||||
- 当前baji已实现的是两段带AAC的dance;新的无声action种类尚需代码owner扩展。交独立媒体候选,标 `unsupported_by_current_contract`;不补静音AAC、不冒充dance、不修改allowlist。
|
||||
|
||||
## 免费测量与验收
|
||||
|
||||
从skill目录运行:
|
||||
|
||||
```sh
|
||||
python3 scripts/audit-silent-video.py \
|
||||
--video /absolute/candidate/action.mp4 --role action \
|
||||
--output /absolute/evidence/fresh-action-report.json
|
||||
```
|
||||
|
||||
工具只读视频,要求ffprobe/ffmpeg在PATH(或用对应参数指定),测量单H264流、shape、fps、实际逐帧PTS、duration、full decode及稳定SHA;默认720×1280/24fps,支持显式480×848。报告路径必须在媒体目录外且未存在。它不检查人物、讲话口型、loop接缝、嘴patch或目标生产parser,不是完整运行准入。
|
||||
|
||||
完整交付还要检查profile的全部引用、N×5 RGBA/ownbody、stateclock、图与缓存,再用接入环境的实际生产parser。本skill内没有另造一个宽松parser;无目标工具时把parser状态标not_run并交字段合同,不能自称runtime-ready。
|
||||
|
||||
## 冻结与交付
|
||||
|
||||
先冻结媒体/patch,再写runtime并计算SHA,再更新index引用与inventory,最后写index并外置其SHA。所有引用为安全相对路径;每个文件提供真实SHA/bytes。不可覆盖旧pin,任何修改成为新revision。
|
||||
|
||||
交付:candidate路径、exact index SHA(有index时)、body/桥/action清单、actual时序、解码RGBA预算、机器报告、全身+脸部原速预览、接缝证据、来源/账本和未测项。区分media候选、机器通过、视觉审核、App导入和真机验证。调用job/私有凭证存放在owner私有账本,公开回执不含keys、用户聊天、音脸数据。
|
||||
|
||||
asset生产不等于App接入。没有本次明确接入授权时,不改Android/gateway source、registry、环境或部署;不发消息给外部人员。人物媒体、APK与运行报告保留在输出目录,不能因skill可入Git而把用户参考/生成素材也提交。
|
||||
@@ -0,0 +1,4 @@
|
||||
interface:
|
||||
display_name: "虚拟人动画资产生产"
|
||||
short_description: "按肖像参考生产 idle、TALK、过渡桥和无声动作,并校验交付"
|
||||
default_prompt: "使用 $avatar-animation-assets,根据我的肖像整体参考和生产清单制作动画资产,先核对生成工具、预算及目标运行格式。"
|
||||
@@ -0,0 +1,92 @@
|
||||
# baji-v2-a01 运行格式参考
|
||||
|
||||
快照依据:`lan-voice-android` commit `34b16130463de82d5b750b2c3ee1a4e835805379` 的生产parser;完整来源指南为同仓库 `docs/ANIMATION_ASSET_PRODUCTION_PIPELINE.md`。这份参考随skill携带,脱离仓库仍可阅读;实际接入时核对目标源码,不假定快照永远最新。
|
||||
|
||||
## 适用边界
|
||||
|
||||
这是baji App特定profile,不是任意角色运行时通用schema。当前identity与packId固定;换肖像也不能自行改identity期待parser支持多角色。新的exact index需要独立接入授权;旧correct-03准入例外不适用于新SHA。资产生产者不修改App或gateway准入来让自己候选通过。
|
||||
|
||||
当前支持会话schema2和两段音乐dance;用户的新要求是无音轨纯action。后者需parser、player、ActionController、模型枚举和gateway能力扩展。无声媒体可以测量和审核,完成App接入前标 `unsupported_by_current_contract`。不得补AAC、伪audioEndUs或伪装旧舞蹈。
|
||||
|
||||
## Shape、时间和预算
|
||||
|
||||
| 项目 | 当前要求 |
|
||||
|---|---|
|
||||
| shape | 480×848或720×1280,同index的body/桥/action统一;新生产默认720×1280 |
|
||||
| fps | 默认24,parser支持有理fps1..60;N和PTS取最终解码结果 |
|
||||
| body/桥时序 | N2..720,duration0.1..30s,PTS从0严格递增且末PTS<duration |
|
||||
| 时序一致性 | duration与N×nominal period差≤1period+2us;相邻PTS及末帧到end间隔≤2period+2us |
|
||||
| state | 2..60曲线帧,100..1000ms,独立fps/PTS/N,alpha有限且0..1 |
|
||||
| patch | RGBA8 straight/unassociated,width/height1..128,坐标在实际body像素范围内 |
|
||||
| 内存 | 每runtime decoded RGBA≤8,000,000 bytes;所有会话+桥≤32,000,000 bytes |
|
||||
| 图 | conversation packages1..12,edges≤100;非fallback有fallback双向路径 |
|
||||
| payload | 运行引用≤512,000,000 bytes;body/桥video≤64,000,000 bytes,PNG≤256,000 bytes |
|
||||
|
||||
N97@24的最后PTS可能4,000,000而duration为4,041,667us。不要把97、25或193当通用固定N。ffprobe与声明比较容差通常2us,manifest内patch.ptsUs与body.ptsUs必须精确一致。
|
||||
|
||||
## Runtime字段
|
||||
|
||||
每个会话/桥runtime有:
|
||||
|
||||
- `schemaVersion:2`、`identityId:a01`、`packId:a01-expression-action-v1-<package-or-edge-id>-runtime-04`。
|
||||
- `publishApproval:false`;`runtimeReady`按真实技术状态填写。默认检查要求true;显式用户debug候选可以false但入口绑定特定exact parent SHA,不能泛用。
|
||||
- `body:{path,sha256,width,height,frameCount,durationUs,fpsNumerator,fpsDenominator,ptsUs,hasAudio:false}`。path为 `body/<safe-name>.mp4`,视频只有一个正常H264流。
|
||||
- `patchFormat:{format:"PNG RGBA 8bit",alphaEncoding:"straight_unassociated",bodySha256,apertureLevels:[0,0.25,0.5,0.75,1],requiresRendererExtension:true}`。
|
||||
- `patches`恰好N条,顺序 `frameIndex=i`、`ptsUs=body.ptsUs[i]`,附 `x/y/width/height/levels`。
|
||||
- `levels`顺序0..4,每个含 `levelIndex/aperture/path/sha256`。所有N×5路径唯一,path为 `patches/<safe-name>.png`,位图大小匹配该帧声明。
|
||||
- 顶层patch `path/sha256`可一并省略;若出现,必须同时出现且精确等于levels[4]。
|
||||
- `mouthStates`包含idle/opening/talk1/talk2/end-talk完整五种;`stateRouting`按下面固定路由。
|
||||
|
||||
每state有 `id/frameCount/fpsNumerator/fpsDenominator/durationMs/ptsUs/globalAlphaByFrame/entryMouthAnchor/exitMouthAnchor`。`frameCount==ptsUs.length==globalAlphaByFrame.length`,不等同body N。
|
||||
|
||||
| state | mouth anchor | alpha | 常用参考 |
|
||||
|---|---|---|---|
|
||||
| idle | A→A | 全0 | 12帧500ms@24 |
|
||||
| opening | A→B | 首0末1 | 6帧250ms@24 |
|
||||
| talk1 / talk2 | B→B | 首末1,中间min<.5 | 各12帧500ms@24 |
|
||||
| end-talk | B→A | 首1末0 | 6帧250ms@24 |
|
||||
|
||||
```json
|
||||
{
|
||||
"idle": ["idle", "opening"],
|
||||
"opening": ["talk1", "talk2", "end-talk"],
|
||||
"talk1": ["talk1", "talk2", "end-talk"],
|
||||
"talk2": ["talk1", "talk2", "end-talk"],
|
||||
"end-talk": ["idle"]
|
||||
}
|
||||
```
|
||||
|
||||
五档表示开口几何,不是opacity。L0绕过patch、L1..4选择最近档、选中档global opacity1;空间alpha做边缘融合。坐标在每段实际body上独立跟踪,不能复用neutral数据或统一乘1.5。身体frameclock与mouthstateclock独立。
|
||||
|
||||
## Index、桥与引用
|
||||
|
||||
index字段:`schemaVersion:2/identityId:a01/packId:a01-expression-action-v1/fallbackPackageId/conversationPackages/edges/actions/files`,并记录revision、review和来源状态。
|
||||
|
||||
conversation row:`id/emotion/visualIntensity/mouthBodySha256/runtimeManifest:{path,sha256}/entryAnchor/exitAnchor/legalExitFrames/loopEdge`。emotion只支持neutral/happy/sad;neutral intensity0,happy/sad intensity1。fallback是neutral。entry/exit身体锚点当前均A。
|
||||
|
||||
edge:`id/from/to/fromAnchor/toAnchor/fromFrame/toFrame/fromPtsUs/toPtsUs/clip`。clip提供相对path、SHA、实际shape/N/PTS/fps/duration、hasAudio:false。源frame在legalExitFrames内,源/目标PTS精确等于对应body帧。
|
||||
|
||||
nativeLoop:true仅同包last→0,clip与自身body SHA/PTS/duration一致;复用已有嘴层。非native会话桥附 `mouthRuntimeManifest:{path,sha256}`及 `mouthAllowed:true`,runtime的body SHA/N/PTS/fps/duration/shape与clip完全一致,N×5使用桥自身数据。无mouth桥只能silent-only,不能当完整live TALK图。
|
||||
|
||||
index `files`列出交付文件的相对path、SHA256、bytes;运行引用必须都在inventory,review可列入但不可自动打进APK。无绝对路径、URL、`.`、`..`或symlink逃逸。runtime SHA先算,index后写,index自身SHA外置。
|
||||
|
||||
## Action候选与运行目标
|
||||
|
||||
新无声候选独立交:kind意图、asset/variant ID、H264单视频流文件、测量报告、`sourcePackageId/sourceFrame/sourcePtsUs/returnPackageId/returnFrame/returnPtsUs`、原速和接缝预览。以实际fallback锚点绑定,`hasAudio:false`;不捏造audioEndUs。
|
||||
|
||||
target播放合同:TTS真实drained、录音真实停止确认、合法neutral入口、ACTION独占、视频真实end/release、回锚点、completed一次,再可发言。mouthAllowed:false/disallowTALK:true只禁止外叠嘴与讲话,视频原有自然笑容或张嘴可保留。
|
||||
|
||||
## 目标仓库可用时的实际checker
|
||||
|
||||
从目标repo根目录执行,evidence需新建且在owner源目录之外;这些命令不导入不发布:
|
||||
|
||||
```sh
|
||||
python3 scripts/check-avatar-runtime.py --manifest <runtime>/manifest.json \
|
||||
--sha256 <actual-runtime-sha> --output logs/asset-production/<fresh>.json
|
||||
python3 scripts/package-avatar-emotion.py --manifest <candidate>/manifest.json \
|
||||
--sha256 <actual-index-sha> --output logs/asset-production/<fresh-dir>
|
||||
python3 scripts/diagnose-avatar-candidate.py --manifest <candidate>/manifest.json \
|
||||
--sha256 <actual-index-sha> --output logs/asset-production/<fresh-reject-dir>
|
||||
```
|
||||
|
||||
现有脚本含原环境路径,迁移执行前由代码owner适配本地工具入口;不要因为python脚本在文件夹就宣称它可跨环境运行。当前checker拒绝新无声action或尚未授权的新candidate时如实保留原因,不调整审核flag或生成假媒体。skill的免费media audit只测媒体,不替代这些生产checks。
|
||||
@@ -0,0 +1,26 @@
|
||||
# 从参考到生产 brief
|
||||
|
||||
这是agent整理信息的模板。已在当前会话给出的信息直接继承;只有实际影响执行且无法合理推断的缺项才询问用户。
|
||||
|
||||
| 项目 | 内容或默认 |
|
||||
|---|---|
|
||||
| reference | 用户给出的本地文件/工具attachment及其用途;原参考只读 |
|
||||
| identity/appearance | 保留脸、发型、服装、体型;用户允许改变哪些要素 |
|
||||
| request | idle / TALK / 表情body / 桥 / action;每类数量或明确清单 |
|
||||
| action intent | 如“转一圈”“凑近看看”;无声、不讲话、自然表情允许 |
|
||||
| visual profile | 默认720×1280/24fps、固定镜头;背景和人物尺度继承参考 |
|
||||
| target | 媒体小样,或baji-v2-a01运行包;其它运行时须有自己的合同 |
|
||||
| existing fallback | 已有neutral候选的路径/SHA/实际frame与PTS,或本次新建 |
|
||||
| mouth amplitude | 继承已审核批次样本;新角色先明确最大档小样,数字不跨尺度继承 |
|
||||
| tools | 实际可调用的reference-image edit、image-to-video、本地处理/跟踪/导出及checker |
|
||||
| authorization/budget | 当前任务已授权的生成范围、费用/调用上限、剩余账本;未知费用标unknown |
|
||||
| output | 独立owner目录、新revision命名、需要的预览与交付位置 |
|
||||
| review | 已认可的样本、可自主继续的范围、尚需人类决定的视觉项 |
|
||||
|
||||
少量文字即可启动,例如:
|
||||
|
||||
> 使用我提供的全身参考,保留人物和服装。制作1套neutral idle及TALK嘴层,再制作转一圈、凑近看看两个无声action候选。720×1280/24fps。沿用本次已授权预算与工具,先做代表样本。输出到指定新目录;暂不导入App。
|
||||
|
||||
这个例子没有给出预算,不构成付费额度授权。实际执行依据当前会话已存在的额度;未存在时先做非付费工作并请求必要信息。
|
||||
|
||||
输出brief应写清“能完成到哪一层”:只video、video+预览、完整嘴层候选、或实际生产parser通过。发现工具欠缺时给出缺失能力及可交付范围,不把“有imagegen/video-gen”误写成“已经具备完整导出器”。
|
||||
@@ -0,0 +1,49 @@
|
||||
# 制作与视觉验收
|
||||
|
||||
## 参考和anchor
|
||||
|
||||
单张全身图足以开始有限动作候选,不保证任意角度身份、背面细节或全部动作一致。先固定一张用户认可的全身anchor,记录参考SHA、构图、背景与形象约束。图像工具支持参考编辑时直接用原参考;不要靠重新描述prompt替代reference conditioning。
|
||||
|
||||
需要补足构图或服装时标成新设计候选。默认镜头固定、人物全头脚且有活动余量;凑近动作可以主动改变人物在画面中的大小,实际审核脸部透视和返回一致性。2D视频是有限动画片段,不是可任意旋转的3D角色。
|
||||
|
||||
## 工具适配
|
||||
|
||||
- 查询当前工具的真实schema,使用其reference/image-to-video能力,不写死某平台参数、费用或模型。
|
||||
- 起止帧约束可帮助loop/返回,但结果要实测和原速审核。只有首帧约束的工具仍可做候选;不能据此宣称末帧已匹配。
|
||||
- 原始生成master只读保留。创建无声、统一shape/fps/timebase的运行derivative,记录方法和SHA;处理后的身份或运动是否改变另审。
|
||||
- 嘴层可以使用已验证的本地跟踪/图像变形与合成脚本。每次使用前确认输入body、坐标、五档和alpha契约一致。没有现成脚本时可在授权输出目录开发并验证;原理描述不能充当实际导出的N×5文件。
|
||||
- 不为媒体查看或全速预览额外调用付费模型。人类未看的项目记not_run。
|
||||
|
||||
## Idle / 会话body
|
||||
|
||||
制作闭嘴、无音轨的细微身体循环。neutral、表情、呼吸/姿态变体各自独立body,不能只改标签。固定最终video后full decode,记录actual N/PTS/duration/fps/SHA,审核多个原速循环及接缝附近运动。
|
||||
|
||||
先做一个代表neutral及嘴层。质量或工具能力未确定时,优先小样暴露问题,不预先整批扩变体。用户已认可的设计和已授权流程可继续,不重复索要相同确认。
|
||||
|
||||
## TALK嘴层
|
||||
|
||||
每个最终body帧跟踪自身嘴位置,输出五档RGBA patch。开口层体现几何变化,空间alpha只做边缘融合;不能用一张大开口PNG的透明度变化冒充五档。低档贴合唇形,高档在手机比例可辨;最大幅度按本批样本审核,不继承历史“1.1像素”或“1.7”等孤立数值。
|
||||
|
||||
逐帧检查皮肤/唇线/嘴角接缝、露齿、脸部运动跟踪、边界hits、闭嘴恢复;数值boundary hits0不能替代肉眼看嘴角伪影。分别提供全身比例及脸部近景。
|
||||
|
||||
嘴状态opening/talk1/talk2/end-talk的曲线与body动画时钟独立。预览覆盖短句、连续长句、间断、切桥中开始讲话。若使用合成音量包络,只写“模拟TALK”,不能声称App实际TTS或手机通过。
|
||||
|
||||
## 桥
|
||||
|
||||
每个新增会话body需fallback双向路径和自loop。以各自实际frame/PTS绑定进出;审核身体位置、姿态、速度、光照、背景连续性。只让首末图像相似仍可能产生中途漂移或速度突变。
|
||||
|
||||
会话能走到的非native桥也生成桥自身N×5嘴层。不能用endpoint的patch,不能为避免嘴层问题把全会话TALK关闭。真实missing mouth交silent-only状态和缺口。
|
||||
|
||||
## 无声action
|
||||
|
||||
交完整单视频“neutral实际锚点→进入→动作→返回neutral实际锚点”。转圈保持脸/服装/肢体身份;凑近保持固定镜头、角色靠近/停留/退回的意图和透视稳定;挥手/鞠躬检查手指、肢体、收势。
|
||||
|
||||
不讲话、不模拟连续台词口型;允许微笑、露齿、自然张嘴。全程无音乐、对白、音效或静音音轨。动作不生成外叠TALK嘴层。
|
||||
|
||||
种类和变体分开记录。同一kind可多个version/variant;具体枚举及导出格式以目标runtime合同为准。当前baji无声新kind未实现,交独立候选+timing+source/return绑定,不写成已准入action。
|
||||
|
||||
## 修改与冻结
|
||||
|
||||
技术拒绝先修确定字段/引用,视觉问题先记具体clip/帧范围/现象。已有视频可确定性修复时不用新生成;修改只写新revision。变化影响body bytes/PTS时,重新核验自身patch与所有edge绑定。
|
||||
|
||||
固定媒体→写runtime→算runtime SHA→更新index引用和全部文件SHA/bytes→index最后冻结→外置index SHA。交原速预览、接缝密集帧、全身/脸部视图和机器报告。机器过、视觉过、App导入、手机/GPU各自说明;source/音乐权利未核实则unknown,不自创审核锚点或批准状态。
|
||||
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only silent H264 timing audit; no generation, tracking or runtime approval."""
|
||||
import argparse
|
||||
from decimal import Decimal, ROUND_HALF_EVEN
|
||||
from fractions import Fraction
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
class AuditError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def require(value, reason):
|
||||
if not value:
|
||||
raise AuditError(reason)
|
||||
|
||||
|
||||
def file_sha(path):
|
||||
with path.open('rb') as stream:
|
||||
digest = hashlib.sha256()
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b''):
|
||||
digest.update(block)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def microseconds(value):
|
||||
return int((Decimal(str(value)) * 1_000_000).to_integral_value(rounding=ROUND_HALF_EVEN))
|
||||
|
||||
|
||||
def audit(video, role, width, height, fps, ffprobe, ffmpeg):
|
||||
before = file_sha(video)
|
||||
result = subprocess.run([
|
||||
ffprobe, '-v', 'error', '-show_entries',
|
||||
'stream=codec_type,codec_name,width,height,r_frame_rate,duration:stream_disposition=attached_pic:frame=media_type,best_effort_timestamp_time',
|
||||
'-show_streams', '-show_frames', '-of', 'json', str(video),
|
||||
], capture_output=True, timeout=60)
|
||||
require(result.returncode == 0, 'ffprobe_failed')
|
||||
data = json.loads(result.stdout)
|
||||
streams = data['streams']
|
||||
require(len(streams) == 1 and streams[0]['codec_type'] == 'video', 'requires_single_video_no_audio')
|
||||
stream = streams[0]
|
||||
require(stream['codec_name'] == 'h264' and not stream.get('disposition', {}).get('attached_pic', 0), 'requires_normal_h264')
|
||||
require((stream['width'], stream['height']) == (width, height), 'shape_mismatch')
|
||||
actual_fps = Fraction(stream['r_frame_rate'])
|
||||
require(actual_fps == fps and 1 <= actual_fps <= 60, 'fps_mismatch')
|
||||
frames = [frame for frame in data['frames'] if frame.get('media_type') == 'video']
|
||||
pts = [microseconds(frame['best_effort_timestamp_time']) for frame in frames]
|
||||
limit = 5400 if role == 'action' else 720
|
||||
duration = microseconds(stream['duration'])
|
||||
require(2 <= len(pts) <= limit, 'frame_count_bound')
|
||||
require((1_000_000 if role == 'action' else 100_000) <= duration <= (90_000_000 if role == 'action' else 30_000_000), 'duration_bound')
|
||||
require(pts[0] == 0 and pts[-1] < duration and all(a < b for a, b in zip(pts, pts[1:])), 'invalid_actual_pts')
|
||||
period = Fraction(1_000_000, 1) / fps
|
||||
require(abs(Fraction(duration) - len(pts) * period) <= period + 2 and
|
||||
duration - pts[-1] <= 2 * period + 2 and
|
||||
all(b - a <= 2 * period + 2 for a, b in zip(pts, pts[1:])), 'timeline_inconsistent')
|
||||
decoded = subprocess.run([
|
||||
ffmpeg, '-nostdin', '-v', 'error', '-xerror', '-i', str(video),
|
||||
'-map', '0:v:0', '-f', 'null', '-',
|
||||
], capture_output=True, timeout=60)
|
||||
require(decoded.returncode == 0, 'full_decode_failed')
|
||||
require(file_sha(video) == before, 'source_drift')
|
||||
return {
|
||||
'status': 'passed', 'scope': 'silent_media_only_not_runtime_admission',
|
||||
'source_file': video.name, 'role': role, 'sha256': before, 'bytes': video.stat().st_size,
|
||||
'codec': 'h264', 'width': width, 'height': height, 'frameCount': len(pts),
|
||||
'ptsUs': pts, 'durationUs': duration, 'fpsNumerator': fps.numerator,
|
||||
'fpsDenominator': fps.denominator, 'hasAudio': False, 'streams': 1,
|
||||
'full_decode': 'passed', 'talking_visual_review': 'not_run',
|
||||
'seam_review': 'not_run', 'production_parser': 'not_run', 'device': 'not_run',
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--video', type=Path, required=True)
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
parser.add_argument('--role', choices=('body', 'bridge', 'action'), required=True)
|
||||
parser.add_argument('--width', type=int, default=720)
|
||||
parser.add_argument('--height', type=int, default=1280)
|
||||
parser.add_argument('--fps', default='24')
|
||||
parser.add_argument('--ffprobe', default='ffprobe')
|
||||
parser.add_argument('--ffmpeg', default='ffmpeg')
|
||||
args = parser.parse_args()
|
||||
video = args.video.resolve(strict=True)
|
||||
output = args.output.resolve()
|
||||
require(video.is_file(), 'source_not_file')
|
||||
require(not output.exists() and not output.is_relative_to(video.parent), 'fresh_evidence_outside_media_directory_required')
|
||||
require((args.width, args.height) in ((720, 1280), (480, 848)), 'unsupported_target_shape')
|
||||
try:
|
||||
fps = Fraction(args.fps)
|
||||
require(1 <= fps <= 60, 'invalid_target_fps')
|
||||
report = audit(video, args.role, args.width, args.height, fps, args.ffprobe, args.ffmpeg)
|
||||
except AuditError as error:
|
||||
report = {'status': 'rejected', 'scope': 'silent_media_only_not_runtime_admission', 'reason': str(error)}
|
||||
except FileNotFoundError:
|
||||
report = {'status': 'not_run', 'reason': 'required_media_tool_missing'}
|
||||
except subprocess.TimeoutExpired:
|
||||
report = {'status': 'rejected', 'reason': 'media_tool_timeout'}
|
||||
except (KeyError, ValueError, TypeError, ArithmeticError):
|
||||
report = {'status': 'rejected', 'reason': 'invalid_probe_metadata_or_target_fps'}
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
with output.open('x') as target:
|
||||
json.dump(report, target, indent=2)
|
||||
target.write('\n')
|
||||
print(json.dumps({key: value for key, value in report.items() if key != 'ptsUs'}))
|
||||
return 0 if report['status'] == 'passed' else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
raise SystemExit(main())
|
||||
except (AuditError, OSError) as error:
|
||||
print(json.dumps({'status': 'rejected', 'reason': str(error) if isinstance(error, AuditError) else 'file_operation_failed'}))
|
||||
raise SystemExit(1)
|
||||
@@ -0,0 +1,95 @@
|
||||
"""Finite synthetic-media checks; no AI, portraits, device or network access."""
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).with_name('audit-silent-video.py')
|
||||
FFMPEG = os.environ.get('AVATAR_AUDIT_FFMPEG') or shutil.which('ffmpeg')
|
||||
FFPROBE = os.environ.get('AVATAR_AUDIT_FFPROBE') or shutil.which('ffprobe')
|
||||
|
||||
|
||||
@unittest.skipUnless(FFMPEG and FFPROBE, 'ffmpeg/ffprobe required for synthetic media integration tests')
|
||||
class MediaAuditTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.temp = tempfile.TemporaryDirectory(prefix='avatar-skill-test-')
|
||||
cls.root = Path(cls.temp.name)
|
||||
cls.media = cls.root/'media'
|
||||
cls.media.mkdir()
|
||||
cls.silent = cls.media/'synthetic-silent.mp4'
|
||||
cls.audio = cls.media/'synthetic-with-aac.mp4'
|
||||
subprocess.run([FFMPEG, '-nostdin', '-v', 'error', '-f', 'lavfi', '-i',
|
||||
'color=c=gray:s=480x848:r=24', '-frames:v', '48', '-c:v', 'libx264',
|
||||
'-pix_fmt', 'yuv420p', '-an', str(cls.silent)], check=True, capture_output=True, timeout=30)
|
||||
subprocess.run([FFMPEG, '-nostdin', '-v', 'error', '-i', str(cls.silent),
|
||||
'-f', 'lavfi', '-i', 'anullsrc=r=48000:cl=mono',
|
||||
'-c:v', 'copy', '-c:a', 'aac', '-shortest', str(cls.audio)],
|
||||
check=True, capture_output=True, timeout=30)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.temp.cleanup()
|
||||
|
||||
def run_audit(self, source, name, *extra):
|
||||
output = self.root/(name+'.json')
|
||||
result = subprocess.run([sys.executable, str(SCRIPT), '--video', str(source),
|
||||
'--role', 'action', '--width', '480', '--height', '848',
|
||||
'--output', str(output), '--ffmpeg', FFMPEG, '--ffprobe', FFPROBE,
|
||||
*extra], capture_output=True, text=True, timeout=30)
|
||||
return result, output
|
||||
|
||||
def test_silent_video_measures_actual_pts_and_keeps_review_unrun(self):
|
||||
result, output = self.run_audit(self.silent, 'silent')
|
||||
self.assertEqual(result.returncode, 0, result.stdout)
|
||||
report = json.loads(output.read_text())
|
||||
self.assertEqual(report['frameCount'], 48)
|
||||
self.assertEqual(len(report['ptsUs']), 48)
|
||||
self.assertEqual(report['ptsUs'][:4], [0, 41667, 83333, 125000])
|
||||
self.assertEqual(report['durationUs'], 2_000_000)
|
||||
self.assertFalse(report['hasAudio'])
|
||||
self.assertEqual(report['full_decode'], 'passed')
|
||||
self.assertEqual(report['production_parser'], 'not_run')
|
||||
self.assertEqual(report['talking_visual_review'], 'not_run')
|
||||
|
||||
def test_even_silent_aac_is_rejected(self):
|
||||
result, output = self.run_audit(self.audio, 'audio')
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(json.loads(output.read_text())['reason'], 'requires_single_video_no_audio')
|
||||
|
||||
def test_wrong_fps_and_shape_are_rejected(self):
|
||||
for name, extra, reason in (
|
||||
('fps', ['--fps', '30'], 'fps_mismatch'),
|
||||
('shape', ['--width', '720', '--height', '1280'], 'shape_mismatch'),
|
||||
):
|
||||
with self.subTest(name=name):
|
||||
result, output = self.run_audit(self.silent, name, *extra)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(json.loads(output.read_text())['reason'], reason)
|
||||
|
||||
def test_existing_evidence_cannot_be_overwritten(self):
|
||||
result, output = self.run_audit(self.silent, 'existing')
|
||||
self.assertEqual(result.returncode, 0)
|
||||
before = output.read_bytes()
|
||||
result, _ = self.run_audit(self.audio, 'existing')
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(output.read_bytes(), before)
|
||||
|
||||
def test_evidence_cannot_be_written_into_media_directory(self):
|
||||
result, output = self.run_audit(self.silent, 'unused', '--output', str(self.media/'report.json'))
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertFalse((self.media/'report.json').exists())
|
||||
|
||||
def test_missing_tool_is_not_a_pass(self):
|
||||
result, output = self.run_audit(self.silent, 'missing', '--ffprobe', str(self.root/'absent-ffprobe'))
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(json.loads(output.read_text())['status'], 'not_run')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user