Question

I am trying to record a 480X640 video using media recorder with camcorder profile 480P but in some devices it is giving me start failed-19 when i press start recording.

private void initRecorder() {

  if(recorder!=null) return;

    // to delete the previous mp4 file created
       File deletefile=new File(outputFileName!=null?outputFileName:"abc.mp4");
       if(deletefile.exists())
           deletefile.delete();

    //Create Folder
    File folder = new File(Environment.getExternalStorageDirectory()+"/Chance");
    if(!folder.exists() )
    {
    folder.mkdirs();
    }

    File outFile= new File(folder.toString(),System.currentTimeMillis()+".mp4"); 
    outputFileName= outFile.toString();
    System.out.println("Filename "+outputFileName); 
            if(outFile.exists())
                    outFile.delete();



            try{
                    //camera.stopPreview();
                    camera.unlock();
                    recorder=new MediaRecorder();
                    recorder.setCamera(camera);                      
                    recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
                    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                if(typ==1)                     
                {  
                    //sequence should not be change
                    //Setting the quality of front camera

                     recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_480P));

                     CameraInfo cameraInfo = new CameraInfo();
                     Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
                     //To rotate the camera by 630 i.e 90 by default + 270=630
                     int rot=270;
                     recorder.setOrientationHint(rot);

                }else     //video settings for back camera
                {
                    recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_480P));

                    recorder.setOrientationHint(camera_orientation);
                }
                    recorder.setMaxDuration(20000);     //20 sec                 
                    recorder.setPreviewDisplay(holder.getSurface());

                    recorder.setOutputFile(outputFileName);
                    recorder.prepare();
                    Log.v(TAG,"MediaRecorder initilized"); 


            }
            catch(Exception e)
            {
            runOnUiThread(new Runnable(){


                    @Override
                    public void run(){
                    Toast.makeText(getApplicationContext(), "Unable to connect  camera", Toast.LENGTH_SHORT).show();
                    }
                 });

                    Log.v(TAG,"MediaRecorder failed to initilized");
                    e.printStackTrace();
            }

       //     beginRecording();


    }

EDIT:

    private void initRecorder() {
            if(recorder!=null) return;

           // to delete the previous mp4 file created
            File deletefile=new File(outputFileName!=null?outputFileName:"abc.mp4");
            if(deletefile.exists())
            deletefile.delete();

          //Create Folder
    File folder = new File(Environment.getExternalStorageDirectory()+"/Chance");
    if(!folder.exists() )
    {
    folder.mkdirs();
    }

    File outFile= new File(folder.toString(),System.currentTimeMillis()+".mp4"); 
    outputFileName= outFile.toString();
    System.out.println("Filename "+outputFileName); 
            if(outFile.exists())
                    outFile.delete();



            try{

                    //camera.stopPreview();
                    camera.unlock();
                    recorder=new MediaRecorder();
                    recorder.setCamera(camera);                      
                    recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
                    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                if(typ==1)                     
                {  
                    //sequence should not be change
                 //Setting the quality of front camera
                 if(CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P))
                     recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_480P));
                 else if(CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW))
                 {
                    Log.v(TAG,"MediaRecorder LOW QUALITY"); 
                     recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_LOW));

                     if(optimalVideoSize!=null)
                       recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
                     else
                        recorder.setVideoSize(640, 480);     
                 }

                     CameraInfo cameraInfo = new CameraInfo();
                     Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
                     //To rotate the camera by 630 i.e 90 by default + 270=630
                     int rot=270;
                     recorder.setOrientationHint(rot);


                }else     //video settings for back camera
                {
                    //Setting the quality of front camera
                     if(CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_480P))
                        recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_480P));
                     else if(CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_HIGH))
                     {
                        Log.v(TAG,"MediaRecorder HIGH QUALITY"); 
                         recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_HIGH));
                        if(optimalVideoSize!=null)
                            recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
                        else
                            recorder.setVideoSize(640, 480);
                     }  
                     else
                     {
                        Log.v(TAG,"MediaRecorder LOW QUALITY"); 
                        recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_LOW));
                        if(optimalVideoSize!=null)
                            recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
                        else
                            recorder.setVideoSize(640, 480); 
                     }


                    recorder.setOrientationHint(camera_orientation);
                }
                    recorder.setMaxDuration(20000);     //20 sec                 
                    recorder.setPreviewDisplay(holder.getSurface());

                    recorder.setOutputFile(outputFileName);
                    recorder.prepare();
                    Log.v(TAG,"MediaRecorder initilized"); 


            }
            catch(Exception e)
            {
            runOnUiThread(new Runnable(){


                    @Override
                    public void run(){
                    Toast.makeText(getApplicationContext(), "Unable to connect  camera", Toast.LENGTH_SHORT).show();
                    }
                 });

                    Log.v(TAG,"MediaRecorder failed to initilized");
                    e.printStackTrace();
            }

       //     beginRecording();


    }
Was it helpful?

Solution

the camera does not support 480P then what should i do to record 480 X 640

If the camera does not support 480p for video recording, you cannot record in 480p. Record in some other resolution, one that is supported. QUALITY_LOW and QUALITY_HIGH are the only ones that are guaranteed to be supported. If you do not like the QUALITY_LOW results, and QUALITY_480P is not available, record at QUALITY_HIGH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top