Recherche avancée

Médias (1)

Mot : - Tags -/iphone

Autres articles (99)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Mise à jour de la version 0.1 vers 0.2

    24 juin 2013, par

    Explications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
    Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

Sur d’autres sites (9850)

  • Tap to record like in vine using javacv

    8 décembre 2015, par human123

    I am trying to implement a tap to record feature like in vine. A sample for handling recording (not touch to record) provided in javacv is https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java. I am trying to modify it so that in onPreviewFrame method frames are added to buffer only when user has his finger placed on screen. These frames are then tried to be combined into final video in stopRecording method.

    The issue is that if I set the timestamp as given in below code snippet (in stopRecording method)

    if (t > recorder.getTimestamp())
    {
       recorder.setTimestamp(t);
    }

    the behavior is as below

    Case 1

    If I tap on screen to record for 2 seconds and take the finger away from screen for 3 seconds and then again place finger back on screen to record for another 4 seconds the resulting video is like,

    For 1st 2 seconds video has recorded content. For next 3 seconds (time when finger is put away from screen). video just shows the last frame recorded when finger was placed on screen last. Then the video has recorded video content for next 4 seconds. So there seems to be an issue in handling video recording when finger is removed from screen.

    Case 2

    Next I removed the code setting time stamp to recorder(the code snippet given above) in stopRecording method.

    Now the resulting video (for the same steps tried in case 1) does not contain the middle 3 seconds(which is what is required) when finger was taken away from screen. But video is playing at a faster rate. So it seems that we need to set time stamp so that video plays at normal rate.

    Full code of my activity is given below. (Please note that video recording is mainly handled from onPreviewFrame and stopRecording methods)

    public class TouchToRecordActivity extends Activity implements OnClickListener, View.OnTouchListener {

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

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

    long startTime = 0;
    boolean recording = false;
    boolean rec = false;

    private FFmpegFrameRecorder recorder;

    private boolean isPreviewOn = false;

    private int sampleAudioRateInHz = 44100;
    private int imageWidth = 640;
    private int imageHeight = 480;
    private int destWidth = 480;
    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 Frame yuvImage = 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 = 480;
    private int screenWidth, screenHeight;
    private Button btnRecorderControl;

    /* The number of seconds in the continuous record loop (or 0 to disable loop). */
    final int RECORD_LENGTH = 20;
    Frame[] images;
    long[] timestamps;
    ShortBuffer[] samples;
    int imagesIndex, samplesIndex;

    long firstTime = 0;
    long startPauseTime = 0;
    long totalPauseTime = 0;
    long pausedTime = 0;
    long stopPauseTime = 0;
    long totalTime = 0;

    long totalRecordedTS = 0;

    private TextView txtTimer;
    private Handler mHandler = new Handler();

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

       setContentView(R.layout.touch_main);

       initLayout();
    }

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

       recording = false;

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

       if (cameraDevice != null) {
           cameraDevice.stopPreview();
           cameraDevice.release();
           cameraDevice = 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.touch_main, null);
       layoutParam = new RelativeLayout.LayoutParams(screenWidth, screenHeight);
       topLayout.addView(preViewLayout, layoutParam);

       txtTimer = (TextView) preViewLayout.findViewById(R.id.txtTimer);

       /* 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);
       topLayout.setOnTouchListener(this);
       Log.i(LOG_TAG, "cameara preview start: OK");
    }

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

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

       if (RECORD_LENGTH > 0) {
           imagesIndex = 0;
           images = new Frame[RECORD_LENGTH * frameRate];
           timestamps = new long[images.length];
           for (int i = 0; i < images.length; i++) {
               images[i] = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
               timestamps[i] = -1;
           }
       } else if (yuvImage == null) {
           yuvImage = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
           Log.i(LOG_TAG, "create yuvImage");
       }
       Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
       recorder = new FFmpegFrameRecorder(ffmpeg_link, destWidth, imageHeight, 1);
       recorder.setFormat("mp4");
       recorder.setVideoCodecName("libx264");
       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);
       runAudioThread = true;
    }

    public void startRecording() {

       initRecorder();

       mHandler.removeCallbacks(mUpdateTimeTask);
       mHandler.postDelayed(mUpdateTimeTask, 100);

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

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

    public void stopRecording() {

       runAudioThread = false;
       try {
           audioThread.join();
       } catch (InterruptedException e) {
           e.printStackTrace();
       }
       audioRecordRunnable = null;
       audioThread = null;

       if (recorder != null && recording) {
           if (RECORD_LENGTH > 0) {
               Log.v(LOG_TAG, "Writing frames");
               try {
                   int firstIndex = imagesIndex % samples.length;
                   int lastIndex = (imagesIndex - 1) % images.length;
                   if (imagesIndex <= images.length) {
                       firstIndex = 0;
                       lastIndex = imagesIndex - 1;
                   }
                   if ((startTime = timestamps[lastIndex] - RECORD_LENGTH * 1000000L) < 0) {
                       startTime = 0;
                   }
                   if (lastIndex < firstIndex) {
                       lastIndex += images.length;
                   }
                   int videoCounter = 0;
                   for (int i = firstIndex; i <= lastIndex; i++) {
                       if (timestamps[i] == -1) {
                           Log.v(LOG_TAG, "frame not recorded");
                       }
                       if (timestamps[i] != -1) {
                           long t = timestamps[i % timestamps.length] - startTime;
                           if (t >= 0) {

                               videoCounter++;

                               /*if (((i % images.length) != 0) && images[i % images.length] != images[(i % images.length) - 1]) {
                                   if (t > recorder.getTimestamp()) {
                                       recorder.setTimestamp(t);
                                   }*/
                                   Log.v(LOG_TAG, "imageIndex=" + (i % images.length));
                                   recorder.record(images[i % images.length]);
                           /*    }*/
                               Log.v(LOG_TAG, "videoCounter=" + videoCounter);
                           }
                       }
                   }

                   firstIndex = samplesIndex % samples.length;
                   lastIndex = (samplesIndex - 1) % samples.length;
                   if (samplesIndex <= samples.length) {
                       firstIndex = 0;
                       lastIndex = samplesIndex - 1;
                   }
                   if (lastIndex < firstIndex) {
                       lastIndex += samples.length;
                   }
                   for (int i = firstIndex; i <= lastIndex; i++) {
                       if (timestamps[i] != -1) {
                           recorder.recordSamples(samples[i % samples.length]);
                       }
                   }
               } catch (FFmpegFrameRecorder.Exception e) {
                   Log.v(LOG_TAG, e.getMessage());
                   e.printStackTrace();
               }
           }

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

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
       switch (motionEvent.getAction()) {
           case MotionEvent.ACTION_DOWN:
               Log.v(LOG_TAG, "ACTION_DOWN" + recording);

               if (!recording) {
                   startRecording();
               } else {
                   stopPauseTime = System.currentTimeMillis();
                   totalPauseTime = stopPauseTime - startPauseTime - ((long) (1.0 / (double) frameRate) * 1000);
                   pausedTime += totalPauseTime;
               }
               rec = true;
               setTotalVideoTime();
               btnRecorderControl.setText(getResources().getString(R.string.stop));
               break;
           case MotionEvent.ACTION_MOVE:
               rec = true;
               setTotalVideoTime();
               break;
           case MotionEvent.ACTION_UP:
               Log.v(LOG_TAG, "ACTION_UP");
               rec = false;
               startPauseTime = System.currentTimeMillis();
               break;
       }
       return true;
    }

    private Runnable mUpdateTimeTask = new Runnable() {
       public void run() {
           if (recording) {
               setTotalVideoTime();
           }
           mHandler.postDelayed(this, 500);
       }
    };

    private synchronized void setTotalVideoTime() {
       totalTime = System.currentTimeMillis() - firstTime - pausedTime - ((long) (1.0 / (double) frameRate) * 1000);
       if (totalTime > 0)
           txtTimer.setText(getRecordingTimeFromMillis(totalTime));
    }

    private String getRecordingTimeFromMillis(long millis) {
       String strRecordingTime = null;
       int seconds = (int) (millis / 1000);
       int minutes = seconds / 60;
       int hours = minutes / 60;

       if (hours >= 0 && hours < 10)
           strRecordingTime = "0" + hours + ":";
       else
           strRecordingTime = hours + ":";

       if (hours > 0)
           minutes = minutes % 60;

       if (minutes >= 0 && minutes < 10)
           strRecordingTime += "0" + minutes + ":";
       else
           strRecordingTime += minutes + ":";

       seconds = seconds % 60;

       if (seconds >= 0 && seconds < 10)
           strRecordingTime += "0" + seconds;
       else
           strRecordingTime += seconds;

       return strRecordingTime;

    }


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

           if (RECORD_LENGTH > 0) {
               samplesIndex = 0;
               samples = new ShortBuffer[RECORD_LENGTH * sampleAudioRateInHz * 2 / bufferSize + 1];
               for (int i = 0; i < samples.length; i++) {
                   samples[i] = ShortBuffer.allocate(bufferSize);
               }
           } else {
               audioData = ShortBuffer.allocate(bufferSize);
           }

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

           /* ffmpeg_audio encoding loop */
           while (runAudioThread) {
               if (RECORD_LENGTH > 0) {
                   audioData = samples[samplesIndex++ % samples.length];
                   audioData.position(0).limit(0);
               }
               //Log.v(LOG_TAG,"recording? " + recording);
               bufferReadResult = audioRecord.read(audioData.array(), 0, audioData.capacity());
               audioData.limit(bufferReadResult);
               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 && rec) {
                       Log.v(LOG_TAG, "Recording audio");
                       if (RECORD_LENGTH <= 0) try {
                           recorder.recordSamples(audioData);
                           //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) {
           stopPreview();

           Camera.Parameters camParams = mCamera.getParameters();
           List sizes = camParams.getSupportedPreviewSizes();
           // Sort the list in ascending order
           Collections.sort(sizes, new Comparator() {

               public int compare(final Camera.Size a, final Camera.Size b) {
                   return a.width * a.height - b.width * b.height;
               }
           });

           camParams.setPreviewSize(imageWidth, imageHeight);

           Log.v(LOG_TAG, "Setting imageWidth: " + imageWidth + " imageHeight: " + imageHeight + " frameRate: " + frameRate);

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

           mCamera.setParameters(camParams);

           List videoSizes = mCamera.getParameters().getSupportedVideoSizes();

           // Set the holder (which might have changed) again
           try {
               mCamera.setPreviewDisplay(holder);
               mCamera.setPreviewCallback(CameraView.this);
               startPreview();
           } catch (Exception e) {
               Log.e(LOG_TAG, "Could not set preview display in surfaceChanged");
           }
       }

       @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) {
           if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
               startTime = System.currentTimeMillis();
               return;
           }
           if (RECORD_LENGTH > 0) {
               int i = imagesIndex++ % images.length;
               Log.v(LOG_TAG, "recording:" + recording + "rec:" + rec);
               if (recording && rec) {
                   yuvImage = images[i];
                   timestamps[i] = 1000 * (System.currentTimeMillis() - startTime);
                   totalRecordedTS++;
               } else {
                   Log.v(LOG_TAG, "recording is paused");
                   yuvImage = null;
                   timestamps[i] = -1;
               }
           }

           /* get video data */
           if (yuvImage != null && recording && rec) {
               if (data.length != imageWidth * imageHeight) {
                   Camera.Size sz = camera.getParameters().getPreviewSize();
                   imageWidth = sz.width;
                   imageHeight = sz.height;
                   destWidth = imageHeight;
                   Log.v(LOG_TAG, "data length:" + data.length);
               }

               ByteBuffer bb = (ByteBuffer) yuvImage.image[0].position(0); // resets the buffer
               int start = 2 * ((imageWidth - destWidth) / 4); // this must be even
               for (int row = 0; row < imageHeight * 3 / 2; row++) {
                   bb.put(data, start, destWidth);
                   start += imageWidth;
               }

           }
       }
    }

    @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");
       }
    }}

    Changes made as per Alex Cohn’s suggestions

    Suggestion 1 - Estimate average frame rate

       public void stopRecording() {

      ..............................

                               if (((i % images.length) != 0) && images[i % images.length] != images[(i % images.length) - 1]) {
                                   if (t > recorder.getTimestamp()) {
                                       t += 1000000 / frameRate;
                                       recorder.setTimestamp(t);
                                   }

                                   recorder.record(images[i % images.length]);
                               }
                ..........................................


    }

    Change made was adding t += 1000000 / frameRate ; But this caused the video to freeze (as in case 1 described above) in portions when finger was placed away from screen.

    Suggestion 2 - Modification in onPreviewFrame()

    long[] timestampsForRecorder;
    private void initRecorder() {

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

       if (RECORD_LENGTH > 0) {
          .......................................................
           timestampsForRecorder = new long[images.length];
           for (int i = 0; i < images.length; i++) {
               images[i] = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
               timestamps[i] = -1;
               timestampsForRecorder[i] = -1;
           }
       } else if (yuvImage == null) {
           yuvImage = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
           Log.i(LOG_TAG, "create yuvImage");
       }
       ...................................................
    }

    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {
           if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
               startTime = SystemClock.elapsedRealtime();
               return;
           }
           if (RECORD_LENGTH > 0) {
               int i = imagesIndex++ % images.length;
               Log.v(LOG_TAG, "recording:" + recording + "rec:" + rec);
               if (recording && rec) {
                   yuvImage = images[i];
                   long thisFrameTime = SystemClock.elapsedRealtime();
                   timestamps[i] = thisFrameTime;
                   long lastFrameTime = timestamps[(int) (imagesIndex == 0 ? startTime : ((imagesIndex-1) % images.length))];
                   Log.v(LOG_TAG, "lastFrameTime:" + lastFrameTime+",stopPauseTime:" + stopPauseTime);
                   if (lastFrameTime > stopPauseTime) {
                       timestampsForRecorder[i] = 1000 * (thisFrameTime - Math.max(stopPauseTime, lastFrameTime));
                   }
               }
           }

          .....................................................
       }

    public void stopRecording() {

       .......................................................

       if (recorder != null && recording) {
           if (RECORD_LENGTH > 0) {
               Log.v(LOG_TAG, "Writing frames");
               try {
                   int firstIndex = imagesIndex % samples.length;
                   int lastIndex = (imagesIndex - 1) % images.length;
                   if (imagesIndex <= images.length) {
                       firstIndex = 0;
                       lastIndex = imagesIndex - 1;
                   }
                   if ((startTime = timestampsForRecorder[lastIndex] - RECORD_LENGTH * 1000000L) < 0) {
                       startTime = 0;
                   }
                   if (lastIndex < firstIndex) {
                       lastIndex += images.length;
                   }
                   for (int i = firstIndex; i <= lastIndex; i++) {

                       if (timestampsForRecorder[i] != -1) {
                           long t = timestampsForRecorder[i % timestampsForRecorder.length] - startTime;
                           if (t >= 0) {

                               if (((i % images.length) != 0) && images[i % images.length] != images[(i % images.length) - 1]) {
                                   if (t > recorder.getTimestamp()) {
                                       recorder.setTimestamp(t);
                                   }
                                   Log.v(LOG_TAG, "imageIndex=" + (i % images.length));
                                   recorder.record(images[i % images.length]);
                               }
                           }
                       }
                   }
                   .............................................
               } catch (FFmpegFrameRecorder.Exception e) {
                  .................................
               }
           }

           ...........................................

       }
    }

    The video recorded using this was having the issue in case 2 mentioned above. ie,It was playing at a faster rate

  • Android : Pass video path to FFmpeg

    7 janvier 2016, par marian

    I have developed an app that play video from gallery. I would like to add watermark using FFmpeg command in the video selected. But I do not know how to pass the path to the FFmpeg command. I could not find proper tutorials or reference regarding this. My coding are as follows :

    MainActivity.java :

    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.os.PowerManager;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    import android.widget.VideoView;

    import com.netcompss.ffmpeg4android.CommandValidationException;
    import com.netcompss.ffmpeg4android.GeneralUtils;
    import com.netcompss.ffmpeg4android.Prefs;
    import com.netcompss.ffmpeg4android.ProgressCalculator;
    import com.netcompss.loader.LoadJNI;

    public class MainActivity extends Activity {
    public ProgressDialog progressBar;

    String workFolder = null;
    String demoVideoFolder = null;
    String demoVideoPath = null;
    String vkLogPath = null;
    LoadJNI vk;
    private final int STOP_TRANSCODING_MSG = -1;
    private final int FINISHED_TRANSCODING_MSG = 0;
    private boolean commandValidationFailedFlag = false;

    Button button;
    VideoView videoView;
    private static final int PICK_FROM_GALLERY = 1;


    private void runTranscodingUsingLoader() {
       Log.i(Prefs.TAG, "runTranscodingUsingLoader started...");

       PowerManager powerManager = (PowerManager)MainActivity.this.getSystemService(Activity.POWER_SERVICE);
       PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VK_LOCK");
       Log.d(Prefs.TAG, "Acquire wake lock");
       wakeLock.acquire();



       String[] complexCommand = {"ffmpeg","-y" ,"-i", "/sdcard/videokit/in.mp4","-strict","experimental",
               "-vf", "movie=/sdcard/videokit/watermark.png [watermark];" +
               " [in][watermark] overlay=main_w-overlay_w-10:10 [out]","-s",
               "320x240","-r", "30", "-b", "15496k", "-vcodec", "mpeg4","-ab",
               "48000", "-ac", "2", "-ar", "22050", "/sdcard/videokit/out1.mp4"};
       ///////////////////////////////////////////////////////////////////////


       vk = new LoadJNI();
       try {
           // running complex command with validation
           vk.run(complexCommand, workFolder, getApplicationContext());

           // running without command validation
           //vk.run(complexCommand, workFolder, getApplicationContext(), false);

           // running regular command with validation
           //vk.run(GeneralUtils.utilConvertToComplex(commandStr), workFolder, getApplicationContext());

           Log.i(Prefs.TAG, "vk.run finished.");
           // copying vk.log (internal native log) to the videokit folder
           GeneralUtils.copyFileToFolder(vkLogPath, demoVideoFolder);

       } catch (CommandValidationException e) {
           Log.e(Prefs.TAG, "vk run exeption.", e);
           commandValidationFailedFlag = true;

       } catch (Throwable e) {
           Log.e(Prefs.TAG, "vk run exeption.", e);
       }
       finally {
           if (wakeLock.isHeld()) {
               wakeLock.release();
               Log.i(Prefs.TAG, "Wake lock released");
           }
           else{
               Log.i(Prefs.TAG, "Wake lock is already released, doing nothing");
           }
       }

       // finished Toast
       String rc = null;
       if (commandValidationFailedFlag) {
           rc = "Command Vaidation Failed";
       }
       else {
           rc = GeneralUtils.getReturnCodeFromLog(vkLogPath);
       }
       final String status = rc;
       MainActivity.this.runOnUiThread(new Runnable() {
           public void run() {
               Toast.makeText(MainActivity.this, status, Toast.LENGTH_LONG).show();
               if (status.equals("Transcoding Status: Failed")) {
                   Toast.makeText(MainActivity.this, "Check: " + vkLogPath + " for more information.", Toast.LENGTH_LONG).show();
               }
           }
       });
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       button = (Button) findViewById(R.id.button);

       videoView = (VideoView) findViewById(R.id.videoview);

       button.setOnClickListener(new View.OnClickListener() {

           public void onClick(View v) {
               // TODO Auto-generated method stub
               Intent intent = new Intent();

               intent.setType("video/*");
               intent.setAction(Intent.ACTION_GET_CONTENT);

               startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
           }
       });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
       if (resultCode != RESULT_OK) return;

       if (requestCode == PICK_FROM_GALLERY) {
           Uri mVideoURI = data.getData();
           videoView.setVideoURI(mVideoURI);
           videoView.start();
           demoVideoFolder = mVideoURI.getPath();
           demoVideoPath = demoVideoFolder;
           savevideo(mVideoURI);

       }


    }
    private Handler handler = new Handler() {
       @Override
       public void handleMessage(Message msg) {
           Log.i(Prefs.TAG, "Handler got message");
           if (progressBar != null) {
               progressBar.dismiss();

               // stopping the transcoding native
               if (msg.what == STOP_TRANSCODING_MSG) {
                   Log.i(Prefs.TAG, "Got cancel message, calling fexit");
                   vk.fExit(getApplicationContext());


               }
           }
       }
    };

    public void runTranscoding() {
       progressBar = new ProgressDialog(MainActivity.this);
       progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
       progressBar.setTitle("FFmpeg4Android Direct JNI");
       progressBar.setMessage("Press the cancel button to end the operation");
       progressBar.setMax(100);
       progressBar.setProgress(0);

       progressBar.setCancelable(false);
       progressBar.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
               handler.sendEmptyMessage(STOP_TRANSCODING_MSG);
           }
       });

       progressBar.show();

       new Thread() {
           public void run() {
               Log.d(Prefs.TAG,"Worker started");
               try {
                   //sleep(5000);
                   runTranscodingUsingLoader();
                   handler.sendEmptyMessage(FINISHED_TRANSCODING_MSG);

               } catch(Exception e) {
                   Log.e("threadmessage",e.getMessage());
               }
           }
       }.start();

       // Progress update thread
       new Thread() {
           ProgressCalculator pc = new ProgressCalculator(vkLogPath);
           public void run() {
               Log.d(Prefs.TAG,"Progress update started");
               int progress = -1;
               try {
                   while (true) {
                       sleep(300);
                       progress = pc.calcProgress();
                       if (progress != 0 && progress < 100) {
                           progressBar.setProgress(progress);
                       }
                       else if (progress == 100) {
                           Log.i(Prefs.TAG, "==== progress is 100, exiting Progress update thread");
                           pc.initCalcParamsForNextInter();
                           break;
                       }
                   }

               } catch(Exception e) {
                   Log.e("threadmessage",e.getMessage());
               }
           }
       }.start();
    }

    public void savevideo (Uri mVideoURI){
       demoVideoFolder = mVideoURI.getPath();
       demoVideoPath = demoVideoFolder;
       Log.i(Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(getApplicationContext()));

       Button invoke = (Button) findViewById(R.id.button);
       invoke.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               Log.i(Prefs.TAG, "run clicked.");
               runTranscoding();
           }
       });

       workFolder = getApplicationContext().getFilesDir() + "/";
       Log.i(Prefs.TAG, "workFolder (license and logs location) path: " + workFolder);
       vkLogPath = workFolder + "vk.log";
       Log.i(Prefs.TAG, "vk log (native log) path: " + vkLogPath);
       GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(this, workFolder);
       GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(this, demoVideoFolder);
       int rc = GeneralUtils.isLicenseValid(getApplicationContext(), workFolder);
       Log.i(Prefs.TAG, "License check RC: " + rc);

    }
    }

    ffmpeg command :

    String[] complexCommand = {"ffmpeg","-y" ,"-i",  "/sdcard/videokit/in.mp4","-strict","experimental",
               "-vf", "movie=/sdcard/videokit/watermark.png [watermark];" +
               " [in][watermark] overlay=main_w-overlay_w-10:10 [out]","-s",
               "320x240","-r", "30", "-b", "15496k", "-vcodec", "mpeg4","-ab",
               "48000", "-ac", "2", "-ar", "22050", "/sdcard/videokit/out1.mp4"};

    Tis command is from a sample project. How do i pass the video path to this command ? I do not know how to edit the command to support my requirement. Can someone guide me through this. Any help will be really helpful. Thank you.

  • Feeding MediaCodec with byte data from AVPacket : problems with output buffers

    2 mars 2016, par serg66

    Description of my task :
    I’m developing a video player on Android (API >= 17). It has to work both with HLS and multicast video. In addition, it has to support multiple audio tracks.

    Why I decided to use ffmpeg :

    • On some devices MediaPlayer doesn’t support multicast-video
    • MediaExtractor doesn’t work with HLS (getTrackCount() returns 0)
    • ffmpeg works both with HLS and multicast

    My idea :
    I demux a stream using ffmpeg in a loop. I get the CSD using videoStream->codec->extradata and then properly configure the MediaFormat. On each iteration when I have a new video AVPacket available, I filter it’s buffer using av_bitstream_filter_init to h264_mp4toannexb. Then I call the java method onNewVideoData, in which I get the AVPacket byte array. I clear the available input buffer, after that I fill it with the new data. I also get the pts. Since I have a stream with no beginning, additionally, I calculate new pts’ by subtracting the pts of the first AVPacket from all the following pts’. The first pts I assign to 0. Then I call queueInputBuffer to send the buffer to the decoder.

    I use two threads : one for getting and submitting data to the input buffers, and another one for posting it to the Surface.

    The full player c-code :

    #include
    #include <android></android>log.h>
    #include

    #include <libavformat></libavformat>avformat.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavutil></libavutil>buffer.h>

    #define TAG "ffmpegPlayer"

    struct
    {
       const char* url;
       jint width;
       jint height;
       jfloat aspectRatio;
       jint streamsCount;
       AVFormatContext* formatContext;
       AVStream* videoStream;
    } context;

    AVPacket packet;
    AVBitStreamFilterContext* avBitStreamFilterContext;

    JNIEXPORT jbyteArray JNICALL Java_com_example_app_FfmpegPlayer_getCsdNative(JNIEnv* env, jobject x)
    {
       jbyteArray arr = (*env)->NewByteArray(env, context.videoStream->codec->extradata_size);
       (*env)->SetByteArrayRegion(env, arr, 0, context.videoStream->codec->extradata_size, (jbyte*)context.videoStream->codec->extradata);

       return arr;
    }

    JNIEXPORT jint JNICALL Java_com_example_app_FfmpegPlayer_getWidthNative(JNIEnv* env, jobject x)
    {
       return context.width;
    }

    JNIEXPORT jint JNICALL Java_com_example_app_FfmpegPlayer_getHeightNative(JNIEnv* env, jobject x)
    {
       return context.height;
    }

    JNIEXPORT jfloat JNICALL Java_com_example_app_FfmpegPlayer_getAspectRatioNative(JNIEnv* env, jobject x)
    {
       return context.aspectRatio;
    }

    JNIEXPORT jfloat JNICALL Java_com_example_app_FfmpegPlayer_getStreamsCountNative(JNIEnv* env, jobject x)
    {
       return context.streamsCount;
    }

    JNIEXPORT jlong JNICALL Java_com_example_app_FfmpegPlayer_getPtsNative(JNIEnv* env, jobject obj)
    {
       return packet.pts * av_q2d(context.videoStream->time_base) * 1000000;
    }

    JNIEXPORT jboolean JNICALL Java_com_example_app_FfmpegPlayer_initNative(JNIEnv* env, jobject obj, const jstring u)
    {
       av_register_all();
       avBitStreamFilterContext = av_bitstream_filter_init("h264_mp4toannexb");

       const char* url = (*env)->GetStringUTFChars(env, u , NULL);
       __android_log_print(ANDROID_LOG_DEBUG, TAG, "Init: %s", url);

       AVFormatContext* formatContext = NULL;
       if (avformat_open_input(&amp;formatContext, url, NULL, NULL) &lt; 0) {
           __android_log_print(ANDROID_LOG_ERROR, TAG, "Unable to open input");
           return JNI_FALSE;
       }

       if (avformat_find_stream_info(formatContext, NULL) &lt; 0) {
           __android_log_print(ANDROID_LOG_ERROR, TAG, "Unable to find stream info");
           return JNI_FALSE;
       }

       AVInputFormat * iformat = formatContext->iformat;
       __android_log_print(ANDROID_LOG_DEBUG, TAG, "format: %s", iformat->name);

       context.streamsCount = formatContext->nb_streams;
       __android_log_print(ANDROID_LOG_DEBUG, TAG, "Streams count: %d", formatContext->nb_streams);

       int i = 0;
       AVStream* videoStream = NULL;
       AVDictionaryEntry* lang;
       for (i = 0; i &lt; formatContext->nb_streams; i++) {
           int codecType = formatContext->streams[i]->codec->codec_type;
           if (videoStream == NULL &amp;&amp; codecType == AVMEDIA_TYPE_VIDEO) {
               videoStream = formatContext->streams[i];
           }
           else if (codecType == AVMEDIA_TYPE_AUDIO) {
               lang = av_dict_get(formatContext->streams[i]->metadata, "language", NULL, 0);
               if (lang != NULL) {
                   __android_log_print(ANDROID_LOG_DEBUG, TAG, "Audio stream %d: %s", i, lang->value);
               }
           }
       }
       if (videoStream == NULL) {
           __android_log_print(ANDROID_LOG_ERROR, TAG, "Unable to find video stream");
           return JNI_FALSE;
       }
       context.videoStream = videoStream;
       __android_log_print(ANDROID_LOG_DEBUG, TAG, "Video stream:  %d", videoStream->index);

       AVCodecContext *codecContext = formatContext->streams[videoStream->index]->codec;

       __android_log_print(ANDROID_LOG_DEBUG, TAG, "width: %d, height: %d", codecContext->width, codecContext->height);
       context.width = codecContext->width;
       context.height = codecContext->height;

       AVRational aspectRatio = codecContext->sample_aspect_ratio;
       __android_log_print(ANDROID_LOG_DEBUG, TAG, "aspect ratio: %d/%d", aspectRatio.num, aspectRatio.den);
       context.aspectRatio = aspectRatio.num / aspectRatio.den;

       context.formatContext = formatContext;

       return JNI_TRUE;
    }

    void filterPacket()
    {
       av_bitstream_filter_filter(avBitStreamFilterContext, context.videoStream->codec, NULL, &amp;packet.data, &amp;packet.size, packet.data, packet.size, packet.flags);
    }

    JNIEXPORT void JNICALL Java_com_example_app_FfmpegPlayer_startNative(JNIEnv* env, jobject obj)
    {
       jclass cl = (*env)->GetObjectClass(env, obj);
       jmethodID updateMethodId = (*env)->GetMethodID(env, cl, "onNewVideoData", "()V");

       while (av_read_frame(context.formatContext, &amp;packet) >= 0) {
           if (context.formatContext == NULL) {
               return;
           }
           if (packet.stream_index == context.videoStream->index) {
               filterPacket();
               (*env)->CallVoidMethod(env, obj, updateMethodId);
           }
       }
    }

    JNIEXPORT jbyteArray JNICALL Java_com_example_app_FfmpegPlayer_getVideoDataNative(JNIEnv* env, jobject obj)
    {
       AVBufferRef *buf = packet.buf;

       jbyteArray arr = (*env)->NewByteArray(env, buf->size);
       (*env)->SetByteArrayRegion(env, arr, 0, buf->size, (jbyte*)buf->data);

       return arr;
    }

    The full Java-code :

    package com.example.app;


    import android.media.MediaCodec;
    import android.media.MediaFormat;
    import android.view.Surface;

    import java.nio.ByteBuffer;

    public class FfmpegPlayer {

       static {
           System.loadLibrary("avutil-54");
           System.loadLibrary("swscale-3");
           System.loadLibrary("swresample-1");
           System.loadLibrary("avcodec-56");
           System.loadLibrary("avformat-56");
           System.loadLibrary("avfilter-5");
           System.loadLibrary("ffmpeg-player");
       }

       private native boolean initNative(String url);
       private native boolean startNative();
       private native int getWidthNative();
       private native int getHeightNative();
       private native float getAspectRatioNative();
       private native byte[] getVideoDataNative();
       private native long getPtsNative();
       private native byte[] getCsdNative();

       private String source;
       private PlayerThread playerThread;
       private int width;
       private int height;
       private MediaCodec decoder;
       private ByteBuffer[] inputBuffers;
       private Surface surface;
       private long firstPtsTime;

       public PlanetaPlayer(Surface surface) {
           this.surface = surface;
       }

       public void setDataSource(String source) {
           if (!initNative(source)) {
               return;
           }
           width = getWidthNative();
           height = getHeightNative();
           MediaFormat format = MediaFormat.createVideoFormat("video/avc", width, height);
           format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, width * height);
           format.setByteBuffer("csd-0", ByteBuffer.wrap(getCsdNative()));
           LogUtils.log("CSD: ");
           outputAsHex(getCsdNative());
           try {
               decoder = MediaCodec.createDecoderByType("video/avc");
               decoder.configure(format, surface, null, 0);
               decoder.start();

               playerThread = new PlayerThread();
               playerThread.start();

               new OutputThread().run();
           }
           catch (Exception e) {
               e.printStackTrace();
           }
       }

       public void onNewVideoData() {
           int index = decoder.dequeueInputBuffer(0);
           if (index >= 0) {
               byte[] data = getVideoDataNative();
               ByteBuffer byteBuffer = decoder.getInputBuffers()[index];
               byteBuffer.clear();
               byteBuffer.put(data);
               long pts = getPtsNative();

               LogUtils.log("Input AVPacket pts: " + pts);
               LogUtils.log("Input AVPacket data length: " + data.length);
               LogUtils.log("Input AVPacket data: ");
               outputAsHex(data);

               if (firstPtsTime == 0) {
                   firstPtsTime = pts;
                   pts = 0;
               }
               else {
                   pts -= firstPtsTime;
               }
               decoder.queueInputBuffer(index, 0, data.length, pts, 0);
           }
       }

       private void outputAsHex(byte[] data) {
           String[] test = new String[data.length];
           for (int i = 0; i &lt; data.length; i++) {
               test[i] = String.format("%02x", data[i]);
           }
           LogUtils.log(test);
       }

       private class PlayerThread extends Thread {
           @Override
           public void run() {
               super.run();

               startNative();
           }
       }

       private class OutputThread extends Thread {

           @Override
           public void run() {
               super.run();
               MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
               while (true) {
                   int index = decoder.dequeueOutputBuffer(info, 0);
                   if (index >= 0) {
                       ByteBuffer buffer = decoder.getOutputBuffers()[index];
                       buffer.position(info.offset);
                       buffer.limit(info.offset + info.size);
                       byte[] test = new byte[info.size];
                       for (int i = 0; i &lt; info.size; i++) {
                           test[i] = buffer.get(i);
                       }
                       LogUtils.log("Output info: size=" + info.size + ", presentationTimeUs=" + info.presentationTimeUs + ",offset=" + info.offset + ",flags=" + info.flags);
                       LogUtils.log("Output data: ");
                       outputAsHex(test);
                       decoder.releaseOutputBuffer(index, true);
                   }
               }
           }
       }
    }

    The problem :
    For the tests I used a TS file with the following video stream :

    Codec: H264 - MPEG-4 AVC (part 10) (h264)
    Resolution: 720x578
    Frame rate: 25
    Decoded format: Planar 4:2:0 YUV

    The CSD is the following :

    [00, 00, 00, 01, 09, 10, 00, 00, 00, 01, 27, 4d, 40, 1e, 9a, 62, 01, 68, 48, b0, 44, 20, a0, a0, a8, 00, 00, 03, 00, 08, 00, 00, 03, 01, 94, a0, 00, 00, 00, 01, 28, ee, 3c, 80]

    On different devices I have different results. But I couldn’t achieve showing the video on the Surface.

    Input :

    Input AVPacket pts: 351519222
    Input AVPacket data length: 54941
    Input AVPacket data: [00, 00, 00, 01, 09, 10, 00, 00, 00, 01, 27, 4d, 40, 1e, 9a, 62, 01, 68, 48, b0, 44, 20, a0, a0, a8, 00, 00, 03, 00, 08, 00, 00, 03, 01, 94, a0, 00, 00, 00, 01,...]
    ------------------------------------
    Input AVPacket pts: 351539222
    Input AVPacket data length: 9605
    Input AVPacket data: [00, 00, 00, 01, 09, 30, 00, 00, 00, 01, 06, 01, 01, 24, 80, 00, 00, 00, 01, 21, e3, bd, da, e4, 46, c5, 8b, 6b, 7d, 07, 59, 23, 6f, 92, e9, fb, 3b, b9, 4d, f9,...]
    ------------------------------------
    Input AVPacket pts: 351439222
    Input AVPacket data length: 1985
    Input AVPacket data: [00, 00, 00, 01, 09, 50, 00, 00, 00, 01, 06, 01, 01, 14, 80, 00, 00, 00, 01, 21, a8, f2, 74, 69, 14, 54, 4d, c5, 8b, e8, 42, 52, ac, 80, 53, b4, 4d, 24, 1f, 6c,...]
    ------------------------------------
    Input AVPacket pts: 351459222
    Input AVPacket data length: 2121
    Input AVPacket data: [00, 00, 00, 01, 09, 50, 00, 00, 00, 01, 06, 01, 01, 24, 80, 00, 00, 00, 01, 21, a8, f3, 74, e9, 0b, 8b, 17, e8, 43, f8, 10, 88, ca, 2b, 11, 53, c8, 31, f0, 0b,...]
    ... on and on

    Asus Zenfone (Android 5.0.2) output thread (after decoding, strange results with 25 buffers of only 8 byte data) :

    Output info: size=8, presentationTimeUs=-80001,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, 90, c5, 99, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=0,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, 78, ea, 86, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=720000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e8, 86, b6, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=780000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, c0, cb, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=840000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, 80, 87, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=960000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e0, 3f, 8b, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=1040000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, f8, 76, 85, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=1180000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e0, 87, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=1260000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e8, b5, d2, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=1800000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, 90, c5, 99, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=1860000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e0, c0, 84, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=2080000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, c0, cb, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=3440000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, 80, 87, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=3520000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, 78, ea, 86, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4160000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e8, 86, b6, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4300000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e0, 3f, 8b, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4400000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, 90, c5, 99, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4480000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, f8, 76, 85, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4680000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, c0, cb, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4720000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e0, c0, 84, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4760000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e0, 87, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=4800000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, 58, 54, 83, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=5040000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, e8, b5, d2, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=5100000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, 80, 87, 93, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=5320000,offset=0,flags=0
    Output data:
    [01, 00, 00, 00, 78, ea, 86, ac]
    ---------------------------
    Output info: size=8, presentationTimeUs=5380000,offset=0,flags=1
    Output data:
    [01, 00, 00, 00, e8, 86, b6, ac]

    Other Asus Zenfone logs :

    01-25 17:11:36.859 4851-4934/com.example.app I/OMXClient: Using client-side OMX mux.
    01-25 17:11:36.865 317-1075/? I/OMX-VDEC-1080P: component_init: OMX.qcom.video.decoder.avc : fd=43
    01-25 17:11:36.867 317-1075/? I/OMX-VDEC-1080P: Capabilities: driver_name = msm_vidc_driver, card = msm_vdec_8974, bus_info = , version = 1, capabilities = 4003000
    01-25 17:11:36.881 317-1075/? I/OMX-VDEC-1080P: omx_vdec::component_init() success : fd=43
    01-25 17:11:36.885 4851-4934/com.example.app I/ACodec: [OMX.qcom.video.decoder.avc] DRC Mode: Dynamic Buffer Mode
    01-25 17:11:36.893 317-20612/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.933 317-12269/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.933 317-12269/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.935 317-5559/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.957 317-5559/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.957 4851-4934/com.example.app I/ExtendedCodec: Decoder will be in frame by frame mode
    01-25 17:11:36.963 317-1075/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.963 317-1075/? E/C2DColorConvert: unknown format passed for luma alignment number
    01-25 17:11:36.964 317-20612/? E/OMX-VDEC-1080P: Extension: OMX.google.android.index.describeColorFormat not implemented
    01-25 17:11:37.072 317-20612/? E/OMX-VDEC-1080P: Extension: OMX.google.android.index.describeColorFormat not implemented
    01-25 17:11:37.072 4851-4934/com.example.app W/ACodec: do not know color format 0x7fa30c04 = 2141391876

    Asus Nexus 7 (Android 6.0.1) crashes :

    01-25 17:23:06.921 11602-11695/com.example.app I/OMXClient: Using client-side OMX mux.
    01-25 17:23:06.952 11602-11694/com.example.app I/MediaCodec: [OMX.qcom.video.decoder.avc] setting surface generation to 11880449
    01-25 17:23:06.954 194-194/? E/OMX-VDEC-1080P: Extension: OMX.google.android.index.storeANWBufferInMetadata not implemented
    01-25 17:23:06.954 194-194/? E/OMX-VDEC-1080P: Extension: OMX.google.android.index.storeMetaDataInBuffers not implemented
    01-25 17:23:06.954 194-194/? E/OMXNodeInstance: getExtensionIndex(45:qcom.decoder.avc, OMX.google.android.index.storeMetaDataInBuffers) ERROR: NotImplemented(0x80001006)
    01-25 17:23:06.954 11602-11695/com.example.app E/ACodec: [OMX.qcom.video.decoder.avc] storeMetaDataInBuffers failed w/ err -2147483648
    01-25 17:23:06.963 11602-11695/com.example.app D/SurfaceUtils: set up nativeWindow 0xa0b7a108 for 720x576, color 0x7fa30c03, rotation 0, usage 0x42002900
    01-25 17:23:06.967 194-604/? E/OMX-VDEC-1080P: GET_MV_BUFFER_SIZE returned: Size: 122880 and alignment: 8192
    01-25 17:23:07.203 11602-11695/com.example.app W/AHierarchicalStateMachine: Warning message AMessage(what = 'omxI') = {
                                                                            int32_t type = 0
                                                                            int32_t event = 2130706432
                                                                            int32_t data1 = 1
                                                                            int32_t data2 = 0
                                                                          } unhandled in root state.
    01-25 17:23:07.232 11602-11695/com.example.app D/SurfaceUtils: set up nativeWindow 0xa0b7a108 for 720x576, color 0x7fa30c03, rotation 0, usage 0x42002900
    01-25 17:23:07.241 194-194/? E/OMX-VDEC-1080P: GET_MV_BUFFER_SIZE returned: Size: 122880 and alignment: 8192
    01-25 17:23:07.242 194-194/? E/OMX-VDEC-1080P: Insufficient sized buffer given for playback, expected 671744, got 663552
    01-25 17:23:07.242 194-194/? E/OMXNodeInstance: useBuffer(45:qcom.decoder.avc, Output:1 671744@0xb60a0860) ERROR: BadParameter(0x80001005)
    01-25 17:23:07.243 11602-11695/com.example.app E/ACodec: registering GraphicBuffer 0 with OMX IL component failed: -2147483648
    01-25 17:23:07.243 11602-11695/com.example.app E/ACodec: Failed to allocate output port buffers after port reconfiguration: (-2147483648)
    01-25 17:23:07.243 11602-11695/com.example.app E/ACodec: signalError(omxError 0x80001001, internalError -2147483648)
    01-25 17:23:07.243 11602-11694/com.example.app E/MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 6
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err: java.lang.IllegalStateException
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2379)
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at com.example.app.FfmpegPlayer$OutputThread.run(FfmpegPlayer.java:122)
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at com.example.app.FfmpegPlayer.setDataSource(FfmpegPlayer.java:66)
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at com.example.app.activities.TestActivity$2.surfaceCreated(TestActivity.java:151)
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at android.view.SurfaceView.updateWindow(SurfaceView.java:583)
    01-25 17:23:07.245 11602-11602/com.example.app W/System.err:     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2055)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.Choreographer.doFrame(Choreographer.java:606)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.os.Looper.loop(Looper.java:148)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    01-25 17:23:07.246 11602-11602/com.example.app W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

    Another device always has empty output buffers, thought the indexes aren >= 0 ;

    What am I doing wrong ?