cómo especificar OUTPUT_FORMAT_MPEG2TS en el dispositivo android

Estoy confundido por qué no puedo utilizar OutputFormat.OUTPUT_FORMAT_MPEG2TS como parámetro a la MediaRecorder.setOutputFormat método MediaRecorder.setOutputFormat en el dispositivo con Android versión 2.3.6?

En la fuente de Android hay este bit de código:

 /** * Defines the output format. These constants are used with * {@link MediaRecorder#setOutputFormat(int)}. */ public final class OutputFormat { /* Do not change these values without updating their counterparts * in include/media/mediarecorder.h! */ private OutputFormat() {} public static final int DEFAULT = 0; /** 3GPP media file format*/ public static final int THREE_GPP = 1; /** MPEG4 media file format*/ public static final int MPEG_4 = 2; /** The following formats are audio only .aac or .amr formats **/ /** @deprecated Deprecated in favor of AMR_NB */ /** Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB */ /** AMR NB file format */ public static final int RAW_AMR = 3; /** AMR NB file format */ public static final int AMR_NB = 3; /** AMR WB file format */ public static final int AMR_WB = 4; /** @hide AAC ADIF file format */ public static final int AAC_ADIF = 5; /** @hide AAC ADTS file format */ public static final int AAC_ADTS = 6; /** @hide Stream over a socket, limited to a single stream */ public static final int OUTPUT_FORMAT_RTP_AVP = 7; /** @hide H.264/AAC data encapsulated in MPEG2/TS */ public static final int OUTPUT_FORMAT_MPEG2TS = 8; }; 

El dispositivo de prueba es Samsung galaxia nota que muestra Android versión 2.3.6.

MediaRecorder.setAudioSource (7) llamada no lanza un error, ya que también es la opción oculta (MediaRecorder.AudioSource.VOICE_COMMUNICATION == 7).

La llamada de MediaRecorder.setOutputFormat (8) lanza la excepción con esta salida de registro:

  03-21 17:45:27.330: E/MediaRecorder(30622): setOutputFormat failed: -2147483648 

Aquí está el código que falla en la llamada de MediaRecorder.setOutputFormat :

 import java.io.IOException; import android.app.Activity; import android.content.pm.ActivityInfo; import android.media.CamcorderProfile; import android.media.MediaRecorder; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; public class CameraStreamer extends Activity implements OnClickListener, SurfaceHolder.Callback { MediaRecorder recorder; SurfaceHolder holder; boolean recording = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); recorder = new MediaRecorder(); initRecorder(); setContentView(R.layout.main); SurfaceView cameraView = (SurfaceView) findViewById(R.id.CameraView); holder = cameraView.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); cameraView.setClickable(true); cameraView.setOnClickListener(this); } private void initRecorder() { recorder.setAudioSource(7); //MediaRecorder.AudioSource.VOICE_COMMUNICATION); //MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); recorder.setOutputFormat(8); //MediaRecorder.OutputFormat.OUTPUT_FORMAT_MPEG2TS); // for reference only CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); int width=320, height=240; recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); recorder.setVideoSize(width, height); recorder.setVideoFrameRate(25); recorder.setVideoEncodingBitRate(cpHigh.videoBitRate); recorder.setAudioEncodingBitRate(cpHigh.audioBitRate); recorder.setAudioChannels(1); recorder.setAudioSamplingRate(cpHigh.audioSampleRate); // recorder.setProfile(cpHigh); // This sets format, framerate, size, bitrate, channels, sampling rate, encoders recorder.setOutputFile("/sdcard/videocapture_example.ts"); recorder.setMaxDuration(50000); // 50 seconds recorder.setMaxFileSize(5000000); // Approximately 5 megabytes } private void prepareRecorder() { recorder.setPreviewDisplay(holder.getSurface()); try { recorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); finish(); } catch (IOException e) { e.printStackTrace(); finish(); } } public void onClick(View v) { if (recording) { recorder.stop(); recording = false; // Let's initRecorder so we can record again initRecorder(); prepareRecorder(); } else { recording = true; recorder.start(); } } public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } public void surfaceCreated(SurfaceHolder arg0) { prepareRecorder(); } public void surfaceDestroyed(SurfaceHolder arg0) { if (recording) { recorder.stop(); recording = false; } recorder.release(); finish(); } } 

En la práctica todo depende de la implementación de hardware y software en un dispositivo particular.

La nota de la galaxia de Samsung que funciona androide 4.0 puede emitir la secuencia de MPEG-TS en descriptor del archivo o del zócalo.

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.