简体   繁体   中英

Create video with encoded frames in Java

I have one application in Android (Java) that encodes frames that comes from a Camera.

Each frame is one array of bytes, that after being captured, was encoded with the API MediaCodec.

If i write the frames directly on a video file, i can open it with ffplay (not with another videoplayers as VLC), but it says for example:

Input #0, h263, from 'example.avi':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: h263, yuv420p, 640x480 [PAR 12:11 DAR 16:11], 25 fps, 25 tbr, 1200k tbn, 29.97 tbc
5.58 A-V:  0.000 s:0.0 aq=    0KB vq=    0KB sq=    0B f=0/0   0/0   

In other words, it doesnt recognise the duration, neither the bitrate.

I suppose that i have to write the metadata to the file but i have no idea how to do it.

As i said in the post, the application is being implemented with Java (with Android API), so i want to know how to add the metadata that makes the video players will recognice my video.

The output of MediaCodec is a raw H.264 stream. Starting with Android 4.3 (API 18), you can convert this stream to a .mp4 file by running it through the MediaMuxer class.

A related item, possibly of interest, is that you can now feed the camera's Surface preview to MediaCodec instead of passing YUV data through ByteBuffer. This approach requires less data copying and doesn't need a color plane swap.

See the CameraToMpegTest example here .

It's not an avi container, it is just h264 stream. Try to rename to "*.h264" and play with some player(vlc, mplayer).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM