Вопрос

I am trying to use a MediaRecorder object to record video in the highest quality available on my device, a Samsung S2. However with my current code I see a hang when calling MediaRecorder.close(), and then the phone crashes (LOGCAT: http://pastebin.com/yzqWqta3)

I have a working piece of code when the CamcorderProfile is set to QUALITY_LOW, but this same code results in a device crash (requiring power cycling to recover), of the Camcorder profile is changed to QUALITY_HIGH.

camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);

and later that is set to the recorder object;

recorder.setProfile(camcorderProfile);

However the following causes a crash right after MediaRecorder.stop() is called;

camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

my code is based off this project (from the Android Pro Media guy - Shawn van Every) https://github.com/vanevery/Custom-Video-Capture-with-Preview.git

That code in the original form also causes the recorder to crash (LOGCAT: http://pastebin.com/L2ahkj82) on Mediarecorder#start() and I had to use the suggestions in this thread to apply Samsung specific fixes; " [Q] Can't Record Hi Def Video on the 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();

However, with the code above I get either a crash, or the app stops responding; LOGCAT http://pastebin.com/D7Ap7yQZ

Checking device support for 1920/1080 or QUALITY_HIGH generally

The stock Camera app supports recording in 1920x1080 at something it calls "superfine", but the resolution is set explicitly, and I guess the appropriate paramters are inferred from known good settings, and not from the QUALITY_HIGH CamcorderProfile.

However there are other apps in the play store that support 1920x1080, that work on the S2 from 3rd parties (who presumably wouldn't have access to Samsung proprietary documentation) and hence it should be possible to replicate QUALITY_HIGH by setting each Parameter explicitly, or uncover Samsung's undocumented bef*ckery.

device introspection

The Samsung SII appears to support the use of QUALITY_HIGH;

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

returns this;

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

and the Android documentation indicates that "QUALITY_HIGH" is a predefined profile representing the level corresponding to the highest available resolution.

int   QUALITY_HIGH    Quality level corresponding to the highest available resolution.

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

Notes

  1. I have factory reset the phone this morning
  2. I have tried an alternative SD card, and get the same crash in the same place
  3. This might be a hardware issue. I have yet to find another Samsung S2 to test on.

Related SO Questions

There are other SO questions relating to recording HIGH QUALITY video on samsung S2, but none have an answer, so I created this one to capture my logs and code

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

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

Possible Solution

This SO question and answer seems to address the same issue, but I cannot replicate their result using the code example given; CamcorderProfile.QUALITY_HIGH resolution produces green flickering video

There is a link to a thread on xda, which has some detailed analysis

Это было полезно?

Решение 2

I managed to get the example code from Shawn Every's "Android Pro Media" working with a little help from here and the dicussion here

The main issues were the use of Samsung undocumented parameter crap, and the setting of the PreviewSize to the same as the video frame size; commented below;

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);

here is the example code, (which will only work on a real device due to the emulator limitations at this time)

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

which produces a file with these properties;

$ 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

Другие советы

Could be that your Samsung S2 doesnt not support HIGH QUALITY!
Refer to this post.
There is a way to iterate supported profiles, try to do that before setting the quality.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top