视频保存
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* 录制管线:
|
||||
* ┌─────────────┐ RTP/RTCP ┌──────────────┐ SDP+stdin ┌────────┐ fs ┌─────────┐
|
||||
* │ Producer X │ ───────────> │ PlainTransport│ ───────────────> │ ffmpeg │ ──────> │ *.mp4 │
|
||||
* │ Producer X │ ───────────> │ PlainTransport│ ───────────────> │ ffmpeg │ ──────> │ *.webm │
|
||||
* │ (audio/video)│ │ + Consumer │ (UDP loopback) │ (子进程)│ └─────────┘
|
||||
* └─────────────┘ └──────────────┘ └────────┘
|
||||
*
|
||||
@@ -95,7 +95,7 @@ interface RecordingEntry {
|
||||
ffmpeg: ChildProcess;
|
||||
/** SDP 临时文件 */
|
||||
sdpFilePath: string;
|
||||
/** 输出 mp4 文件 */
|
||||
/** 输出 webm 文件(VP8 + Opus 原生容器,-c copy 零重编码) */
|
||||
outputPath: string;
|
||||
/** ffmpeg 退出 promise,stop 时 await */
|
||||
ffmpegExited: Promise<void>;
|
||||
@@ -339,7 +339,10 @@ function buildSdp(tracks: RecordingTrack[], localIp: string): string {
|
||||
* -use_wallclock_as_timestamps 1:避免 RTP 时间戳跳变导致 mp4 时长异常
|
||||
* -c copy:不重编码,直接复用 RTP 载荷
|
||||
* - 优点:CPU 占用极低
|
||||
* - 缺点:浏览器侧 VP8 进 mp4 容器在某些播放器不支持;后续可改 libx264
|
||||
* - 限制:输出容器必须能装 VP8/Opus。mp4 muxer 不接受 VP8(ffmpeg 报
|
||||
* "Could not find tag for codec vp8" 后 exit code=1)。改用 webm 恶不必重编码
|
||||
* (VP8+Opus 是 webm 原生组合)。后续如需 mp4 可在 go-service 上传后异步 ffmpeg 转一次
|
||||
* -f webm:显式指定 webm muxer(依赖后缀推断也可,但显式更稳)
|
||||
* -y:覆盖已存在文件(防止 recordingId 碰撞)
|
||||
*/
|
||||
function buildFfmpegArgs(sdpFilePath: string, outputPath: string): string[] {
|
||||
@@ -360,6 +363,8 @@ function buildFfmpegArgs(sdpFilePath: string, outputPath: string): string[] {
|
||||
'0:v?',
|
||||
'-c',
|
||||
'copy',
|
||||
'-f',
|
||||
'webm',
|
||||
'-y',
|
||||
outputPath,
|
||||
];
|
||||
@@ -404,7 +409,8 @@ export async function startRecording(input: StartRecordingInput): Promise<StartR
|
||||
const id = recordingId();
|
||||
const startedAt = Date.now();
|
||||
const localIp = '127.0.0.1';
|
||||
const outputPath = join(OUTPUT_DIR, `${id}.mp4`);
|
||||
// 输出后缀 .webm:VP8 不能装进 mp4,webm 是 VP8+Opus 的原生容器,-c copy 零重编码
|
||||
const outputPath = join(OUTPUT_DIR, `${id}.webm`);
|
||||
const sdpFilePath = join(OUTPUT_DIR, `${id}.sdp`);
|
||||
|
||||
// 已分配资源,用于失败时回滚
|
||||
|
||||
Reference in New Issue
Block a user