Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

android - MediaMuxer error "Failed to stop the muxer"

I'm encoding Camera preview data using MediaCodec with mime-type "video/avc" and passing the encoded data (video-only, no audio) to MediaMuxer. The muxer seems to run fine and creates a reasonably sized output file (i.e., gets larger the longer I record). However, when I try to stop the muxer I get the "Failed to stop the muxer" error:

10-21 10:39:40.755: E/AndroidRuntime(2166): Caused by: java.lang.IllegalStateException: Failed to stop the muxer

There are some suspicious MPEG4Writer log messages preceding the failed stop:

10-21 10:39:40.740: D/MPEG4Writer(2166): Stopping Video track
10-21 10:39:40.740: E/MPEG4Writer(2166): Missing codec specific data
10-21 10:39:40.740: W/MPEG4Writer(2166): 0-duration samples found: 122
10-21 10:39:40.740: I/MPEG4Writer(2166): Received total/0-length (123/1) buffers and encoded 123 frames. - video
10-21 10:39:40.740: D/MPEG4Writer(2166): Stopping Video track source
10-21 10:39:40.740: D/MPEG4Writer(2166): Video track stopped
10-21 10:39:40.740: D/MPEG4Writer(2166): Stopping writer thread
10-21 10:39:40.740: D/MPEG4Writer(2166): 0 chunks are written in the last batch
10-21 10:39:40.740: D/MPEG4Writer(2166): Writer thread stopped
10-21 10:39:40.740: E/MPEG4Writer(2166): writer error ended!

Any clues what is causing this? Not sure what more info you'll need.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
E/MPEG4Writer(2166): Missing codec specific data

Sounds like you didn't call MediaMuxer#addTrack() with a MediaFormat that included the CSD. See the EncodeAndMuxTest.java code for an example of how to do this.

Looking at the MPEG4Writer implementation used by MediaMuxer, there's an isTrackMalformed() check on line 2360; it sets ERROR_MALFORMED if the CSD data isn't present, but doesn't return immediately. Nothing clears the error, so it'll do a bunch of work and then fail, which seems to match what you're seeing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...