組合 AI 影片片段前先檢查音訊串流
Check the audio stream before assembling AI video clips
組合 AI 影片片段前,先用 ffprobe 檢查輸入檔的音訊串流,避免因每個鏡頭都映射音訊而令可播放片段在渲染前失敗。探測失敗代表檔案無法檢查;探測成功但 streams 陣列為空,則表示沒有音訊串流。應按鏡頭用途訂明缺少音訊的處理方式,並把探測結果連同鏡頭 ID 保存,方便渲染失敗時查核。
AI video exports can mix clips with audio and clips with no audio stream at all. If your assembly job maps an audio stream for every shot, an otherwise playable clip can fail before the edit is rendered.
Inspect the file, then make a decision
Run this on one input before it enters the assembly queue:
ffprobe -v error -select_streams a:0 \
-show_entries stream=index,codec_name,sample_rate,channels \
-of json input.mp4
Check the command's exit status first. A failed probe means the file could not be inspected. A successful probe with an empty streams array means the selected audio stream is absent. A successful probe with a stream gives you its codec, sample rate, and channel count. It does not tell you whether that track contains silence.
To reproduce the missing-stream case without using production material, generate a one-second input without audio:
ffmpeg -v error -f lavfi -i color=c=black:s=360x640:r=24 \
-t 1 -an -c:v libx264 silent-shot.mp4
Then run the probe on silent-shot.mp4. Use a filename that does not already exist, or FFmpeg will prompt before replacing it.
Decide what a missing track means for each shot
For narration that will be mixed in later, a video-only shot may be fine. For a shot that is supposed to retain dialogue, send it back for review. If your assembly needs each input to have matching audio streams, normalize deliberate silence and real audio to the chosen sample rate and layout before concatenating. Make the policy explicit so that missing dialogue never gets silently replaced with silence.
Keep the probe result next to the shot ID. When a render fails, the person reviewing it can see whether the input was unreadable, missing a stream, or incompatible with the assembly settings.
Disclosure: I’m part of the AlphaDrama team. AI assisted with drafting this article.
來源:DEV Community · dev.to