银河S3录制时的视频显示为乱码 [英] Video display is garbled when recording on Galaxy S3

查看:276
本文介绍了银河S3录制时的视频显示为乱码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个摄像头的应用程序,我有一个问题与S3。每当我开始录音,显示屏将垃圾(见下面的截图)。然后,当我停止记录我得到一个异常:

I'm writing a camera app and am having an issue with the S3. Whenever I start recording, the display goes to garbage (see screenshots below). Then, when I stop recording I get an exception:

10-02 13:36:31.647: E/MediaRecorder(24283): stop failed: -1007
10-02 13:36:31.647: D/AndroidRuntime(24283): Shutting down VM
10-02 13:36:31.647: W/dalvikvm(24283): threadid=1: thread exiting with uncaught exception (group=0x40c49a68)
10-02 13:36:31.647: E/AndroidRuntime(24283): FATAL EXCEPTION: main
10-02 13:36:31.647: E/AndroidRuntime(24283): java.lang.RuntimeException: stop failed.
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.media.MediaRecorder.native_stop(Native Method)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.media.MediaRecorder.stop(MediaRecorder.java:742)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at com.myapp.android.ui.camera.NewCameraActivity.stopRecording(NewCameraActivity.java:178)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at com.myapp.android.ui.camera.NewCameraActivity.toggleRecording(NewCameraActivity.java:189)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at com.myapp.android.ui.camera.NewCameraActivity.onClick(NewCameraActivity.java:97)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.view.View.performClick(View.java:3565)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.view.View$PerformClick.run(View.java:14165)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.os.Handler.handleCallback(Handler.java:605)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.os.Looper.loop(Looper.java:137)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at android.app.ActivityThread.main(ActivityThread.java:4514)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at java.lang.reflect.Method.invokeNative(Native Method)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at java.lang.reflect.Method.invoke(Method.java:511)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-02 13:36:31.647: E/AndroidRuntime(24283):    at dalvik.system.NativeStart.main(Native Method)

我对Galaxy Nexus的(4.1),银河S2,的Nexus S和Galaxy Tab的10.1测试我的应用程序。他们都很好地工作。我跟着视频录制 发展的指导方针。我不明白为什么这个装置是和别人那么不同。下面是我看到的设备。第一张照片是之前,我开始录制。第二张照片是,一旦我开始录制会发生什么。

I've tested my app on the Galaxy Nexus (4.1), Galaxy S2, Nexus S, and Galaxy Tab 10.1. All of them work fine. I've followed development guidelines for video recording. I don't understand why this device is so different from the others. Here's what I'm seeing on the device. First picture is before I start recording. Second picture is what happens once I start recording.

下面是我的code为preparing并启动 MediaRecorder 目标:

Here's my code for preparing and starting the MediaRecorder object:

@Override
public void onClick( View v ) {

    switch (v.getId()) {
        case R.id.camera_action_ImageView:
            int mode = getMode();
            if ( mode == MODE_PHOTO ) {
                focusThenTakePicture();
            }
            else if ( mode == MODE_VIDEO ) {
                toggleRecording();
            }
            break;
    }
}

private void startRecording() {

    if ( prepareRecorder() ) {
        getRecorder().start();
        setRecording( true );
    }
}

@TargetApi( 9 )
private boolean prepareRecorder() {

    Camera camera = getCamera();
    camera.unlock();

    MediaRecorder recorder = new MediaRecorder();
    setRecorder( recorder );
    recorder.setCamera( camera );
    recorder.setAudioSource( MediaRecorder.AudioSource.CAMCORDER );
    recorder.setVideoSource( MediaRecorder.VideoSource.CAMERA );

    CamcorderProfile profile;
    if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD ) {
        profile = CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH );
    }
    else {
        profile = CamcorderProfile.get( getCameraId(), CamcorderProfile.QUALITY_HIGH );
    }
    recorder.setProfile( profile );

    File outputFile = LocalMediaUtil.getOutputMediaFile( LocalMediaUtil.MEDIA_TYPE_VIDEO );
    setRecorderOutputFile( outputFile );
    recorder.setOutputFile( outputFile.toString() );
    recorder.setPreviewDisplay( getPreview().getHolder().getSurface() );

    try {
        recorder.prepare();
    }
    catch (Exception e) {
        camera.lock();
        setRecorder( null );
        return false;
    }

    return true;
}

private void stopRecording() {

    MediaRecorder recorder = getRecorder();
    recorder.stop();
    releaseRecorder();
    setRecording( false );

    LocalMediaUtil.scanMedia( this, getRecorderOutputFile().toString(), 90 );
    setRecorderOutputFile( null );
}

private void toggleRecording() {

    if ( isRecording() ) {
        stopRecording();
    }
    else {
        startRecording();
    }
}

private void releaseRecorder() {

    MediaRecorder recorder = getRecorder();
    if ( recorder != null ) {

        recorder.reset();
        recorder.release();
        setRecorder( null );

        getCamera().lock();
    }
}

编辑:所以这个事做的 CamcorderProfile 被设置。我将其更改为 CamcorderProfile.QUALITY_LOW 和它工作得很好。所以,我怎么能有高分辨率的视频没有乱码输出?

So this has something to do with the CamcorderProfile being set. I change it to CamcorderProfile.QUALITY_LOW and it worked fine. So how can I have high resolution video without garbled output?

EDIT2:因此,与 CamcorderProfile.QUALITY_LOW 设置,我得到使用视频记录没有错误。但是,输出视频看起来非常相似,上面的乱码截图公布。那么怎么办?

So with CamcorderProfile.QUALITY_LOW set, I get no errors using the video recorder. However, the output video looks very similar the garbled screenshot posted above. So what gives?

推荐答案

我也有类似的问题,终于想通了,这是由于共享相机和媒体记录器之间的preVIEW面(我不是确保这其实是根本原因,但是从API调用看来这种方式)。

I had a similar problem, and finally figured out it was due to sharing the preview surface between the camera and the media recorder (I'm not sure this is actually the underlying cause, but from the API calls it appears that way).

我假设你已经打开了摄像头,并附加了preVIEW显示它,如果是的话尽量在你的prepareRecorder方法的顶部插入以下行:

I'm assuming you have already opened the camera and attached a preview display to it, if so try inserting the following lines at the top of your prepareRecorder method:

Camera camera = getCamera();
camera.stopPreview();
camera.lock();
camera.release();

camera = Camera.open();
camera.unlock();

您可能还需要重新分配的摄像头本地的背后隐藏着对getCamera()领域,很遗憾我不能告诉你如何用给定的code段实现了。

You might also need to reassign the camera local to the field hidden behind getCamera(), unfortunately I can't tell how you've implemented it with the given code snippet.

希望这有助于。

这篇关于银河S3录制时的视频显示为乱码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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