captured video gets a -90 rotate,how to solve it?

All your problems with Audio, Video and Images.

captured video gets a -90 rotate,how to solve it?

Postby szlxiaoyao » Sun Jan 03, 2010 7:59 am

hi.all.i have write a app to recorder,but the captured video gets a -90 rotate,and when i finished capturing a video,the screen turns black while i want it to be preview for another capturing.
How can i solve these two problems?
thanks very much.
here are my codes:
CamcorderPreview
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class CamcorderPreview extends SurfaceView implements
  3.  
  4. SurfaceHolder.Callback {
  5.  
  6.  
  7.  
  8. MediaRecorder recorder;
  9.  
  10. SurfaceHolder holder;
  11.  
  12. private Camera mCamera;
  13.  
  14.  
  15.  
  16. public CamcorderPreview(Context context, AttributeSet attrs) {
  17.  
  18. super(context, attrs);
  19.  
  20. holder = getHolder();
  21.  
  22. holder.addCallback(this);
  23.  
  24. holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  25.  
  26. recorder = new MediaRecorder();
  27.  
  28. recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  29.  
  30. recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  31.  
  32. recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  33.  
  34. recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  35.  
  36. recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. // recorder.setVideoSize(480, 320);
  45.  
  46. // recorder.setVideoFrameRate(15);
  47.  
  48. // recorder.setMaxDuration(10000);
  49.  
  50. }
  51.  
  52.  
  53.  
  54. @Override
  55.  
  56. public void surfaceChanged(SurfaceHolder holder, int format, int width,
  57.  
  58.      int height) {
  59.  
  60. }
  61.  
  62.  
  63.  
  64. @Override
  65.  
  66. public void surfaceCreated(SurfaceHolder holder) {
  67.  
  68.         recorder.setOutputFile("/sdcard/" + System.currentTimeMillis() + ".mp4");
  69.  
  70. recorder.setPreviewDisplay(holder.getSurface());
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. if (recorder != null) {
  83.  
  84.      try {
  85.  
  86.           recorder.prepare();
  87.  
  88.      } catch (IllegalStateException e) {
  89.  
  90.           Log.e("IllegalStateException", e.toString());
  91.  
  92.      } catch (IOException e) {
  93.  
  94.           Log.e("IOException", e.toString());
  95.  
  96.      }
  97.  
  98. }
  99.  
  100. }
  101.  
  102.  
  103.  
  104. @Override
  105.  
  106. public void surfaceDestroyed(SurfaceHolder holder) {
  107.  
  108. }
  109.  
  110.  
  111.  
  112. public MediaRecorder getRecorder() {
  113.  
  114. return recorder;
  115.  
  116. }
  117.  
  118.  
  119.  
  120. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

CamcorderActivity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class CamcorderActivity extends Activity {
  3.  
  4.     private CamcorderPreview camcorderPreview;
  5.  
  6.     private boolean recording = false;
  7.  
  8.     SurfaceHolder holder;
  9.  
  10.  
  11.  
  12.     /** Called when the activity is first created. */
  13.  
  14.     @Override
  15.  
  16.     public void onCreate(Bundle savedInstanceState) {
  17.  
  18.          super.onCreate(savedInstanceState);
  19.  
  20.          requestWindowFeature(Window.FEATURE_NO_TITLE);
  21.  
  22.          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  23.  
  24.          setContentView(R.layout.main);
  25.  
  26.          Toast.makeText(CamcorderActivity.this, "点击屏幕开始摄像,再次点击完成摄像",
  27.  
  28.                                         Toast.LENGTH_LONG).show();
  29.  
  30.          
  31.  
  32.  
  33.  
  34.          camcorderPreview = (CamcorderPreview) findViewById(R.id.camcorder_preview);
  35.  
  36.  
  37.  
  38.          camcorderPreview.setOnTouchListener(new OnTouchListener() {
  39.  
  40.               @Override
  41.  
  42.               public boolean onTouch(View view, MotionEvent event) {
  43.  
  44.                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
  45.  
  46.                         if (recording) {
  47.  
  48.                                 recording = false;
  49.  
  50.                              camcorderPreview.getRecorder().stop();
  51.  
  52.                            
  53.  
  54.                             //amcorderPreview.getRecorder().release();
  55.  
  56.                              
  57.  
  58.                              Toast.makeText(CamcorderActivity.this, "摄像完成",
  59.  
  60.                                                                 Toast.LENGTH_LONG).show();
  61.  
  62.                             // Intent intent = new Intent();
  63.  
  64.                                                                 //intent.setClass(CamcorderActivity.this, CamcorderActivity.class);
  65.  
  66.                                                                 //startActivity(intent);
  67.  
  68.                              //
  69.  
  70.                              
  71.  
  72.                         } else {
  73.  
  74.                              recording = true;
  75.  
  76.                              camcorderPreview.getRecorder().start();
  77.  
  78.                              Toast.makeText(CamcorderActivity.this, "正在摄像......",
  79.  
  80.                                                                 Toast.LENGTH_LONG).show();
  81.  
  82.                         }
  83.  
  84.                         return true;
  85.  
  86.                    }
  87.  
  88.                    return false;
  89.  
  90.               }
  91.  
  92.          });
  93.  
  94.     }
  95.  
  96. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4

xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.     android:orientation="vertical" android:layout_width="fill_parent"
  7.  
  8.     android:layout_height="fill_parent">
  9.  
  10.      <com.CamcorderActivity.CamcorderPreview android:id="@+id/camcorder_preview"
  11.  
  12.          android:layout_width="fill_parent" android:layout_height="fill_parent"
  13.  
  14.          android:enabled="false" android:focusable="true" android:clickable="true" />
  15.  
  16. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4



Thanks again.
szlxiaoyao
Freshman
Freshman
 
Posts: 2
Joined: Sat Jan 02, 2010 3:52 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 21 guests