Recherche avancée

Médias (1)

Mot : - Tags -/ogv

Autres articles (63)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • List of compatible distributions

    26 avril 2011, par

    The table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)

  • Pas question de marché, de cloud etc...

    10 avril 2011

    Le vocabulaire utilisé sur ce site essaie d’éviter toute référence à la mode qui fleurit allègrement
    sur le web 2.0 et dans les entreprises qui en vivent.
    Vous êtes donc invité à bannir l’utilisation des termes "Brand", "Cloud", "Marché" etc...
    Notre motivation est avant tout de créer un outil simple, accessible à pour tout le monde, favorisant
    le partage de créations sur Internet et permettant aux auteurs de garder une autonomie optimale.
    Aucun "contrat Gold ou Premium" n’est donc prévu, aucun (...)

Sur d’autres sites (8551)

  • Recording video on Android using JavaCV

    11 décembre 2013, par Fabio Bergmann

    I'm trying to record a video in Android using the JavaCV lib.
    I need to record the video in 640x360.

    I have installed everything as described in README.txt file and I followed the example as below :
    https://code.google.com/p/javacv/source/browse/samples/RecordActivity.java
    In this example, the video size is this :
    private int imageWidth = 320 ;
    private int imageHeight = 240 ;

    In my case, I need to record a video in 640x360 H.264.
    But, or I get an exception or the video records with no correct image.

    I think that the fix is arround a correct combination on :
    yuvIplimage = IplImage.create(imageWidth, imageHeight, IPL_DEPTH_8S, 2) ;
    changing the depth and :
    recorder.record(yuvIplimage, AV_PIX_FMT_VDPAU_H264) ;
    the pixel format.

    Here is my code :

    import static com.googlecode.javacv.cpp.avutil.AV_PIX_FMT_NONE;
    import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;

    import java.io.IOException;
    import java.nio.ShortBuffer;

    import android.app.Activity;
    import android.content.Context;
    import android.content.pm.ActivityInfo;
    import android.hardware.Camera;
    import android.hardware.Camera.PreviewCallback;
    import android.media.AudioFormat;
    import android.media.AudioRecord;
    import android.media.MediaRecorder;
    import android.os.Bundle;
    import android.os.PowerManager;
    import android.util.Log;
    import android.view.Display;
    import android.view.KeyEvent;
    import android.view.LayoutInflater;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;

    import com.autosonvideo.logic.CameraHelpers;
    import com.googlecode.javacv.FFmpegFrameRecorder;
    import com.googlecode.javacv.cpp.opencv_core.IplImage;

    public class FFmpegRecordActivity extends Activity implements OnClickListener {

       private final static String CLASS_LABEL = "RecordActivity";
       private final static String LOG_TAG = CLASS_LABEL;

       private PowerManager.WakeLock mWakeLock;

       private String ffmpeg_link = "/mnt/sdcard/stream.flv";

       long startTime = 0;
       boolean recording = false;

       private volatile FFmpegFrameRecorder recorder;

       private boolean isPreviewOn = false;

       private int sampleAudioRateInHz = 44100;
       private int imageWidth = 640;
       private int imageHeight = 360;
       private int frameRate = 30;

       /* audio data getting thread */
       private AudioRecord audioRecord;
       private AudioRecordRunnable audioRecordRunnable;
       private Thread audioThread;
       volatile boolean runAudioThread = true;

       /* video data getting thread */
       private Camera cameraDevice;
       private CameraView cameraView;

       private IplImage yuvIplimage = null;

       /* layout setting */
       private final int bg_screen_bx = 232;
       private final int bg_screen_by = 128;
       private final int bg_screen_width = 700;
       private final int bg_screen_height = 500;
       private final int bg_width = 1123;
       private final int bg_height = 715;
       private final int live_width = 640;
       private final int live_height = 360;
       private int screenWidth, screenHeight;
       private Button btnRecorderControl;

       @Override
       public void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);
           setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

           setContentView(R.layout.main);

           PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
           mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
                   CLASS_LABEL);
           mWakeLock.acquire();

           initLayout();
           initRecorder();
       }

       @Override
       protected void onResume() {
           super.onResume();

           if (mWakeLock == null) {
               PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
               mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
                       CLASS_LABEL);
               mWakeLock.acquire();
           }
       }

       @Override
       protected void onPause() {
           super.onPause();

           if (mWakeLock != null) {
               mWakeLock.release();
               mWakeLock = null;
           }
       }

       @Override
       protected void onDestroy() {
           super.onDestroy();

           recording = false;

           if (cameraView != null) {
               cameraView.stopPreview();
               cameraDevice.release();
               cameraDevice = null;
           }

           if (mWakeLock != null) {
               mWakeLock.release();
               mWakeLock = null;
           }
       }

       private void initLayout() {

           /* get size of screen */
           Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
                   .getDefaultDisplay();
           screenWidth = display.getWidth();
           screenHeight = display.getHeight();
           RelativeLayout.LayoutParams layoutParam = null;
           LayoutInflater myInflate = null;
           myInflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           RelativeLayout topLayout = new RelativeLayout(this);
           setContentView(topLayout);
           LinearLayout preViewLayout = (LinearLayout) myInflate.inflate(
                   R.layout.main, null);
           layoutParam = new RelativeLayout.LayoutParams(screenWidth, screenHeight);
           topLayout.addView(preViewLayout, layoutParam);

           /* add control button: start and stop */
           btnRecorderControl = (Button) findViewById(R.id.recorder_control);
           btnRecorderControl.setText("Start");
           btnRecorderControl.setOnClickListener(this);

           /* add camera view */
           int display_width_d = (int) (1.0 * bg_screen_width * screenWidth / bg_width);
           int display_height_d = (int) (1.0 * bg_screen_height * screenHeight / bg_height);
           int prev_rw, prev_rh;
           if (1.0 * display_width_d / display_height_d > 1.0 * live_width
                   / live_height) {
               prev_rh = display_height_d;
               prev_rw = (int) (1.0 * display_height_d * live_width / live_height);
           } else {
               prev_rw = display_width_d;
               prev_rh = (int) (1.0 * display_width_d * live_height / live_width);
           }
           layoutParam = new RelativeLayout.LayoutParams(prev_rw, prev_rh);
           layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight / bg_height);
           layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth / bg_width);

           cameraDevice = Camera.open();
           Log.i(LOG_TAG, "cameara open");
           cameraView = new CameraView(this, cameraDevice);
           topLayout.addView(cameraView, layoutParam);
           Log.i(LOG_TAG, "cameara preview start: OK");
       }

       // ---------------------------------------
       // initialize ffmpeg_recorder
       // ---------------------------------------
       private void initRecorder() {

           Log.w(LOG_TAG, "init recorder");

           if (yuvIplimage == null) {
               yuvIplimage = IplImage.create(imageWidth, imageHeight,
                       IPL_DEPTH_8U, 2);
               Log.i(LOG_TAG, "create yuvIplimage");
           }

           ffmpeg_link = CameraHelpers.getOutputMediaFile(
                   CameraHelpers.MEDIA_TYPE_VIDEO).toString();

           Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
           recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth,
                   imageHeight, 1);
           recorder.setFormat("mp4");
           recorder.setSampleRate(sampleAudioRateInHz);
           // Set in the surface changed method
           recorder.setFrameRate(frameRate);

           Log.i(LOG_TAG, "recorder initialize success");

           audioRecordRunnable = new AudioRecordRunnable();
           audioThread = new Thread(audioRecordRunnable);
       }

       public void startRecording() {

           try {
               recorder.start();
               startTime = System.currentTimeMillis();
               recording = true;
               audioThread.start();

           } catch (FFmpegFrameRecorder.Exception e) {
               e.printStackTrace();
           }
       }

       public void stopRecording() {

           runAudioThread = false;

           if (recorder != null && recording) {
               recording = false;
               Log.v(LOG_TAG,
                       "Finishing recording, calling stop and release on recorder");
               try {
                   recorder.stop();
                   recorder.release();
               } catch (FFmpegFrameRecorder.Exception e) {
                   e.printStackTrace();
               }
               recorder = null;

           }
       }

       @Override
       public boolean onKeyDown(int keyCode, KeyEvent event) {

           if (keyCode == KeyEvent.KEYCODE_BACK) {
               if (recording) {
                   stopRecording();
               }

               finish();

               return true;
           }

           return super.onKeyDown(keyCode, event);
       }

       // ---------------------------------------------
       // audio thread, gets and encodes audio data
       // ---------------------------------------------
       class AudioRecordRunnable implements Runnable {

           @Override
           public void run() {
               android.os.Process
                       .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

               // Audio
               int bufferSize;
               short[] audioData;
               int bufferReadResult;

               bufferSize = AudioRecord
                       .getMinBufferSize(sampleAudioRateInHz,
                               AudioFormat.CHANNEL_IN_MONO,
                               AudioFormat.ENCODING_PCM_16BIT);
               audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                       sampleAudioRateInHz, AudioFormat.CHANNEL_IN_MONO,
                       AudioFormat.ENCODING_PCM_16BIT, bufferSize);

               audioData = new short[bufferSize];

               Log.d(LOG_TAG, "audioRecord.startRecording()");
               audioRecord.startRecording();

               /* ffmpeg_audio encoding loop */
               while (runAudioThread) {
                   // Log.v(LOG_TAG,"recording? " + recording);
                   bufferReadResult = audioRecord.read(audioData, 0,
                           audioData.length);
                   if (bufferReadResult > 0) {
                       // Log.v(LOG_TAG, "bufferReadResult: " + bufferReadResult);
                       // If "recording" isn't true when start this thread, it
                       // never get's set according to this if statement...!!!
                       // Why? Good question...
                       if (recording) {
                           try {
                               recorder.record(ShortBuffer.wrap(audioData, 0,
                                       bufferReadResult));
                               // Log.v(LOG_TAG,"recording " + 1024*i + " to " +
                               // 1024*i+1024);
                           } catch (FFmpegFrameRecorder.Exception e) {
                               Log.v(LOG_TAG, e.getMessage());
                               e.printStackTrace();
                           }
                       }
                   }
               }
               Log.v(LOG_TAG, "AudioThread Finished, release audioRecord");

               /* encoding finish, release recorder */
               if (audioRecord != null) {
                   audioRecord.stop();
                   audioRecord.release();
                   audioRecord = null;
                   Log.v(LOG_TAG, "audioRecord released");
               }
           }
       }

       // ---------------------------------------------
       // camera thread, gets and encodes video data
       // ---------------------------------------------
       class CameraView extends SurfaceView implements SurfaceHolder.Callback,
               PreviewCallback {

           private SurfaceHolder mHolder;
           private Camera mCamera;

           public CameraView(Context context, Camera camera) {
               super(context);
               Log.w("camera", "camera view");
               mCamera = camera;
               mHolder = getHolder();
               mHolder.addCallback(CameraView.this);
               mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
               mCamera.setPreviewCallback(CameraView.this);
           }

           @Override
           public void surfaceCreated(SurfaceHolder holder) {
               try {
                   stopPreview();
                   mCamera.setPreviewDisplay(holder);
               } catch (IOException exception) {
                   mCamera.release();
                   mCamera = null;
               }
           }

           public void surfaceChanged(SurfaceHolder holder, int format, int width,
                   int height) {
               Log.v(LOG_TAG, "Setting imageWidth: " + imageWidth
                       + " imageHeight: " + imageHeight + " frameRate: "
                       + frameRate);
               Camera.Parameters camParams = mCamera.getParameters();
               camParams.setPreviewSize(imageWidth, imageHeight);

               Log.v(LOG_TAG,
                       "Preview Framerate: " + camParams.getPreviewFrameRate());

               camParams.setPreviewFrameRate(frameRate);
               mCamera.setParameters(camParams);
               startPreview();
           }

           @Override
           public void surfaceDestroyed(SurfaceHolder holder) {
               try {
                   mHolder.addCallback(null);
                   mCamera.setPreviewCallback(null);
               } catch (RuntimeException e) {
                   // The camera has probably just been released, ignore.
               }
           }

           public void startPreview() {
               if (!isPreviewOn && mCamera != null) {
                   isPreviewOn = true;
                   mCamera.startPreview();
               }
           }

           public void stopPreview() {
               if (isPreviewOn && mCamera != null) {
                   isPreviewOn = false;
                   mCamera.stopPreview();
               }
           }

           @Override
           public void onPreviewFrame(byte[] data, Camera camera) {
               /* get video data */
               if (yuvIplimage != null && recording) {
                   int cap = yuvIplimage.getByteBuffer().capacity();
                   int dataLen = data.length;
                   Log.d("FFmpeg", "cap: " + cap + " data: " + dataLen);
                   yuvIplimage.getByteBuffer().put(data);

                   Log.v(LOG_TAG, "Writing Frame");
                   try {
                       long t = 1000 * (System.currentTimeMillis() - startTime);
                       if (t > recorder.getTimestamp()) {
                           recorder.setTimestamp(t);
                       }
                       recorder.record(yuvIplimage, AV_PIX_FMT_NONE);
                   } catch (FFmpegFrameRecorder.Exception e) {
                       Log.v(LOG_TAG, e.getMessage());
                       e.printStackTrace();
                   }
               }
           }
       }

       @Override
       public void onClick(View v) {
           if (!recording) {
               startRecording();
               Log.w(LOG_TAG, "Start Button Pushed");
               btnRecorderControl.setText("Stop");
           } else {
               // This will trigger the audio recording loop to stop and then set
               // isRecorderStart = false;
               stopRecording();
               Log.w(LOG_TAG, "Stop Button Pushed");
               btnRecorderControl.setText("Start");
           }
       }
    }

    Thanks in advance !

  • Recording video on Android using JavaCV (Updated 2014 02 17)

    25 septembre 2014, par Fabio Bergmann

    I’m trying to record a video in Android using the JavaCV lib.
    I need to record the video in 640x360.

    I have installed everything as described in README.txt file and I followed the example as below :
    https://code.google.com/p/javacv/source/browse/samples/RecordActivity.java
    In this example, the video size is this :
    private int imageWidth = 320 ;
    private int imageHeight = 240 ;

    In my case, I need to record a video in 640x360 H.264.

    (UPDATE) I have reverted my code and kept exactly like in the example, just changing imageWidth and imageHeight to 640x360.
    Now I’m getting the video like this image :
    http://bergmann.net.br/img/screenshot_video_error.png

    Here is my code :

    import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;

    import java.io.IOException;
    import java.nio.ShortBuffer;

    import android.app.Activity;
    import android.content.Context;
    import android.content.pm.ActivityInfo;
    import android.hardware.Camera;
    import android.hardware.Camera.PreviewCallback;
    import android.media.AudioFormat;
    import android.media.AudioRecord;
    import android.media.MediaRecorder;
    import android.os.Bundle;
    import android.os.PowerManager;
    import android.util.Log;
    import android.view.Display;
    import android.view.KeyEvent;
    import android.view.LayoutInflater;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;

    import com.autosonvideo.helpers.Helpers;
    import com.autosonvideo.logic.CameraHelpers;
    import com.googlecode.javacv.FFmpegFrameRecorder;
    import com.googlecode.javacv.cpp.opencv_core.IplImage;

    public class FFmpegRecordActivity extends Activity implements OnClickListener {

       private final static String CLASS_LABEL = "RecordActivity";
       private final static String LOG_TAG = CLASS_LABEL;

       private PowerManager.WakeLock mWakeLock;

       private String ffmpeg_link;

       long startTime = 0;
       boolean recording = false;

       private volatile FFmpegFrameRecorder recorder;

       private boolean isPreviewOn = false;

       private int sampleAudioRateInHz = 44100;
       private int imageWidth = 640;
       private int imageHeight = 480;

       private int finalImageWidth = 640;
       private int finalImageHeight = 360;

       private int frameRate = 30;

       /* audio data getting thread */
       private AudioRecord audioRecord;
       private AudioRecordRunnable audioRecordRunnable;
       private Thread audioThread;
       volatile boolean runAudioThread = true;

       /* video data getting thread */
       private Camera cameraDevice;
       private CameraView cameraView;

       private IplImage yuvIplimage = null;

       /* layout setting */
       private final int bg_screen_bx = 232;
       private final int bg_screen_by = 128;
       private final int bg_screen_width = 700;
       private final int bg_screen_height = 500;
       private final int bg_width = 1123;
       private final int bg_height = 715;
       private final int live_width = 1280;
       private final int live_height = 960;
       private int screenWidth, screenHeight;
       private Button btnRecorderControl;

       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

           setContentView(R.layout.main);

           PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
           mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
                   CLASS_LABEL);
           mWakeLock.acquire();

           initLayout();
           initRecorder();
       }

       @Override
       protected void onResume() {
           super.onResume();

           if (mWakeLock == null) {
               PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
               mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
                       CLASS_LABEL);
               mWakeLock.acquire();
           }
       }

       @Override
       protected void onPause() {
           super.onPause();

           if (mWakeLock != null) {
               mWakeLock.release();
               mWakeLock = null;
           }
       }

       @Override
       protected void onDestroy() {
           super.onDestroy();

           recording = false;

           if (cameraView != null) {
               cameraView.stopPreview();
               cameraDevice.release();
               cameraDevice = null;
           }

           if (mWakeLock != null) {
               mWakeLock.release();
               mWakeLock = null;
           }
       }

       private void initLayout() {

           /* get size of screen */
           Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
                   .getDefaultDisplay();
           screenWidth = display.getWidth();
           screenHeight = display.getHeight();
           RelativeLayout.LayoutParams layoutParam = null;
           LayoutInflater myInflate = null;
           myInflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           RelativeLayout topLayout = new RelativeLayout(this);
           setContentView(topLayout);
           LinearLayout preViewLayout = (LinearLayout) myInflate.inflate(
                   R.layout.main, null);
           layoutParam = new RelativeLayout.LayoutParams(screenWidth, screenHeight);
           topLayout.addView(preViewLayout, layoutParam);

           /* add control button: start and stop */
           btnRecorderControl = (Button) findViewById(R.id.recorder_control);
           btnRecorderControl.setText("Start");
           btnRecorderControl.setOnClickListener(this);

           /* add camera view */
           int display_width_d = (int) (1.0 * bg_screen_width * screenWidth / bg_width);
           int display_height_d = (int) (1.0 * bg_screen_height * screenHeight / bg_height);
           int prev_rw, prev_rh;
           if (1.0 * display_width_d / display_height_d > 1.0 * live_width
                   / live_height) {
               prev_rh = display_height_d;
               prev_rw = (int) (1.0 * display_height_d * live_width / live_height);
           } else {
               prev_rw = display_width_d;
               prev_rh = (int) (1.0 * display_width_d * live_height / live_width);
           }
           layoutParam = new RelativeLayout.LayoutParams(prev_rw, prev_rh);
           layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight / bg_height);
           layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth / bg_width);

           cameraDevice = Camera.open();
           Log.i(LOG_TAG, "cameara open");
           cameraView = new CameraView(this, cameraDevice);
           topLayout.addView(cameraView, layoutParam);
           Log.i(LOG_TAG, "cameara preview start: OK");
       }

       // ---------------------------------------
       // initialize ffmpeg_recorder
       // ---------------------------------------
       private void initRecorder() {

           Log.w(LOG_TAG, "init recorder");

           if (yuvIplimage == null) {
               yuvIplimage = IplImage.create(finalImageWidth, finalImageHeight,
                       IPL_DEPTH_8U, 2);
               Log.i(LOG_TAG, "create yuvIplimage");
           }

           ffmpeg_link = CameraHelpers.getOutputMediaFile(
                   CameraHelpers.MEDIA_TYPE_VIDEO).toString();

           Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
           recorder = new FFmpegFrameRecorder(ffmpeg_link, finalImageWidth,
                   finalImageHeight, 1);
           recorder.setFormat("mp4");
           recorder.setSampleRate(sampleAudioRateInHz);
           // Set in the surface changed method
           recorder.setFrameRate(frameRate);

           Log.i(LOG_TAG, "recorder initialize success");

           audioRecordRunnable = new AudioRecordRunnable();
           audioThread = new Thread(audioRecordRunnable);
       }

       public void startRecording() {

           try {
               recorder.start();
               startTime = System.currentTimeMillis();
               recording = true;
               audioThread.start();

           } catch (FFmpegFrameRecorder.Exception e) {
               e.printStackTrace();
           }
       }

       public void stopRecording() {

           runAudioThread = false;

           if (recorder != null && recording) {
               recording = false;
               Log.v(LOG_TAG,
                       "Finishing recording, calling stop and release on recorder");
               try {
                   recorder.stop();
                   recorder.release();
               } catch (FFmpegFrameRecorder.Exception e) {
                   e.printStackTrace();
               }
               recorder = null;

           }
       }

       @Override
       public boolean onKeyDown(int keyCode, KeyEvent event) {

           if (keyCode == KeyEvent.KEYCODE_BACK) {
               if (recording) {
                   stopRecording();
               }

               finish();

               return true;
           }

           return super.onKeyDown(keyCode, event);
       }

       // ---------------------------------------------
       // audio thread, gets and encodes audio data
       // ---------------------------------------------
       class AudioRecordRunnable implements Runnable {

           @Override
           public void run() {
               android.os.Process
                       .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

               // Audio
               int bufferSize;
               short[] audioData;
               int bufferReadResult;

               bufferSize = AudioRecord
                       .getMinBufferSize(sampleAudioRateInHz,
                               AudioFormat.CHANNEL_IN_MONO,
                               AudioFormat.ENCODING_PCM_16BIT);
               audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                       sampleAudioRateInHz, AudioFormat.CHANNEL_IN_MONO,
                       AudioFormat.ENCODING_PCM_16BIT, bufferSize);

               audioData = new short[bufferSize];

               Log.d(LOG_TAG, "audioRecord.startRecording()");
               audioRecord.startRecording();

               /* ffmpeg_audio encoding loop */
               while (runAudioThread) {
                   // Log.v(LOG_TAG,"recording? " + recording);
                   bufferReadResult = audioRecord.read(audioData, 0,
                           audioData.length);
                   if (bufferReadResult > 0) {
                       Log.v(LOG_TAG, "bufferReadResult: " + bufferReadResult);
                       // If "recording" isn't true when start this thread, it
                       // never get's set according to this if statement...!!!
                       // Why? Good question...
                       if (recording) {
                           try {
                               recorder.record(ShortBuffer.wrap(audioData, 0,
                                       bufferReadResult));
                               // Log.v(LOG_TAG,"recording " + 1024*i + " to " +
                               // 1024*i+1024);
                           } catch (FFmpegFrameRecorder.Exception e) {
                               Log.v(LOG_TAG, e.getMessage());
                               e.printStackTrace();
                           }
                       }
                   }
               }
               Log.v(LOG_TAG, "AudioThread Finished, release audioRecord");

               /* encoding finish, release recorder */
               if (audioRecord != null) {
                   audioRecord.stop();
                   audioRecord.release();
                   audioRecord = null;
                   Log.v(LOG_TAG, "audioRecord released");
               }
           }
       }

       // ---------------------------------------------
       // camera thread, gets and encodes video data
       // ---------------------------------------------
       class CameraView extends SurfaceView implements SurfaceHolder.Callback,
               PreviewCallback {

           private SurfaceHolder mHolder;
           private Camera mCamera;

           public CameraView(Context context, Camera camera) {
               super(context);
               Log.w("camera", "camera view");
               mCamera = camera;
               mHolder = getHolder();
               mHolder.addCallback(CameraView.this);
               mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
               mCamera.setPreviewCallback(CameraView.this);
           }

           @Override
           public void surfaceCreated(SurfaceHolder holder) {
               try {
                   stopPreview();
                   mCamera.setPreviewDisplay(holder);
               } catch (IOException exception) {
                   mCamera.release();
                   mCamera = null;
               }
           }

           public void surfaceChanged(SurfaceHolder holder, int format, int width,
                   int height) {
               Log.v(LOG_TAG, "Setting imageWidth: " + imageWidth
                       + " imageHeight: " + imageHeight + " frameRate: "
                       + frameRate);
               Camera.Parameters camParams = mCamera.getParameters();
               camParams.setPreviewSize(imageWidth, imageHeight);

               Log.v(LOG_TAG,
                       "Preview Framerate: " + camParams.getPreviewFrameRate());

               camParams.setPreviewFrameRate(frameRate);
               mCamera.setParameters(camParams);
               startPreview();
           }

           @Override
           public void surfaceDestroyed(SurfaceHolder holder) {
               try {
                   mHolder.addCallback(null);
                   mCamera.setPreviewCallback(null);
               } catch (RuntimeException e) {
                   // The camera has probably just been released, ignore.
               }
           }

           public void startPreview() {
               if (!isPreviewOn && mCamera != null) {
                   isPreviewOn = true;
                   mCamera.startPreview();
               }
           }

           public void stopPreview() {
               if (isPreviewOn && mCamera != null) {
                   isPreviewOn = false;
                   mCamera.stopPreview();
               }
           }

           @Override
           public void onPreviewFrame(byte[] data, Camera camera) {
               /* get video data */
               if (yuvIplimage != null && recording) {
                   // yuvIplimage.getByteBuffer().put(data);

                   final int startY = 640 * (480 - 360) / 2;
                   final int lenY = 640 * 360;
                   yuvIplimage.getByteBuffer().put(data, startY, lenY);
                   final int startVU = 640 * 480 + 320 * 2 * (240 - 180) / 2;
                   final int lenVU = 320 * 180 * 2;
                   yuvIplimage.getByteBuffer().put(data, startVU, lenVU);

                   Log.v(LOG_TAG, "Writing Frame");
                   try {
                       long t = 1000 * (System.currentTimeMillis() - startTime);
                       if (t > recorder.getTimestamp()) {
                           recorder.setTimestamp(t);
                       }
                       recorder.record(yuvIplimage);
                   } catch (FFmpegFrameRecorder.Exception e) {
                       Log.v(LOG_TAG, e.getMessage());
                       e.printStackTrace();
                   }
               }
           }
       }

       @Override
       public void onClick(View v) {
           if (!recording) {
               startRecording();
               Log.w(LOG_TAG, "Start Button Pushed");
               btnRecorderControl.setText("Stop");
           } else {
               // This will trigger the audio recording loop to stop and then set
               // isRecorderStart = false;
               stopRecording();
               Log.w(LOG_TAG, "Stop Button Pushed");
               btnRecorderControl.setText("Start");
           }
       }
    }
  • Dreamcast SD Adapter and DreamShell

    31 décembre 2014, par Multimedia Mike — Sega Dreamcast

    Nope ! I’m never going to let go of the Sega Dreamcast hacking. When I was playing around with Dreamcast hacking early last year, I became aware that there is such a thing as an SD card adapter for the DC that plugs into the port normally reserved for the odd DC link cable. Of course I wanted to see what I could do with it.

    The primary software that leverages the DC SD adapter is called DreamShell. Working with this adapter and the software requires some skill and guesswork. Searching for these topics tends to turn up results from various forums where people are trying to cargo-cult their way to solutions. I have a strange feeling that this post might become the unofficial English-language documentation on the matter.

    Use Cases
    What can you do with this thing ? Undoubtedly, the primary use is for backing up (ripping) the contents of GD-ROMs (the custom optical format used for the DC) and playing those backed up (ripped) copies. Presumably, users of this device leverage the latter use case more than the former, i.e., download ripped games, load them on the SD card, and launch them using DreamShell.

    However, there are other uses such as multimedia playback, system exploration, BIOS reprogramming, high-level programming, and probably a few other things I haven’t figured out yet.

    Delivery
    I put in an order via the dc-sd.com website and in about 2 short months, the item arrived from China. This marked my third lifetime delivery from China and curiously, all 3 of the shipments have pertained to the Sega Dreamcast.


    Dreamcast SD Adapter package

    Click for larger image


    I thought it was very interesting that this adapter came in such complete packaging. The text is all in Chinese, though the back states “Windows 98 / ME / 2000 / XP, Mac OS 9.1, LINUX2.4”. That’s what tipped me off that they must have just cannibalized some old USB SD card readers and packaging in order to create these. Closer inspection of the internals through the translucent pink case confirms this.

    Usage
    According to its change log, DreamShell has been around for a long time with version 1.0.0 released in February of 2004. The current version is 4.0.0 RC3. There are several downloads available :

    1. DreamShell 4.0 RC 3 CDI Image
    2. DreamShell 4.0 RC 3 + Boot Loader
    3. DreamShell 4.0 RC 3 + Core CDI image

    Option #2 worked for me. It contains a CDI disc image and the DreamShell files in a directory named DS/.

    Burn the CDI to a CD-R in the normal way you would burn a bootable Dreamcast disc from a CDI image. This is open-ended and left as an exercise to the reader, since there are many procedures depending on platform. On Linux, I used a small script I found once called burncdi-dc.sh.

    Then, copy the contents of the DS/ folder to an SD card. As for filesystem, FAT16 and FAT32 are both known to work. The files in DS/ should land in the root of the SD card ; the folder DS/ should not be in the root.

    Plug the SD card into the DC SD adapter and plug the adapter in the link cable port on the back of the Dreamcast. Then, boot the disc. If it works, you will see this minor corruption of the usual Sega licensing screen :


    DreamShell logo on Dreamcast startup

    Then, there will be a brief white-on-black text screen that explains the booting process :


    DreamShell booting text

    Then, there will be the main DreamShell logo :


    DreamShell logo

    Finally, you will land on the DreamShell main desktop :


    DreamShell 4.0.0 RC3 main desktop

    Skepticism
    At first, I was supremely skeptical of the idea that this SD adapter could perform speedily enough to play games reasonably. This was predicated on the observation that my DC coder’s cable that I used to use for homebrew development could not transfer faster than 115200 bits/second, amounting to about 11 kbytes/sec. I assumed that this was a fundamental limitation of the link port.

    In fact, I ripped a few of my Dreamcast discs over a decade ago and still have those rips lying around. So I copied the ISO image of Resident Evil : Code Veronica — the game I personally played most on the DC — to the SD card (anywhere works) and used the “ISO loader” icon seen on the desktop above to launch the game.

    It works :


    Resident Evil: Code Veronica title

    The opening FMV plays at full speed. Everything loads as fast as I remember. I was quite surprised.

    Digression : My assumptions about serial speeds have often been mistaken. 10 years ago, I heard stories about how we would soon be able to watch streaming video on our cell phones. I scoffed because I thought the 56K limitation of dialup modems was some sort of fundamental speed-of-light type of limitation for telephony bandwidth, wired or wireless.

    The desktop menu also includes a ‘speedtest’ tool that profiles the write and read performance of your preferred storage medium. For my fastest SD card (a PNY 2 GB card) :


    DreamShell speedtest utility

    This is probably more representative of the true adapter bandwidth as reading and writing is a good deal faster through more modern interfaces on PC and Mac with this same card.

    Look at the other options on the speedtest console. Hard drive ? Apparently, it’s possible, but it requires a good deal more hardware hacking than just purchasing this SD adapter.

    Ripping
    As you can see from the Resident Evil screenshot, playing games works quite nicely. How about ripping ? I’m pleased to say that DreamShell has a beautiful ripping interface :


    Ripping a GD-ROM using DreamShell

    Enter a name for the disc (or read the disc label), select the storage medium, and let it, well, rip. It indicates which track it’s working on and the Sega logo acts as a progress bar, shading blue as the track rip progresses.

    I’m finally, efficiently, archiving that collection of Sega Dreamcast demo discs ; I’m hoping they’ll eventually find a home at the Internet Archive. How is overall ripping performance ? Usually about 38-40 minutes to rip a full 900-1000 MB. That certainly beats the 27-28 hours that were required when I performed the ripping at 11 kbytes/sec via the DC coders cable.

    All is well until I get a sector reading error :


    DreamShell ripping error

    That’s when it can come in handy to have 3 DC consoles (see ?! not crazy !).

    Other Uses
    There’s a file explorer. You can browse the filesystem of the SD card, visual memory unit, or the CD portion of the GD-ROM (would be more useful if it accessed the GD area). There are FFmpeg files included. So I threw a random Cinepak file and random MPEG-1 file at it to see what happens. MPEG-1 didn’t do anything, but this Cinepak file from some Sierra game played handily :


    DreamShell playing Cinepak

    If you must enter strings, it helps to have a Dreamcast keyboard (which I do). Failing that, here’s a glimpse of the onscreen keyboard that DreamShell equips :


    DreamShell onscreen keyboard

    Learning to use it is a game in itself.

    There is an option of installing DreamShell in the BIOS. I did not attempt this. I don’t know if it’s possible (not like there’s a lot of documentation)– perhaps a custom BIOS modchip is needed. But here’s what the screen looks like :


    DreamShell BIOS installation menu

    There is also a plain console to interact with (better have a physical keyboard). There are numerous file manipulation commands and custom system interaction commands. I see one interesting command called ‘addr’ that looks useful for dumping memory regions to a file.

    A Lua language interpreter is also built in. I would love to play with this if I could ascertain whether DreamShell provided Dreamcast-specific APIs.

    Tips And Troubleshooting
    I have 3 Dreamcast consoles, affectionately named Terran, Protoss, and Zerg after the StarCraft II stickers with which they are adorned. Some seem to work better than others. Protoss seemed to be able to boot the DreamShell disc more reliably than the others. However, I was alarmed when it couldn’t boot one morning when it was churning the previous day.

    I think the problem is that it was just cold. That seemed to be the issue. I put in a normal GD-ROM and let it warm up on that disc for awhile and then DreamShell booted fine. So that’s my piece of cargo-culting troubleshooting advice.