Non-potential video file created using MediaMuxer

I use MediaCodecto encode video. Frames go through the camera preview callback to the instance MediaCodec(no usable surface). I use the JCodec library for multiplexing and I am able to stream the received video (the video player shows the correct duration and I can change the video position using the search bar).

Today I tried to use MediaMuxerinstead JCodecand I have a video that still looks good, but the duration is absolutely incorrect (several hours instead of one minute) and the search bar does not work at all.

mediaMuxer = new MediaMuxer("/path/to/video.mp4", MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

The following code is lazily called when I get MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:

videoTrackIndex = mediaMuxer.addTrack(encoder.getMediaFormat());
mediaMuxer.start();

I encode frames with the following code:

mediaMuxer.writeSampleData(videoTrackIndex, byteBuffer, bufferInfo);

byteBuffer bufferInfo MediaCodec :

byteBuffer.position(bufferInfo.offset);
byteBuffer.limit(bufferInfo.offset + bufferInfo.size);

:

mMediaCodec.queueInputBuffer(inputBufferIndex, 0, getWidth() * getHeight() * 1.5, System.nanoTime() / 1000, 0);

:

mediaMuxer.stop();
mediaMuxer.release();

Logs:

I/MPEG4Writer﹕ setStartTimestampUs: 0
I/MPEG4Writer﹕ Earliest track starting time: 0
D/MPEG4Writer﹕ Stopping Video track
I/MPEG4Writer﹕ Received total/0-length (770/0) buffers and encoded 770 frames. - video
D/MPEG4Writer﹕ Stopping Video track source
D/MPEG4Writer﹕ Video track stopped
D/MPEG4Writer﹕ Stopping writer thread
D/MPEG4Writer0 chunks are written in the last batch
D/MPEG4Writer﹕ Writer thread stopped
I/MPEG4Writer﹕ The mp4 file will not be streamable.
D/MPEG4Writer﹕ Stopping Video track

, The mp4 file will not be streamable. .

Update:

(LG G2), . . .

+4
1

@fadden . TimeUs = 0. , MediaCodec.BUFFER_FLAG_CODEC_CONFIG. , ( ):

if ((mBufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) {
  mBufferInfo.size = 0;
}
+5

Source: https://habr.com/ru/post/1542486/


All Articles