<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hatim Tekri</title>
    <description>The latest articles on DEV Community by Hatim Tekri (@hatimtekri).</description>
    <link>https://dev.to/hatimtekri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F869742%2F2991b715-6044-4eb7-820a-b38d9c6705cd.jpeg</url>
      <title>DEV Community: Hatim Tekri</title>
      <link>https://dev.to/hatimtekri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hatimtekri"/>
    <language>en</language>
    <item>
      <title>Merge multiple Media Stream and save into a single file in React js</title>
      <dc:creator>Hatim Tekri</dc:creator>
      <pubDate>Mon, 30 May 2022 15:17:53 +0000</pubDate>
      <link>https://dev.to/hatimtekri/merge-multiple-media-stream-and-save-into-a-single-file-in-react-js-24c0</link>
      <guid>https://dev.to/hatimtekri/merge-multiple-media-stream-and-save-into-a-single-file-in-react-js-24c0</guid>
      <description>&lt;p&gt;if you are creating webrtc application or any media stream based application and you want to record multiple media streams into one file and then export the merged stream file in the respected format then read this article carefully.&lt;/p&gt;

&lt;p&gt;in this article, I have explained the media stream recording in two parts,&lt;/p&gt;

&lt;h4&gt;
  
  
  1. mix and record multiple audio streams into one file.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  2. mix and record multiple video streams into one file.
&lt;/h4&gt;

&lt;h2&gt;
  
  
  mix and record multiple audio streams into one file
&lt;/h2&gt;

&lt;p&gt;first, install this libraries&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install multistreamsmixer&lt;br&gt;
npm install recordrtc&lt;br&gt;
npm install file-saver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then,import all the libraries&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import MultiStreamsMixer from 'multistreamsmixer';
import RecordRTC, { getSeekableBlob, MultiStreamRecorder } from "recordrtc";
import { saveAs } from 'file-saver';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then write this code to mix and record the audio streams.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const streammixer = new MultiStreamsMixer([stream1, stream2]);
let recorder = RecordRTC(streammixer.getMixedStream(), {type:'audio',mimeType: 'audio/wav'});      
recorder.startRecording();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now write this code to stop and save the mix recorded stream.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;recorder.stopRecording(function () {
  let blob = recorder.getBlob();          
     getSeekableBlob(blob, function (seekableBlob) {
         saveAs(seekableBlob, "filename"+ ".mp4");            
     });          
 });
 recorder.destroy();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this is how you can mix and record the multiple audio streams and then save it in any format you want.&lt;br&gt;
this seekable function is help to make the audio file seekable otherwise it will not be seekable if you not use this function.&lt;/p&gt;
&lt;h2&gt;
  
  
  mix and record multiple video streams into one file
&lt;/h2&gt;

&lt;p&gt;first, install this libraries&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install multistreamsmixer&lt;br&gt;
npm install recordrtc&lt;br&gt;
npm install file-saver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then,import all the libraries&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import MultiStreamsMixer from 'multistreamsmixer';
import RecordRTC, { getSeekableBlob, MultiStreamRecorder } from "recordrtc";
import { saveAs } from 'file-saver';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then write this code to mix and record the audio streams.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let mixAV = new MultiStreamRecorder([stream1, stream2],{
            mimeType: 'video/mp4'
          });
mixAV  = mixTeacherStudentAV;
mixAV.record();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now write this code to stop and save the mix recorded stream.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mixAV.stop(function(blob) {
      getSeekableBlob(blob, function(seekableBlob) {
        saveAs(seekableBlob, "filename"+ ".mp4");        
      });
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this is how you can mix and record the multiple video streams and then save it in any format you want.&lt;br&gt;
this seekable function is help to make the video file seekable otherwise it will not be seekable if you not use this function.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webrtc</category>
      <category>stream</category>
    </item>
  </channel>
</rss>
