1
votes

I am writing an Android app where I plan to encode several images in to a live h.264 video stream that can be replayed on any browser. I am using the MediaCodec API for encoding and then MediaMuxer to write it to a file as per the example here http://bigflake.com/mediacodec/.

What I am stuck with is that how to tell the encoder/muxer to encode it such that it can be progressively played back. From the examples only when the encoder/muxer.stop()/encoder/muxer.release() call is made, then the video file gets the right meta headers, etc..

Thanks

1
you need to move the MPEG4 meta information from the end of file to the beginning see mithunme.wordpress.com/2009/11/04/streaming-mp4-via-http - skyde
The MediaMuxer class really wants to write a .mp4 file to disk. It's not suited to streaming. If what you're after is live-streaming an edited video feed from your app to a host browser, you need to sort out network video streaming protocols. But I'm not convinced I fully understand what you're after. - fadden

1 Answers

0
votes

I guess you are considering the time at which each frame is shown.

You need to give MediaMuxer, along with the frame, the right "MediaCodec.BufferInfo," whose "presentationTimeUs" is set accordingly.

For example, there are 3 frames, each is shown for 1 second in the video:

sec 0---------1---------2-----------
    frame1    frame2    frame3 


int[] timestampSec = {0, 1, 2};
for (int i = 0; i < 3; i++) {
    muxer.writeSampleData(trackId, 
                          frame[i], 
                          timeStampSec[i] * 1000000); 
}

As to initialization and ending of MediaMuxer:

  1. addTrack: when you get index == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED when you call MediaCodec.dequeueOutputBuffer(), send the format to MediaMuxer to initialize a new track for this format(it's "vidio/avc" in this case).

  2. mediamuxer.start()

  3. start put frames as above

  4. mediamuxer.stop(), release()