Recherche avancée

Médias (1)

Mot : - Tags -/ticket

Autres articles (49)

  • Qu’est ce qu’un éditorial

    21 juin 2013, par

    Ecrivez votre de point de vue dans un article. Celui-ci sera rangé dans une rubrique prévue à cet effet.
    Un éditorial est un article de type texte uniquement. Il a pour objectif de ranger les points de vue dans une rubrique dédiée. Un seul éditorial est placé à la une en page d’accueil. Pour consulter les précédents, consultez la rubrique dédiée.
    Vous pouvez personnaliser le formulaire de création d’un éditorial.
    Formulaire de création d’un éditorial Dans le cas d’un document de type éditorial, les (...)

  • MediaSPIP Player : problèmes potentiels

    22 février 2011, par

    Le lecteur ne fonctionne pas sur Internet Explorer
    Sur Internet Explorer (8 et 7 au moins), le plugin utilise le lecteur Flash flowplayer pour lire vidéos et son. Si le lecteur ne semble pas fonctionner, cela peut venir de la configuration du mod_deflate d’Apache.
    Si dans la configuration de ce module Apache vous avez une ligne qui ressemble à la suivante, essayez de la supprimer ou de la commenter pour voir si le lecteur fonctionne correctement : /** * GeSHi (C) 2004 - 2007 Nigel McNie, (...)

  • MediaSPIP Player : les contrôles

    26 mai 2010, par

    Les contrôles à la souris du lecteur
    En plus des actions au click sur les boutons visibles de l’interface du lecteur, il est également possible d’effectuer d’autres actions grâce à la souris : Click : en cliquant sur la vidéo ou sur le logo du son, celui ci se mettra en lecture ou en pause en fonction de son état actuel ; Molette (roulement) : en plaçant la souris sur l’espace utilisé par le média (hover), la molette de la souris n’exerce plus l’effet habituel de scroll de la page, mais diminue ou (...)

Sur d’autres sites (7685)

  • Revision 32737 : habillage par defaut de Zpip utilise les conventions documentees

    8 novembre 2009, par cedric@… — Log

    habillage par defaut de Zpip utilise les conventions documentees

  • 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

  • Attribution Tracking (What It Is and How It Works)

    23 février 2024, par Erin

    Facebook, TikTok, Google, email, display ads — which one is best to grow your business ? There’s one proven way to figure it out : attribution tracking.

    Marketing attribution allows you to see which channels are producing the best results for your marketing campaigns.

    In this guide, we’ll show you what attribution tracking is, why it’s important and how you can leverage it to accelerate your marketing success.

    What is attribution tracking ?

    By 2026, the global digital marketing industry is projected to reach $786.2 billion.

    With nearly three-quarters of a trillion U.S. dollars being poured into digital marketing every year, there’s no doubt it dominates traditional marketing.

    The question is, though, how do you know which digital channels to use ?

    By measuring your marketing efforts with attribution tracking.

    What is attribution tracking?

    So, what is attribution tracking ?

    Attribution tracking is where you use software to keep track of different channels and campaign efforts to determine which channel you should attribute conversion to.

    In other words, you can (and should) use attribution tracking to analyse which channels are pushing the needle and which ones aren’t.

    By tracking your marketing efforts, you’ll be able to accurately measure the scale of impact each of your channels, campaigns and touchpoints have on a customer’s purchasing decision.

    If you don’t track your attribution, you’ll end up blindly pouring time, money, and effort into activities that may or may not be helpful.

    Attribution tracking simply gives you insight into what you’re doing right as a marketer — and what you’re doing wrong.

    By understanding which efforts and channels are driving conversions and revenue, you’ll be able to properly allocate resources toward winning channels to double down on growth.

    Matomo lets you track attribution across various channels. Whether you’re looking to track your conversions through organic, referral websites, campaigns, direct traffic, or social media, you can see all your conversions in one place.

    Try Matomo for Free

    Get the web insights you need, without compromising data accuracy.

    No credit card required

    Why attribution tracking is important

    Attribution tracking is crucial to succeed with your marketing since it shows you your most valuable channels.

    It takes the guesswork out of your efforts.

    You don’t need to scratch your head wondering what made your campaigns a success (or a failure).

    While most tools show you last click attribution by default, using attribution tracking, or marketing attribution, you can track revenue and conversions for each touchpoint.

    For example, a Facebook ad might have no led to a conversion immediately. But, maybe the visitor returned to your website two weeks later through your email campaign. Attribution tracking will give credit over longer periods of time to see the bigger picture of how your marketing channels are impacting your overall performance.

    Here are five reasons you need to be using attribution tracking in your business today :

    Why attribution tracking is important.

    1. Measure channel performance

    The most obvious way attribution tracking helps is to show you how well each channel performs.

    When you’re using a variety of marketing channels to reach your audience, you have to know what’s actually doing well (and what’s not).

    This means having clarity on the performance of your :

    • Emails
    • Google Ads
    • Facebook Ads
    • Social media marketing
    • Search engine optimisation (SEO)
    • And more

    Attribution tracking allows you to measure each channel’s ROI and identify how much each channel impacted your campaigns.

    It gives you a more accurate picture of the performance of each channel and each campaign.

    With it, you can easily break down your channels by how much they drove sales, conversions, signups, or other actions.

    With this information, you can then understand where to further allocate your resources to fuel growth.

    2. See campaign performance over longer periods of time

    When you start tracking your channel performance with attribution tracking, you’ll gain new insights into how well your channels and campaigns are performing.

    The best part — you don’t just get to see recent performance.

    You get to track your campaign results over weeks or months.

    For example, if someone found you through Google by searching a question that your blog had an answer to, but they didn’t convert, your traditional tracking strategy would discount SEO.

    But, if that same person clicked a TikTok ad you placed three weeks later, came back, and converted — SEO would receive some attribution on the conversion.

    Using an attribution tracking tool like Matomo can help paint a holistic view of how your marketing is really doing from channel to channel over the long run.

    Try Matomo for Free

    Get the web insights you need, without compromising data accuracy.

    No credit card required

    3. Increase revenue

    Attribution tracking has one incredible benefit for marketers : optimised marketing spend.

    When you begin looking at how well your campaigns and your channels are performing, you’ll start to see what’s working.

    Attribution tracking gives you clarity into the performance of campaigns since it’s not just looking at the first time someone clicks through to your site. It’s looking at every touchpoint a customer made along the way to a conversion.

    By understanding what channels are most effective, you can pour more resources like time, money and labour into those effective channels.

    By doubling down on the winning channels, you’ll be able to grow like never before.

    Rather than trying to “diversify” your marketing efforts, lean into what’s working.

    This is one of the key strategies of an effective marketer to maximise your campaign returns and experience long-term success in terms of revenue.

    4. Improve profit margins

    The final benefit to attribution tracking is simple : you’ll earn more profit.

    Think about it this way : let’s say you’re putting 50% of your marketing spend into Facebook ads and 50% of your spend into email marketing.

    You do this for one year, allocating $500,000 to Facebook and $500,000 to email.

    Then, you start tracking attribution.

    You find that your Facebook ads are generating $900,000 in revenue. 

    That’s a 1,800% return on your investment.

    Not bad, right ?

    Well, after tracking your attribution, you see what your email revenue is.

    In the past year, you generated $1.7 million in email revenue.

    That’s a 3,400% return on your investment (close to the average return of email marketing across all industries).

    In this scenario, you can see that you’re getting nearly twice as much of a return on your marketing spend with email.

    So, the following year, you decide to go for a 75/25 split.

    Instead of putting $500,000 into both email and Facebook ads and email, you put $750,000 into email and $250,000 into Facebook ads.

    You’re still diversifying, but you’re doubling down on what’s working best.

    The result is that you’ll be able to get more revenue by investing the same amount of money, leaving you with higher profit margins.

    Different types of marketing attribution tracking

    There are several types of attribution tracking models in marketing.

    Depending on your goals, your business and your preferred method, there are a variety of types of attribution tracking you can use.

    Here are the six main types of attribution tracking :

    Pros and cons of different marketing attribution models.

    1. Last interaction

    Last interaction attribution model is also called “last touch.”

    It’s one of the most common types of attribution. The way it works is to give 100% of the credit to the final channel a customer interacted with before they converted into a customer.

    This could be through a paid ad, direct traffic, or organic search.

    One potential drawback of last interaction is that it doesn’t factor in other channels that may have assisted in the conversion. However, this model can work really well depending on the business.

    2. First interaction

    This is the opposite of the previous model.

    First interaction, or “first touch,” is all about the first interaction a customer has with your brand.

    It gives 100% of the credit to the channel (i.e. a link clicked from a social media post). And it doesn’t report or attribute anything else to another channel that someone may have interacted with in your marketing mix.

    For example, it won’t attribute the conversion or revenue if the visitor then clicked on an Instagram ad and converted. All credit would be given to the first touch which in this case would be the social media post. 

    The first interaction is a good model to use at the top of your funnel to help establish which channels are bringing leads in from outside your audience.

    3. Last non-direct

    Another model is called the last non-direct attribution model. 

    This model seeks to exclude direct traffic and assigns 100% credit for a conversion to the final channel a customer interacted with before becoming a customer, excluding clicks from direct traffic.

    For instance, if someone first comes to your website from an emai campaignl, and then, a week later, directly visits and buys a product, the email campaign gets all the credit for the sale.

    This attribution model tells a bit more about the whole sales process, shedding some more light on what other channels may have influenced the purchase decision.

    4. Linear

    Another common attribution model is linear.

    This model distributes completely equal credit across every single touchpoint (that’s tracked). 

    Imagine someone comes to your website in different ways : first, they find it through a Google search, then they click a link in an email from your campaign the next day, followed by visiting from a Facebook post a few days later, and finally, a week later, they come from a TikTok ad. 

    Here’s how the attribution is divided among these sources :

    • 25% Organic
    • 25% Email
    • 25% Facebook
    • 25% TikTok ad

    This attirubtion model provides a balanced perspective on the contribution of various sources to a user’s journey on your website.

    5. Position-based

    Position-based attribution is when you give 40% credit to both the first and last touchpoints and 20% credit is spread between the touchpoints in between.

    This model is preferred if you want to identify the initial touchpoint that kickstarted a conversion journey and the final touchpoint that sealed the deal.

    The downside is that you don’t gain much insight into the middle of the customer journey, which can make it hard to make effective decisions.

    For example, someone may have been interacting with your email newsletter for seven weeks, which allowed them to be nurtured and build a relationship with you.

    But that relationship and trust-building effort will be overlooked by the blog post that brought them in and the social media ad that eventually converted them.

    6. Time decay

    The final attribution model is called time decay attribution.

    This is all about giving credit based on the timing of the interactions someone had with your brand.

    For example, the touchpoints that just preceded the sale get the highest score, while the first touchpoints get the lowest score.

    For example, let’s use that scenario from above with the linear model :

    • 25% SEO
    • 25% Email
    • 25% Facebook ad
    • 25% Organic TikTok

    But, instead of splitting credit by 25% to each channel, you weigh the ones closer to the sale with more credit.

    Instead, time decay may look at these same channels like this :

    • 5% SEO (6 weeks ago)
    • 20% Email (3 weeks ago)
    • 30% Facebook ad (1 week ago)
    • 45% Organic TikTok (2 days ago)

    One downside is that it underestimates brand awareness campaigns. And, if you have longer sales cycles, it also isn’t the most accurate, as mid-stage nurturing and relationship building are underlooked. 

    Leverage Matomo : A marketing attribution tool

    Attribution tracking is a crucial part of leading an effective marketing strategy.

    But it’s impossible to do this without the right tools.

    A marketing attribution tool can give you insights into your best-performing channels automatically. 

    What is a marketing attribution tool?

    One of the best marketing attribution tools available is Matomo, a web analytics tool that helps you understand what’s going on with your website and different channels in one easy-to-use dashboard.

    With Matomo, you get marketing attribution as a plug-in or within Matomo On-Premise or for free in Matomo Cloud.

    The best part is it’s all done with crystal-clear data. Matomo gives you 100% accurate data since it doesn’t use data sampling on any plans like Google Analytics.

    To start tracking attribution today, try Matomo’s 21-day free trial. No credit card required.