javaCV Android,流到rtmp服务器时叠加上的奇怪颜色 [英] javaCV Android, Strange colors on overlay while streaming to rtmp server

查看:237
本文介绍了javaCV Android,流到rtmp服务器时叠加上的奇怪颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Android直播到Facebook.我能够将现有示例改编为FB流.

I wanna stream to facebook live from android. I was able to adapt an existing example for streaming to FB.

第一步或多或少有效(音频仍然是一个问题,但不在她的范围内).我可以流到FB.

That first step more or less works (audio is still a problem, but not in the scope her). I can stream to FB.

我现在想用透明的png图像覆盖流.

I now wanna overlay the stream with a transparent png image.

我正在通过以下方式创建FFmpegFrameFilter:

I am creating a FFmpegFrameFilter on start up by:

try{
    filter = new FFmpegFrameFilter("movie="+path+"/image.png [logo];[in][logo]overlay=0:0:format=rgb [out]",imageWidth, imageHeight);
    filter.start();
}catch (FrameFilter.Exception e){
    Log.e(CLASS_LABEL,"Error while starting filter: "+e.getMessage());
    e.printStackTrace();
}

在每个帧上我都执行以下操作:

and on each frame i do the following:

filter.push(yuvImage);

Frame frame;
while ((frame = filter.pull()) != null) {
    recorder.record(frame,avutil.AV_PIX_FMT_NV21);
}

问题是我不知道应该使用哪种像素格式. 我的重叠图像具有rgb颜色( https://postimg.org/image/f1ri3vj43/)

The problem is that i have no idea which pixel format i should use. My overlay image has rgb colors (https://postimg.org/image/f1ri3vj43/)

使用上述像素格式,我得到的是这样的内容: https://postimg.org/image/45ha64q9z /

With the above pixel format i get something like this: https://postimg.org/image/45ha64q9z/

由于我已经尝试了许多像素格式,因此我感到非常沮丧.所有这些都具有不同的输出,有时徽标会多次出现.

I am pretty frustrated since i already tried many pixel formats. All with a different output, sometimes the logo appears multiple times.

是否有办法从avutil.java可能性中找出应该选择的一个?

Is there a way to find out which one i should choose from the avutil.java possibilities?

您可以在我已经尝试过以下格式:

I allready tried the following formats:

// AV_PIX_FMT_ARGB --> 4 at once, all black/white
// AV_PIX_FMT_0RGB --> 4 at once, all black/white
// AV_PIX_FMT_BGR8 --> 1 a bit to big, strange colors
// AV_PIX_FMT_BGR4_BYTE --> 1 a bit to big, stranger blue tint
// AV_PIX_FMT_YUVA422P_LIBAV --> error: Cannot initialize the conversion context.
// AV_PIX_FMT_FLAG_ALPHA --> error: Cannot initialize the conversion context.
// AV_PIX_FMT_FLAG_PLANAR --> error: Cannot initialize the conversion context.
// AV_PIX_FMT_RGB4 --> error: Cannot initialize the conversion context.
// AV_PIX_FMT_RGB32_1 --> 4 at a time, all black/white
// AV_PIX_FMT_0BGR --> 4 at a time, all black/white
// AV_PIX_FMT_YVYU422 --> 2 side by side, gruen, purple tint
// AV_PIX_FMT_YUVJ422P --> Fatal signal 11 (SIGSEGV) at 0x61f7xf000 (code=1), thread 18401 (e.yannick.olay1)
// AV_PIX_FMT_BAYER_BGGR8 --> 1 a bit to big, black/white
// AV_PIX_FMT_BAYER_GBRG8 --> 1 a bit to big, black/white
// AV_PIX_FMT_FLAG_RGB --> 2 a bit to big, black/white
// AV_PIX_FMT_RGB555LE --> 2 a bit to big, strange colors
// AV_PIX_FMT_RGB555BE --> 2 a bit to big, strange colors
// AV_PIX_FMT_RGB555 --> 2 a bit to big, strange colors
// AV_PIX_FMT_RGB4_BYTE --> 1 a bit to big, orange tint
// AV_PIX_FMT_RGBA64 --> 8 side by side, black/white
// AV_PIX_FMT_RGB24 --> 3 side by side, red tint

推荐答案

我知道了:

  1. 通过运行找出Android相机支持的格式

  1. Find out which formats your android camera supports by running

mCamera = Camera.open(); 
Camera.Parameters params = mCamera.getParameters(); 
for(int i: params.getSupportedPreviewFormats()) {
   Log.e(TAG, "preview format supported are = "+i);
}

您将获得一个整数列表.以我为例17和842094169. 我将使用842094169(YV12).因此,通过调用

You will get a list of Integers. In my case 17 and 842094169. I will go with 842094169 (YV12). So set your camera to that by calling

mCamera.getParameters().setPreviewFormat(ImageFormat.YV12);

  • 转到 https://developer.android.com/reference /android/graphics/ImageFormat.html 并检查如何正确定义支持的格式. 842094169是YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed by (W/2) x (H/2) Cr and Cb planes.

  • Goto https://developer.android.com/reference/android/graphics/ImageFormat.html and check how your supported formats are defined exactly. 842094169 is YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed by (W/2) x (H/2) Cr and Cb planes.

    转到 https://ffmpeg.org/ffmpeg-filters.html #overlay-1 并检查您要使用的过滤器,我的是重叠式过滤器.该过滤器提供了一个名为格式"的参数,将其设置为您从相机获得的最接近的格式(YV12不在列表中).在我的情况下是"yuv420". 过滤器现在看起来像这样:

    Goto https://ffmpeg.org/ffmpeg-filters.html#overlay-1 and check for your filter which you like to use, mine is the overlay filter. This filter provides a parameter called 'format', set it to the closest (YV12 is not in the list) you get from your camera. In my case 'yuv420'. The filter now looks like this:

    filter = new FFmpegFrameFilter("movie="+path+"/image.png [logo];[in][logo]overlay=0:0:format=yuv420 [out]",imageWidth, imageHeight);
    

  • 设置录制帧时的正确像素格式:

  • Set the correct pixel format while recording the frame:

    Frame frame;
    while ((frame = filter.pull()) != null) {
        Log.i(LOG_TAG,"In record-pull");
        recorder.record(frame,avutil.AV_PIX_FMT_YUV420P);
    }
    

  • 实际上,您必须将所有像素格式设置为相同.搜索所有站点以查找所有组件"都支持的格式有点棘手.

    In fact you must set all your pixelformats to the same. It is a little bit tricky to search throw all the sites to find a format which all your 'components' support.

    建议的替代方法是将YUV图像从相机转换为RGB图像.参见转换YUV-> RGB(图像处理)->在Android的onPreviewFrame期间是YUV吗?

    A suggested alternativ would be to convert the YUV image from the camera to a RGB image. See Converting YUV->RGB(Image processing)->YUV during onPreviewFrame in android?

    我没有尝试过,因为我教过这样做会很慢,并且首先尝试了一个简单的解决方案.

    I did not tried that because i taught this would to be to slow and tried a simpler solution first.

    这篇关于javaCV Android,流到rtmp服务器时叠加上的奇怪颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆