MLT XML音视频合成问题:多轨结构错误排查与正确实现
Got it, let's break down why your MLT XML is throwing those state errors and get it sorted out step by step.
The Root Cause of Your Errors
Your broken XML places <multitrack> elements directly inside the top-level <playlist>, but MLT's structure rules don't allow this. The <multitrack> component (which handles syncing paired video and audio tracks) must be wrapped inside a <tractor> element. Tractors are MLT's core component for managing composite media playback—they handle the state of multitrack sessions, so skipping them leads to the "wrong state" and "invalid playlist end" errors you're seeing.
How the Correct XML Works
Looking at your working example, each audio-video pair is wrapped in a <tractor> that contains the <multitrack>. Those tractors are then placed inside the <playlist>, which tells MLT to play each composite (video + matched audio) sequence one after another in order.
Fixed XML Code
Here's the corrected version of your broken XML, following MLT's required structure:
<playlist> <!-- First composite: video0.mp4 synced with audio0.wav --> <tractor> <multitrack> <producer> <property name="resource">video0.mp4</property> </producer> <producer> <property name="resource">audio0.wav</property> </producer> </multitrack> </tractor> <!-- Second composite: video1.mp4 synced with audio1.wav --> <tractor> <multitrack> <producer> <property name="resource">video1.mp4</property> </producer> <producer> <property name="resource">audio1.wav</property> </producer> </multitrack> </tractor> </playlist>
Key Takeaways
- Tractors are non-negotiable for multitracks: Every
<multitrack>needs a parent<tractor>to manage its playback state properly. - Playlist controls sequence: The top-level
<playlist>orders the tractors, ensuring your composite clips play in the exact order you want. - Sync is automatic: MLT will sync the media in each multitrack by default, so your audio will line up perfectly with its matching video.
内容的提问来源于stack exchange,提问作者iter

