5

I am using this library for recording video from a USB camera. The code I used is as follows:

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);
                }
        }
    };

The video recording works most of the time but sometimes an exception is thrown. Below is the output of 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

Any ideas?

chengsam
  • 7,315
  • 6
  • 30
  • 38
  • It;s completely unclear what you are asking. See [How to ask](http://stackoverflow.com/help/how-to-ask) page and try again. You should introduce reader into your problem, give a code sample and describe the exact problem. Nobody can realize what have you tried if you post only the error log with no code and problem description attached. – Vladimir Vagaytsev Jul 27 '16 at 11:20
  • Sorry, I've updated my question with code. – chengsam Jul 28 '16 at 02:03
  • 3
    Did you figure out what the problem was? I have faced the same issue. – Mike Sep 22 '16 at 13:48
  • @Mike Not yet, let me know also if you can solve the issue! :) – chengsam Sep 23 '16 at 04:02
  • @chengsam I observed that when some of the track has 0 frame written (In your case Received total/0-length (0/0) buffers and encoded 0 frames. - video) muxer can't stop. Though I didn't find a solution for this case as well. – Mike Sep 23 '16 at 07:24
  • @Mike Yes, I have no idea why no frame is received. – chengsam Sep 23 '16 at 08:43

0 Answers0