【问题标题】:Crash when calling mediaRecorder.stop() on samsung S2 using QUALITY_HIGH使用 QUALITY_HIGH 在三星 S2 上调用 mediaRecorder.stop() 时崩溃
【发布时间】:2013-11-17 10:16:27
【问题描述】:

我正在尝试使用 MediaRecorder 对象以我的设备三星 S2 上可用的最高质量录制视频。但是,使用我当前的代码,我在调用 MediaRecorder.close() 时看到挂起,然后手机崩溃(LOGCAT:http://pastebin.com/yzqWqta3

当 CamcorderProfile 设置为 QUALITY_LOW 时,我有一段工作代码,但同样的代码会导致设备崩溃(需要重新启动才能恢复),Camcorder Profile 更改为 QUALITY_HIGH。

camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);

之后设置为记录器对象;

recorder.setProfile(camcorderProfile);

但是,在调用 MediaRecorder.stop() 之后,以下内容会导致崩溃;

camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

我的代码基于这个项目(来自 Android Pro Media 人 - Shawn van Every)https://github.com/vanevery/Custom-Video-Capture-with-Preview.git

原始形式的代码也会导致记录器在Mediarecorder#start() 上崩溃(LOGCAT:http://pastebin.com/L2ahkj82),我不得不使用此线程中的建议来应用三星特定的修复; “ [Q] 无法在 Galaxy Sii 上录制高清视频”; http://forum.xda-developers.com/showthread.php?t=1104970&page=8

 Camera.Parameters p = camera.getParameters();

 // http://forum.xda-developers.com/showthread.php?t=1104970&page=8
 p.set( "cam_mode", 1 ); // green mess in video file without this
 p.setFocusMode(Parameters.FOCUS_MODE_AUTO);    // works  

 p.setPreviewSize(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight);
 p.setPreviewFrameRate(camcorderProfile.videoFrameRate);

 camera.setParameters(p);
 camera.setDisplayOrientation(0);

 camera.setPreviewDisplay(holder);
 camera.startPreview();

但是,使用上面的代码,我要么崩溃,要么应用停止响应; LOGCAThttp://pastebin.com/D7Ap7yQZ

检查设备对 1920/1080 或 QUALITY_HIGH 的支持情况

股票相机应用程序支持以 1920x1080 的分辨率录制,它称之为“超精细”,但分辨率是明确设置的,我猜想适当的参数是从已知的良好设置推断出来的,而不是从 QUALITY_HIGH CamcorderProfile 推断出来的。

但是,在 Play 商店中有 other apps 支持 1920x1080,可以在 S2 上运行来自 3rd 方(他们可能无法访问三星专有文档),因此应该可以通过设置每个来复制 QUALITY_HIGH显式参数化,或揭开三星未记录的 bf*ckery。

设备自检

三星 SII 似乎支持使用 QUALITY_HIGH;

Log.v(LOGTAG, "has Profile QUALITY HIGH? : "+ 
CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_HIGH));

返回这个;

V/VIDEOCAPTURE( 7897): has Profile QUALITY HIGH? : true

并且 Android 文档指出“QUALITY_HIGH”是一个预定义的配置文件,表示对应于最高可用分辨率的级别。

int   QUALITY_HIGH    Quality level corresponding to the highest available resolution.

http://developer.android.com/reference/android/media/CamcorderProfile.html#QUALITY_HIGH

注意事项

  1. 我今天早上将手机恢复出厂设置
  2. 我尝试了其他 SD 卡,但在同一个地方遇到了同样的崩溃
  3. 这可能是硬件问题。我还没有找到另一台三星 S2 进行测试。

相关的 SO 问题

还有其他关于在三星 S2 上录制高质量视频的 SO 问题,但没有一个答案,所以我创建了这个问题来捕获我的日志和代码

"Video recorded with Android MediaRecorder is corrupted on Samsung Galaxy S2"

Samsung Galaxy SIII mediaRecorder() issues. (Corrupt Video)

可能的解决方案

这个 SO question and answer 似乎解决了同样的问题,但我无法使用给出的代码示例复制他们的结果; CamcorderProfile.QUALITY_HIGH resolution produces green flickering video

有一个thread on xda的链接,里面有一些详细的分析

【问题讨论】:

    标签: android samsung-mobile mediarecorder android-mediarecorder


    【解决方案1】:

    可能是您的三星 S2 不支持高品质!
    参考这个post
    有一种方法可以迭代支持的配置文件,请在设置质量之前尝试这样做。

    【讨论】:

      【解决方案2】:

      here 和讨论 here 的帮助下,我设法从 Shawn Every 的“Android Pro Media”中获得了示例代码

      主要问题是使用三星无证参数废话,以及将 PreviewSize 设置为与视频帧大小相同;在下面评论;

      Camera.Parameters p = camera.getParameters();
      
      // Samsung Galaxy hack for HD video
      p.set("cam_mode", 1);
      
      // It is required to set the previewSize tto the same as the Video frame height x width
      p.setPreviewSize(camcorderProfile.videoFrameWidth,
                          camcorderProfile.videoFrameHeight);
      
      
      ...</snip>
      
      camera.setParameters(p);
      

      这里是示例代码,(由于模拟器限制,目前只能在真机上运行)

      https://github.com/tolland/Custom-Video-Capture-with-Preview

      生成具有这些属性的文件;

      $ mplayer -vo null -ao null -frames 0 -identify videocapture-2024713075.3gp | egrep "(ID_VID)"
      ...
      ID_VIDEO_ID=0
      ID_VIDEO_FORMAT=H264
      ID_VIDEO_BITRATE=13773800
      ID_VIDEO_WIDTH=1920
      ID_VIDEO_HEIGHT=1080
      ID_VIDEO_FPS=24.750
      ID_VIDEO_ASPECT=1.7778
      ID_VIDEO_CODEC=ffh264
      

      【讨论】:

      • 嗨 @Tom H,Github 存储库的链接已损坏。
      • @lalongooo 啊,我已经删除了 repo。我已经恢复了,但是代码很粗糙,我还以为现在网上有更好的例子... ;-)
      猜你喜欢
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      相关资源
      最近更新 更多