问题
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.
回答1:
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.
回答2:
I had the same issue .While closing the Muxer it was throwing "Failed to stop" error.When I checked my saved file in an ISO viewer I couldn't find the Track in it . I solved issue by creating the track only after getting the first output from the video encoder.Here is how I add my track
m_VideoTrackIndex = muxer.addTrack(mediaCodec.getOutputFormat());
The media format for the track is obtained from mediaCodec.getOutputFormat() which in turn will get initialized only after encoding the first frame.I changed my code to add the track after getting first encoded data (And of course only once).It is working fine .
回答3:
There are 2 Problems with Android 5.0.2 Devices Moto E 1) The Width & height if not supplied multiples of 16 its crashing 2) The mediaBuffer to be set after the First Frame is Encoded
来源:https://stackoverflow.com/questions/19505845/mediamuxer-error-failed-to-stop-the-muxer