本站消息

站长简介/公众号


站长简介:逗比程序员,理工宅男,前每日优鲜python全栈开发工程师,利用周末时间开发出本站,欢迎关注我的微信公众号:幽默盒子,一个专注于搞笑,分享快乐的公众号

  价值13000svip视频教程,java大神匠心打造,零基础java开发工程师视频教程全套,基础+进阶+项目实战,包含课件和源码

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Android MediaMuxer java.lang.IllegalStateException:无法停止复用器

发布于2021-06-12 09:25     阅读(663)     评论(0)     点赞(29)     收藏(3)


我正在使用这个库来录制来自 USB 摄像头的视频。我使用的代码如下:

try {
    private MediaMuxerWrapper mMuxer;
    mMuxer = new MediaMuxerWrapper("FolderName", ".mp4");
    new MediaVideoEncoder(mMuxer, mMediaEncoderListener);
    mMuxer.prepare();
    mMuxer.startRecording();
} catch (final IOException e) {

}

private final MediaEncoder.MediaEncoderListener mMediaEncoderListener = new MediaEncoder.MediaEncoderListener() {
        @Override
        public void onPrepared(final MediaEncoder encoder) {
            if (encoder instanceof MediaVideoEncoder)
                try {
                    mWeakCameraView.get().setVideoEncoder(encoder);
                } catch (final Exception e) {
                    Log.e(TAG, "onPrepared:", e);
                }
            if (encoder instanceof MediaSurfaceEncoder)
                try {
                    mWeakCameraView.get().setVideoEncoder(encoder);
 mUVCCamera.startCapture(((MediaSurfaceEncoder)encoder).getInputSurface());
                } catch (final Exception e) {
                    Log.e(TAG, "onPrepared:", e);
                }
        }

        @Override
        public void onStopped(final MediaEncoder encoder) {
            if ((encoder instanceof MediaVideoEncoder)
                    || (encoder instanceof MediaSurfaceEncoder))
                try {
                    final MainActivity parent = mWeakParent.get();
                    mWeakCameraView.get().setVideoEncoder(null);
                    mUVCCamera.stopCapture();
                } catch (final Exception e) {
                    Log.e(TAG, "onPrepared:", e);
                }
        }
    };

视频录制大部分时间都可以工作,但有时会引发异常。下面是 logcat 的输出:

D/MPEG4Writer(20994): Setting Video track to done
E/MPEG4Writer(20994): The number of recorded samples is 0
W/MPEG4Writer(20994): 0-duration samples found: 1
W/MPEG4Writer(20994): 0-duration samples found: 1
I/MPEG4Writer(20994): Received total/0-length (0/0) buffers and encoded 0 frames. - video
I/MPEG4Writer(20994): Received total/0-length (528/0) buffers and encoded 528 frames. - audio
I/MPEG4Writer(20994): Audio track drift time: 0 us
D/MPEG4Writer(20994): Setting Audio track to done
D/MPEG4Writer(20994): Stopping Video track
D/MPEG4Writer(20994): Stopping Video track source
D/MPEG4Writer(20994): Video track stopped
D/MPEG4Writer(20994): Stopping Audio track
D/MPEG4Writer(20994): Stopping Audio track source
D/MPEG4Writer(20994): Audio track stopped
D/MPEG4Writer(20994): Duration from tracks range is [0, 12084319] us
D/MPEG4Writer(20994): Stopping writer thread
D/MPEG4Writer(20994): 0 chunks are written in the last batch
D/MPEG4Writer(20994): Writer thread stopped
E/MediaEncoder(20994): failed stopping muxer
E/MediaEncoder(20994): java.lang.IllegalStateException: Failed to stop the muxer
E/MediaEncoder(20994):  at android.media.MediaMuxer.nativeStop(Native Method)
E/MediaEncoder(20994):  at android.media.MediaMuxer.stop(MediaMuxer.java:226)
E/MediaEncoder(20994):  at com.serenegiant.encoder.MediaMuxerWrapper.stop(MediaMuxerWrapper.java:149)
E/MediaEncoder(20994):  at com.serenegiant.encoder.MediaEncoder.release(MediaEncoder.java:234)
E/MediaEncoder(20994):  at com.serenegiant.encoder.MediaAudioEncoder.release(MediaAudioEncoder.java:98)
E/MediaEncoder(20994):  at com.serenegiant.encoder.MediaEncoder.run(MediaEncoder.java:154)
E/MediaEncoder(20994):  at java.lang.Thread.run(Thread.java:841)
D/MediaEncoder(20994): Encoder thread exiting

有任何想法吗?


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/221771/29df613e751216f38c26/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

29 0
收藏该文
已收藏

评论内容:(最多支持255个字符)