Can I play mp4 tracks for multiple audio tracks on my browser?

Asked 2 years ago, Updated 2 years ago, 77 views

I want to specify the tracks of mp4 files containing multiple audio tracks and play them. In the end, I would like to play track 1 with L and track 2 with R.
The browser is Chrome.

I thought I could do it with WebAudioAPI, but it doesn't work.(Loading documents may be easy)

The one I tried below is to specify a track and play it in LR.

If WebAudioAPI is not available, is there an alternative?

<html>
  <head>
    <script type="text/javascript"src="./jquery/jquery-1.11.3.min.js"></script>
  </head>
  <body>
    <video id="player" src=".test.mp4" height="300" controls></video>
    <br of >
    <button type="button" class="track" data-track="0">1</button>
    <button type="button" class="track" data-track="1">2</button>
    <button type="button" class="track" data-track="2">3</button>
    <button type="button" class="track" data-track="3">4</button>
    <button type="button" class="track" data-track="4">5</button>
    <button type="button" class="track" data-track="5">6</button>
    <button type="button" class="track" data-track="6">7</button>
    <button type="button" class="track" data-track="7">8</button>

    <script type="text/javascript">
      varplayer= document.getElementById('player');
      varaudioCtx=new(window.AudioContext||window.WebKitAudioContext)();
      varaudioSource=audioCtx.createMediaElementSource(player);

      trackSelect=function(track){
        varsplitter=audioCtx.createChannelSplitter(8); // I'm dividing it into 8 tracks...
        varmerger=audioCtx.createChannelMerger(2);

        audioSource.disconnect();
        audioSource.connect(splitter);

        splitter.connect (merger, track, 0); //L specification
        splitter.connect(merger, track, 1); //R specification
        merge.connect(audioCtx.destination);
      };
      player.onplay=function(){
        audioCtx.resume();
      };
      player.onpause=function(){
        audioCtx.suspend();
      };

      trackSelect(0);

      $('.track').on('click', function(){
        trackSelect (+$(this).data('track'));
      });
    </script>
  </body>
</html>

javascript video

2022-09-29 22:17

1 Answers

Thank you for your comment.
Extract audio per track with ffmpeg from mp4 file
I will prepare the audio (video) tag for a few tracks and play it simultaneously.


2022-09-29 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.