Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpegFrameRecorder encoding problem frame #2269

Open
openmotion opened this issue Aug 8, 2024 · 5 comments
Open

FFmpegFrameRecorder encoding problem frame #2269

openmotion opened this issue Aug 8, 2024 · 5 comments

Comments

@openmotion
Copy link

Hello
what is the format to encode a frame
i use the otaliastudios camera preview plugin for android
i get the frame in the addFrameProcessor function
the format of the frame is : 17

i get the bitmapbytes : final byte[] mdata = frame.getData();

and i put it directly the buffer
((ByteBuffer)yuvImage.image[0].position(0)).put(mdata);

but the video is black

i set the recorder with this parameters
recorder.setFormat("mp4");
recorder.setVideoCodecName("libopenh264");

i tried also to change
recorder.setPixelFormat();

thanks for your help

@saudet
Copy link
Member

saudet commented Aug 9, 2024

@openmotion
Copy link
Author

openmotion commented Aug 9, 2024

Maybe this class can help? http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/AndroidFrameConverter.html

if i get byte array directly from frame
final byte[] bitmapbytes = frame.getData();

and push
((ByteBuffer)yuvImage_javacv.image[0].position(0)).put(bitmapbytes);
recorder.record(yuvImage_javacv,getFormatPreview);

where getFormatPreview = 17 (ImageFormat.NV21)

i have this result

image

according to this documentation
https://natario1.github.io/CameraView/docs/frame-processing

The default is ImageFormat.YUV_420_888.
and the frame of javacv is set to
org.bytedeco.javacv.Frame.DEPTH_UBYTE
( yuvImage_javacv = new org.bytedeco.javacv.Frame(getWidthPreview, getHeightPreview, org.bytedeco.javacv.Frame.DEPTH_UBYTE, 2); )

if i must use this class : http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/AndroidFrameConverter.html
can you provide an example ?

thanks

@zhang22113
Copy link

也许这个课程可以帮忙?http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/AndroidFrameConverter.html

如果我直接从帧中获取字节数组 final byte[] bitmapbytes = frame.getData();

并推送 ((ByteBuffer)yuvImage_javacv.image[0].position(0)).put(bitmapbytes); recorder.record(yuvImage_javacv,getFormatPreview);

其中 getFormatPreview = 17 (ImageFormat.NV21)

我有这个结果

图像

根据此文档 https://natario1.github.io/CameraView/docs/frame-processing

默认是ImageFormat.YUV_420_888。 并且javacv的frame设置为 org.bytedeco.javacv.Frame.DEPTH_UBYTE ( yuvImage_javacv = new org.bytedeco.javacv.Frame(getWidthPreview, getHeightPreview, org.bytedeco.javacv.Frame.DEPTH_UBYTE, 2); )

如果我必须使用这个类:http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/AndroidFrameConverter.html 你能提供一个例子吗?

谢谢

请问您的这个问题解决了吗?或许我们能讨论一下

@openmotion
Copy link
Author

请问您的这个问题解决了吗?或许我们能讨论一下

my problem is not resolved

@zhang22113
Copy link

请问您的这个问题解决了吗?也许我们可以讨论一下

我的问题还没有解决

My situation is similar to yours, it seems to be due to compatibility issues with the front-end decoder. But I don't quite understand how FFmpeg.grabAVPacket is converted into H264 stream and Frame is converted into H264 stream. What's the difference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants