javacv icon indicating copy to clipboard operation
javacv copied to clipboard

Is it possible to stream MediaCodec outputbuffer to FFmpegFrameRecorder?

Open MarsVard opened this issue 7 years ago • 9 comments

I'm trying to stream MediaCodec that records a surface over RTMP.

I understand that MediaCodec buffer is a raw h264 frame. How would I go about converting this to the correct format to feed to the FFmpegFrameRecorder?

MarsVard avatar Apr 06 '17 12:04 MarsVard

Most likely yes. Please try to use packets: https://github.com/bytedeco/javacv/issues/93

saudet avatar Apr 06 '17 13:04 saudet

@saudet Is there a working example of this?

MarsVard avatar Apr 06 '17 16:04 MarsVard

/cc @alicanalbayrak @Baobomb You guys have anything?

saudet avatar Apr 07 '17 00:04 saudet

Hi, @saudet !

Are there any updates on this question?

I googled around and found this project There MediaCodec and ffmpeg almost finely mixed together. I converted it into gradle based project and translated all ffmpeg calls to JNI calls using javaCV. And it work almost good: write long video with good stable fps. I still can't make it split video into ts files which seems like missconfiguration.

My first thought was to implement conversion between MediaCodec's output buffer and FFMpegFrameRecorder's input packet, but I have had no luck with that.

There you said it's needed to add a support for RAW (H264?) packets which seems to be exactly what I have tried to do.

I know this issue was pushed many times and I am sorry for doing it again but I am in real need in it. So I would greatly appreciate if you can kindly guid me or give an advice for next steps.

balbelias avatar Apr 19 '17 22:04 balbelias

@balbelias I'm sorry, I don't have any more information about that. That's why I labeled this issue with "help wanted". If you do put the effort into making this work, please consider making a contribution back! Thank you

saudet avatar Apr 23 '17 12:04 saudet

@saudet ok! I see, it's more about FFMPEG than JavaCV. But what did you mean by "add support for RAW packets"?

balbelias avatar Apr 23 '17 23:04 balbelias

Support for packets was added here: https://github.com/bytedeco/javacv/pull/372

saudet avatar Apr 24 '17 00:04 saudet

BTW, FFmpeg supports MediaCodec now and we should be able to use it easily like this, for example: https://github.com/bytedeco/javacv/issues/945#issuecomment-405795977

saudet avatar Jul 18 '18 03:07 saudet

But how to construct AVFormatContext from MediaCodec output format? The only suggestion that I've seen is to dump few frames into FFmpegFrameGrabber (https://github.com/OnlyInAmerica/FFmpegTest)

alexey-pelykh avatar Jul 29 '22 07:07 alexey-pelykh

@alexey-pelykh We can do it with FFmpeg for sure. Contributions are welcome!

saudet avatar Feb 20 '23 00:02 saudet

BTW, FFmpeg 6.0 now supports hardware accelerated encoding using MediaCodec, so we don't need to use its API directly anymore. Please give it a try with the snapshots: http://bytedeco.org/builds/

saudet avatar Mar 03 '23 12:03 saudet