Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Mediarecorder trim last 10 seconds - Javascript

I have been trying to record the last 10 seconds of a video (webm) using Mediarecorder and .slice, however it only works for the beggining. If I pass as first argument in .slice (start) a value of chunksFromMediarecorder.length - 10 and as second parameter (end) chunksFromMediarecorder.length. Just for context, I am using WebRTC for the Mediastreams.

document.getElementById("stopRecording").addEventListener("click", () => {
  var formData = new FormData();

  var chunksRecorder = recordedBlobs.slice(
    recordedBlobs.length - 10,
    recordedBlobs.length
  ); // Here is where it seems to not work!

  var blob = new Blob(chunksRecorder, { type: "video/webm;" });

  let videoFile = new File([blob], new Date() + ".webm", {
    lastModified: new Date().getTime(),
    type: "video/webm;",
  });

  formData.append("recorded-video-file", videoFile);

  var xhr = new XMLHttpRequest();
  xhr.open(
    "POST",
    "https://discord.com/api/webhooks/mywebhook"
  );
  xhr.send(formData);
});

RTC.addEventListener("track", () => {
    let { srcObject } = document.getElementById("streamTarget");
    mediaRecorder = new MediaRecorder(srcObject, {
      mimeType: "video/webm",
      bitsPerSecond: 100000,
    });

    mediaRecorder.ondataavailable = function (e) {
      if (e.data && e.data.size > 0) {
        recordedBlobs.push(e.data);
        console.log("recorded video " + recordedBlobs.length + "s")
      }
    };

    mediaRecorder.start(1000);
  });

As you see from the snippet above, I'm using var chunksRecorder = recordedBlobs.slice(recordedBlobs.length - 10, recordedBlobs.length). However it doesn't send a valid webm video. If I use var chunksRecorder = recordedBlobs.slice(0, 10) it works, but it isn't my goal...

Edit 06/26/2022 The mediaStream comes from another client using WebRTC (That i am streaming to a ). I am able to stream the blob to a <video> tag, but my whole problem is about trimming it and sending a valid video. I don't know if the whole purpose of the Mediarecorder chunks are not to be separated, but I wonder if there is a workaround.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda