CamcorderProfile.QUALITY_HIGH 分辨率产生绿色闪烁视频

发布于 2024-12-02 06:00:38 字数 506 浏览 2 评论 0原文

到目前为止我还没有找到任何解释。基本上,我有一个视频录制类,当我的三星 Galaxy S2 上的 setVideoSize() 设置为 720 x 480 时,它的工作效果非常好。

我希望它以尽可能高的分辨率进行录制,因此使用 CamcorderProfile.QUALITY_HIGH 我可以获得各种最高质量的录制属性并将它们设置在我的类中。这适用于文件格式、视频帧速率、编码器和比特率,但是当我尝试将视频大小设置为 CamcorderProfile (1920 x 1080) 返回的宽度和高度时,录制的视频只是绿色闪烁。

我注意到如果我将 720 x 480 更改为 720 x 481,也会发生同样的事情。因此,我只能假设当手机不支持分辨率时会发生这种情况。然而,手机附带的摄像机可以以 1920 x 1080 的分辨率进行录制,并且录制效果非常出色。

我只能假设,在如此高分辨率的情况下,我需要以不同的方式设置一些其他参数,但我只是无法弄清楚它们可能是什么。

还有其他人遇到过这个问题吗?

预先感谢您的回复。

I haven't found any explanation for this so far. Basically I have a video recording class which works splendidly when setVideoSize() is set to 720 x 480 on my Samsung Galaxy S2.

I want it to record in the highest possible resolution so using CamcorderProfile.QUALITY_HIGH I can get the various highest quality recording properties and set them within my class. This works for file format, video frame rate, encoders and bit rate, however when I attempt to set the video size to the width and height returned by the CamcorderProfile (1920 x 1080), the video recorded is just a green flicker.

I noticed if I changed 720 x 480 to 720 x 481 it did the same thing. Therefore I can only assume this happens when the resolution isn't supported by the phone. However, the camcorder the phone came with can record in 1920 x 1080 and it produces an excellent recording.

I can only assume with such a high resolution I need to set some other parameters differently, but I just cant figure out what they might be.

Has anyone else had this problem?

Thanks in advance for any replies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

︶ ̄淡然 2024-12-09 06:00:38

我遇到这个问题试图解决同样的问题。

xda开发者http://forum.xda给出了解决方案-developers.com/showthread.php?t=1104970&page=8。看来你需要设置一个模糊的参数“cam_mode”才能使高清录制工作:

camera = Camera.open();
Camera.Parameters param = camera.getParameters();
param.set( "cam_mode", 1 );     
camera.setParameters( param );

在mediarecorder中,你可以使用,

mediarecorder.setVideoSize(1920, 1080);

尽管现在这也可以工作:(

mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

后者似乎有20Mb/s的视频比特率,所以你可能想把它缩小一点!)我发现我不必将预览尺寸设置为 1920x1080。

(编辑)您还需要设置

parame.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);

param.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);

否则在相机启动之前会延迟几秒钟!

至于三星为什么要这样实现Camera,我不知道。这肯定对开发者不友好!

I came across this question trying to solve the same problem.

A solution is given over on xda developer http://forum.xda-developers.com/showthread.php?t=1104970&page=8. It seems that you need to set an obscure parameter "cam_mode" for high definition recording to work:

camera = Camera.open();
Camera.Parameters param = camera.getParameters();
param.set( "cam_mode", 1 );     
camera.setParameters( param );

In mediarecorder, you can then use

mediarecorder.setVideoSize(1920, 1080);

although this will now also work:

mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

(The latter seems to have a video bitrate of 20Mb/s, so you might want to take that down a bit!) I found that I didn't have to set the preview size to 1920x1080.

(edit) You also need to set

parame.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);

or

param.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);

otherwise you get a delay of a few seconds before the camera starts!

As to why Samsung has implemented the Camera in this way, I have no idea. It's certainly not developer friendly!

陪你搞怪i 2024-12-09 06:00:38

以下是我如何在 Samsung Galaxy S2 上实现此功能。这里的关键点是在相机参数和录像机视频尺寸中设置相同的分辨率。另外,已经提到的“cam_mode”黑客是必需的。因此,我允许用户从三种质量模式中进行选择:低(800x480)、中(1280x720)和高(1920x1080):

enum InternalCameraQuality {
    LOW, MEDIUM, HIGH
}

并且在创建/填充相机和录像机时我做了

// signature types are irrelevant here
File start(DeviceHandler handler, FileHelper fh) throws IOException {
    file = fh.createTempFile(".mp4");

    camera = Camera.open();
    setCameraParameters(camera);
    camera.setPreviewDisplay(getHolder());
    camera.unlock();

    recorder = new MediaRecorder();
    recorder.setCamera(camera);
    setRecorderParameters(recorder);

    recorder.prepare();
    recorder.start();

    return file;
}

void setCameraParameters(Camera camera) {
    Camera.Parameters param = camera.getParameters();

    // getParams() simply returns some field holding configuration parameters
    // only the 'quality' parameter is relevant here
    if (getParams().quality != InternalCameraQuality.LOW) {
        // Samsung Galaxy hack for HD video
        param.set("cam_mode", 1);
    }

    Pair<Integer, Integer> resolution = getResolution(getParams().quality);
    param.setPreviewSize(resolution.first, resolution.second);
    param.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);

    camera.setParameters(param);
}

void setRecorderParameters(MediaRecorder recorder) {
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    Pair<Integer, Integer> resolution = getResolution(getParams().quality);

    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    profile.videoFrameWidth = resolution.first;
    profile.videoFrameHeight = resolution.second;
    recorder.setProfile(profile);

    recorder.setOutputFile(file.getAbsolutePath());
    recorder.setPreviewDisplay(getHolder().getSurface());
}

Pair<Integer, Integer> getResolution(InternalCameraQuality quality) {
    final int width, height;
    switch (quality) {
        case LOW:
            width = 800;
            height = 480;
            break;
        case MEDIUM:
            width = 1280;
            height = 720;
            break;
        case HIGH:
            width = 1920;
            height = 1080;
            break;
        default:
            throw new IllegalArgumentException("Unknown quality: " + quality.name());
    }
    return Pair.create(width, height);
}

注意,您必须仅使用“cam_mode”黑客适用于中、高质量模式,否则低质量模式下会出现绿色闪烁。此外,如果需要,您可能希望自定义一些其他配置文件设置。

希望,这有帮助。

Here is how I managed to make this work on Samsung Galaxy S2. The critical point here is to set the same resolution both in camera parameters and recorder video size. Also, already mentioned 'cam_mode' hack is required. So, I allowed a user to select from three quality modes: low (800x480), medium(1280x720), and high(1920x1080):

enum InternalCameraQuality {
    LOW, MEDIUM, HIGH
}

and when creating/populating camera and recorder I did

// signature types are irrelevant here
File start(DeviceHandler handler, FileHelper fh) throws IOException {
    file = fh.createTempFile(".mp4");

    camera = Camera.open();
    setCameraParameters(camera);
    camera.setPreviewDisplay(getHolder());
    camera.unlock();

    recorder = new MediaRecorder();
    recorder.setCamera(camera);
    setRecorderParameters(recorder);

    recorder.prepare();
    recorder.start();

    return file;
}

void setCameraParameters(Camera camera) {
    Camera.Parameters param = camera.getParameters();

    // getParams() simply returns some field holding configuration parameters
    // only the 'quality' parameter is relevant here
    if (getParams().quality != InternalCameraQuality.LOW) {
        // Samsung Galaxy hack for HD video
        param.set("cam_mode", 1);
    }

    Pair<Integer, Integer> resolution = getResolution(getParams().quality);
    param.setPreviewSize(resolution.first, resolution.second);
    param.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);

    camera.setParameters(param);
}

void setRecorderParameters(MediaRecorder recorder) {
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    Pair<Integer, Integer> resolution = getResolution(getParams().quality);

    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    profile.videoFrameWidth = resolution.first;
    profile.videoFrameHeight = resolution.second;
    recorder.setProfile(profile);

    recorder.setOutputFile(file.getAbsolutePath());
    recorder.setPreviewDisplay(getHolder().getSurface());
}

Pair<Integer, Integer> getResolution(InternalCameraQuality quality) {
    final int width, height;
    switch (quality) {
        case LOW:
            width = 800;
            height = 480;
            break;
        case MEDIUM:
            width = 1280;
            height = 720;
            break;
        case HIGH:
            width = 1920;
            height = 1080;
            break;
        default:
            throw new IllegalArgumentException("Unknown quality: " + quality.name());
    }
    return Pair.create(width, height);
}

Note that you must use the 'cam_mode' hack only for medium and high quality, otherwise green flickering will appear in low quality mode. Also you may wish to customize some other profile settings if you need.

Hope, that helped.

紫瑟鸿黎 2024-12-09 06:00:38
        List<Size> ls = parameters.getSupportedPreviewSizes();
        Size size = ls.get(1);
        sizes 1 ----------960 720
        sizes 2 ----------800 480
        sizes 3 ----------720 480
        sizes 5 -----------640 384
        sizes 6 ----------576 432
        sizes 7 ----------480 320

这是 Android 中的尺寸和更多内容列表。

        List<Size> ls = parameters.getSupportedPreviewSizes();
        Size size = ls.get(1);
        sizes 1 ----------960 720
        sizes 2 ----------800 480
        sizes 3 ----------720 480
        sizes 5 -----------640 384
        sizes 6 ----------576 432
        sizes 7 ----------480 320

this are the list of sizes and more in android.

寂寞美少年 2024-12-09 06:00:38

好的,我测试了许多变体,唯一在真实设备上运行良好的版本是:

CamcorderProfile camcorderProfile    = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

// THREE_GPP works well but only on Phones            
//  camcorderProfile.fileFormat = MediaRecorder.OutputFormat.THREE_GPP;

// so better you use MPEG_4 for most Devices and PC
camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.MPEG_4_SP;

mrec.setProfile(camcorderProfile);

Ok, I tested many variants and the only Version wich works well on real Devices is:

CamcorderProfile camcorderProfile    = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

// THREE_GPP works well but only on Phones            
//  camcorderProfile.fileFormat = MediaRecorder.OutputFormat.THREE_GPP;

// so better you use MPEG_4 for most Devices and PC
camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.MPEG_4_SP;

mrec.setProfile(camcorderProfile);
风月客 2024-12-09 06:00:38

我过去也遇到过类似的问题。
您所做的似乎很好,但这里有一些可能有助于调试问题的建议:

确保您选择支持的分辨率

int cameraId = 0; // using back facing camera
Camera camera = Camera.open(cameraId);
Camera.Parameters cameraParams = camera.getParameters();
List<Camera.Size> supportedPreviewSizes = cameraParams.getSupportedPreviewSizez();

// find suitable Camera preview size from list and set your CamcorderProfile to use that new size

找到合适的预览尺寸后,请务必重置 SurfaceView - 您将需要调整其大小以适应宽高比的变化

MediaRecorder API 使用 SurfaceView,因此如果您的表面视图配置不正确,将会导致您看到绿色闪烁

确保您使用的视频比特率可以支持新的分辨率-- 尝试将视频比特率提高一倍它最初的设置是什么(*注意这会极大地影响您的输出文件大小)

CamcorderProfile.QUALITY_HIGH 返回可能支持的最高相机分辨率。确保您使用正确的摄像头 ID(前置与后置)——也许后置摄像头支持 1080p,但前置摄像头不支持?

希望提示有帮助!

I've experienced similar problems like this in the past.
What you're doing seems to be fine but here are a few suggestions that might help to debug the problem:

Ensure you are selecting a supported resolution

int cameraId = 0; // using back facing camera
Camera camera = Camera.open(cameraId);
Camera.Parameters cameraParams = camera.getParameters();
List<Camera.Size> supportedPreviewSizes = cameraParams.getSupportedPreviewSizez();

// find suitable Camera preview size from list and set your CamcorderProfile to use that new size

After you've located a suitable preview size be sure to reset your SurfaceView -- you will need to resize it to accommodate the change in aspect ratio

MediaRecorder API uses the SurfaceView so if your surface view isn't configured correctly it will result in the green flicker you're seeing

Ensure you are using a video bit rate that can support the new resolution -- try bumping the video bit rate to double what it was originally set to (*note this drastically effects your output filesize)

CamcorderProfile.QUALITY_HIGH returns the highest possible supported camera resolution. Ensure you are using the correct camera id (front vs. back) -- maybe the back facing camera supports 1080p but the front facing camera does not?

Hope the tips help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文