Recherche avancée

Médias (91)

Autres articles (21)

  • 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 ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (4702)

  • Android merging PCM and MP3 into AAC

    4 février 2019, par kataroty

    I have a program that records user input sound as PCM (I needed to do it separately to "play" with the voice) and then I also have a custom audio track, which is in MP3 format, that I want merge with the PCM file.

    To start off I convert both of them to WAV separately, then I combine the 2 WAV files, and finally convert the result to AAC because I also need to merge the audio with video later.

    I tried merging 2 AAC files, but that did not work out for me.

    For audio conversion I am using FFmpeg-Android.

    The problem is that it takes way too long, around 1-2min to do the whole conversion and because of that I need a new way to do it all. I have looked into other libraries but this was the only one I could get to work.

    Can someone recommend something that would do the whole process faster ?

    Here is my code to merge all of the files :

    public class AudioProcessor {

       private Context context;
       private FFmpeg ffmpeg;
       private AudioProcessorListener listener;

       private File micPcmFile;
       private File backgroundMp3File;

       private File pcmtowavTempFile;
       private File mp3towavTempFile;
       private File combinedwavTempFile;

       private File outputFile;
       private File volumeChangedTempFile;

       private FFtask currentTask;

       private int videoRecordingLength = 0;

       TextView extensionDownload, percentProgress;

       private static final String TAG = "FFMPEG AV Processor";

       public AudioProcessor(Context context, Activity activity) {
           ffmpeg = null;
           ffmpeg = FFmpeg.getInstance(context);
           percentProgress = activity.findViewById(R.id.percentProgress);
           percentProgress.setSingleLine(false);
           this.context = context;
           prepare();
       }

       /**
        * Program main method. Starts running program
        * @throws Exception
        */
       public void process() throws Exception {
           if (!ffmpeg.isSupported()) {
               Log.e(TAG, "FFMPEG not supported! Cannot convert audio!");
               throw new RuntimeException("FFMPeg has to be supported");
           }
           if (!checkIfAllFilesPresent()) {
               Log.e(TAG, "All files are not set yet. Please set file first");
               throw new RuntimeException("Files are not set!");
           }

           Log.e(TAG, "Start processing audio!");
           listener.onStart();

           Handler handler = new Handler();
           handler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   convertPCMToWav();
               }
           }, 200);
       }

       /**
        * Prepares program
        */
       private void prepare() {
           Log.d(TAG, "Preparing everything...");
           prepareTempFiles();
       }

       /**
        * Converts PCM to wav file. Automatically create new file.
        */
       private void convertPCMToWav() {
           Log.d(TAG, "Convert PCM TO Wav");
           //ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav
           String[] cmd = { "-f" , "s16le", "-ar", "44.1k", "-i", micPcmFile.toString(), "-y", pcmtowavTempFile.toString()};
           currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setVisibility(View.VISIBLE);
                   percentProgress.setText("Converting your recording\n"+"1/5");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   convertMP3ToWav();
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   onError(message);
                   convertPCMToWav();
               }
           });
       }

       /**
        * Converts mp3 file to wav file.
        * Automatically creates Wav file
        */
       private void convertMP3ToWav() {
           Log.e(TAG, "Convert MP3 TO Wav");

           //ffmpeg -ss 0 -t 30 -i file.mp3 file.wav
           //String[] cmd = { "-ss", "0", "-t", Integer.toString(videoRecordingLength), "-i" , backgroundMp3File.toString(), "-y", mp3towavTempFile.toString() };
           String[] cmd = {  "-i" , backgroundMp3File.toString(), "-y", mp3towavTempFile.toString() };
           currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Converting background audio\n"+"2/5");
                   Log.d(TAG, "Convert MP3 TO Wav");
               }
               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   changeMicAudio();
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   Log.e(TAG, "Failed to convert MP3 TO Wav");
                   onError(message);
                   throw new RuntimeException("Failed to convert MP3 TO Wav");
               }
           });
       }

       /**
        * Combines 2 wav files into one wav file. Overlays audio
        */
       private void combineWavs() {
           Log.e(TAG, "Combine wavs");
           //ffmpeg -i C:\Users\VR1\Desktop\_mp3.wav -i C:\Users\VR1\Desktop\_pcm.wav -filter_complex amix=inputs=2:duration=first:dropout_transition=3 C:\Users\VR1\Desktop\out.wav

           String[] cmd = { "-i" , pcmtowavTempFile.toString(), "-i", volumeChangedTempFile.toString(), "-filter_complex", "amix=inputs=2:duration=first:dropout_transition=3", "-y",combinedwavTempFile.toString()};
           currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Combining the two audio files\n"+"4/5");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   encodeWavToAAC();

               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   onError(message);
               }
           });
       }

       private void changeMicAudio(){
           Log.e(TAG, "Change audio volume");
           //ffmpeg -i input.wav -filter:a "volume=1.5" output.wav

           String[] cmdy = { "-i", mp3towavTempFile.toString(),  "-af", "volume=0.9", "-y",volumeChangedTempFile.toString()};
           currentTask = ffmpeg.execute(cmdy, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Normalizing volume\n"+"3/5");
               }

               @Override
               public void onSuccess(String message) {
                   combineWavs();
                   super.onSuccess(message);
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   Log.e("AudioProcessor", message);
               }
           });
       }


       /**
        * Do something on error. Releases program data (deletes files)
        * @param message
        */
       private void onError(String message) {
           completed();
           if (listener != null) {
               //listener.onError(message);
           }
       }
       /**
        * Encode to AAC
        */
       private void encodeWavToAAC() {
           Log.d(TAG, "Encode Wav file to AAC");
           //ffmpeg -i file.wav -c:a aac -b:a 128k -f adts output.m4a
           String[] cmd = { "-i" , combinedwavTempFile.toString(), "-c:a", "aac", "-b:a", "128k", "-f", "adts", "-y",outputFile.toString()};
           currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Normalizing volume\n"+"3/5");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   if (listener != null) {
                       listener.onSuccess(outputFile);
                   }
                   completed();
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   onError(message);
                   encodeWavToAAC();
               }
           });
       }

       /**
        * Uninitializes class
        */
       private void completed() {
           if (listener != null) {
               listener.onFinish();
           }
           Log.d(TAG, "Process completed successfully!");
           destroyTempFiles();
       }

       /**
        * Prepares temp required files by deleteing them if they exsist.
        * Files cannot exists before ffmpeg actions. FFMpeg automatically creates those files.
        */
       private void prepareTempFiles() {
           Log.d(TAG, "Preparing Temp files...");
           pcmtowavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_pcm.wav");
           mp3towavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_mp3.wav");
           combinedwavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_combined.wav");
           volumeChangedTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_volumeChanged.wav");
       }

       /**
        * Destroys temp required files
        */
       private void destroyTempFiles() {
           Log.d(TAG, "Destroying Temp files...");
           pcmtowavTempFile.delete();
           mp3towavTempFile.delete();
           combinedwavTempFile.delete();
           volumeChangedTempFile.delete();
           Log.d(TAG, "Destroying files completed!");
       }


       /**
        * Checks if all files are set, so we can process them
        * @return - all files ready
        */
       private boolean checkIfAllFilesPresent() {
           if(micPcmFile == null || backgroundMp3File == null || outputFile == null) {
               Log.e(TAG, "All files are not set! Set all files!");
               throw new RuntimeException("Output file is not present!");
           }
           Log.d(TAG, "All files are present!");
           return true;
       }

       public void setOutputFile(File outputFile) {
           this.outputFile = outputFile;
       }

       public void setListener(AudioProcessorListener listener) {
           this.listener = listener;
       }

       public void setMicPcmFile(File micPcmFile) {
           this.micPcmFile = micPcmFile;
       }

       public void setBackgroundMp3File(File backgroundMp3File) {
           this.backgroundMp3File = backgroundMp3File;
       }

       public void setVideoRecordingLength(int seconds) {
           this.videoRecordingLength = seconds;
       }

       /**
        * Quits current processing ffmpeg task
        */
       public void killCurrentTask() {
           if (currentTask != null) {
               currentTask.killRunningProcess();
           }
       }

       public interface AudioProcessorListener {
           void onStart();
           void onSuccess(File output);
           void onError(String message);
           void onFinish();
       }
    }
  • FFmpeg Processes keep running even after finishAndRemoveTask()

    9 octobre 2018, par kataroty

    I have a program that gets Audio files and converts them using Bravobit FFmpeg Bravobit FFmpeg github.

    It works as intended until someone minimizes screen during the convertion process. I am trying to fix that but so far I have not been successful.

    This part is in the Main Activity that creates and starts my AudioProcessor :

    AudioProcessor ac = new AudioProcessor(getApplicationContext(), PostNewActivity.this);
                   ac.setBackgroundMp3File(backgroundAudio);
                   ac.setMicPcmFile(micOutputPCM);
                   ac.setOutputFile(tempOutFile);
                   ac.setListener(new AudioProcessor.AudioProcessorListener() {
                       public void onStart() {
                           Log.d("Audioprocessor", "Audioprocessor is successful");
                       }

                       public void onSuccess(File output) {
                           Log.d("Audioprocessor", "Audioprocessor is successful");
                           goToPublishView();
                       }

                       public void onError(String message) {
                           System.out.println("Audioprocessor: " + message);

                       }

                       public void onFinish() {
                           Log.d("Audioprocessor", "Audioprocessor is finshed");
                      }


                   });

                   try {
                       if (tempOutFile.exists()) {
                           tempOutFile.delete();
                       }
                       ac.process();
                   } catch (Exception ex) {
                       System.out.println("Processing failed!");
                       ex.printStackTrace();
                   }

    And here is the AudioProcessor itself :

    public class AudioProcessor {

       private Context context;
       private FFmpeg ffmpeg;
       private AudioProcessorListener listener;

       private File micPcmFile;
       private File backgroundMp3File;

       private File pcmtowavTempFile;
       private File mp3towavTempFile;
       private File combinedwavTempFile;

       private File outputFile;
       private File volumeChangedTempFile;

       TextView extensionDownload, percentProgress;


       public AudioProcessor(Context context, Activity activity) {
           ffmpeg = null;
           ffmpeg = FFmpeg.getInstance(context);
           percentProgress = activity.findViewById(R.id.percentProgress);
           percentProgress.setSingleLine(false);
           this.context = context;
           prepare();
       }

       /**
        * Program main method. Starts running program
        * @throws Exception
        */
       public void process() throws Exception {
           if (!ffmpeg.isSupported()) {
               Log.e("AudioProcessor", "FFMPEG not supported! Cannot convert audio!");
               throw new Exception("FFMPeg has to be supported");
           }
           if (!checkIfAllFilesPresent()) {
               Log.e("AudioProcessor", "All files are not set yet. Please set file first");
               throw new Exception("Files are not set!");
           }

           Log.e("AudioProcessor", "Start processing audio");
           listener.onStart();



           Handler handler = new Handler();
           handler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   convertPCMToWav();
               }
           }, 200);
       }

       /**
        * Prepares program
        */
       private void prepare() {
           prepareTempFiles();
       }

       /**
        * Converts PCM to wav file. Automatically create new file.
        */
       private void convertPCMToWav() {
           Log.e("AudioProcessor", "Convert PCM TO Wav");
           //ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav
           String[] cmd = { "-f" , "s16le", "-ar", "44.1k", "-i", micPcmFile.toString(), "-y", pcmtowavTempFile.toString()};
           ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setVisibility(View.VISIBLE);
                   percentProgress.setText("Converting your recording\n"+"1/5");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   convertMP3ToWav();
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   onError(message);
                   convertPCMToWav();
               }
           });
       }

       /**
        * Converts mp3 file to wav file.
        * Automatically creates Wav file
        */
       private void convertMP3ToWav() {
           Log.e("AudioProcessor", "Convert MP3 TO Wav");

           //ffmpeg -i file.mp3 file.wav
           String[] cmd = { "-i" , backgroundMp3File.toString(), "-y", mp3towavTempFile.toString() };
           ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Converting background audio\n"+"2/5");
                   Log.e("AudioProcessor", "Starging convertgf MP3 TO Wav");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   changeMicAudio();
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   Log.e("AudioProcessor", "Failed to convert MP3 TO Wav");
                   //onError(message);
                   throw new RuntimeException("Failed to convert MP3 TO Wav");
                   //convertMP3ToWav();
               }
           });
       }

       /**
        * Combines 2 wav files into one wav file. Overlays audio
        */
       private void combineWavs() {
           Log.e("AudioProcessor", "Combine wavs");
           //ffmpeg -i C:\Users\VR1\Desktop\_mp3.wav -i C:\Users\VR1\Desktop\_pcm.wav -filter_complex amix=inputs=2:duration=first:dropout_transition=3 C:\Users\VR1\Desktop\out.wav

           String[] cmd = { "-i" , pcmtowavTempFile.toString(), "-i", volumeChangedTempFile.toString(), "-filter_complex", "amix=inputs=2:duration=first:dropout_transition=3", "-y",combinedwavTempFile.toString()};
           ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Combining the two audio files\n"+"4/5");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   encodeWavToAAC();

               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   onError(message);
               }
           });
       }

       private void changeMicAudio(){
           Log.e("AudioProcessor", "Change audio volume");
           //ffmpeg -i input.wav -filter:a "volume=1.5" output.wav

           String[] cmdy = { "-i", mp3towavTempFile.toString(),  "-af", "volume=0.9", "-y",volumeChangedTempFile.toString()};
           ffmpeg.execute(cmdy, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Normalizing volume\n"+"3/5");
               }

               @Override
               public void onSuccess(String message) {
                   combineWavs();
                   super.onSuccess(message);
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   Log.e("AudioProcessor", message);
               }
           });
       }


       /**
        * Do something on error. Releases program data (deletes files)
        * @param message
        */
       private void onError(String message) {
           release();
           if (listener != null) {
               //listener.onError(message);
           }
       }
       /**
        * Encode to AAC
        */
       private void encodeWavToAAC() {
           Log.e("AudioProcessor", "Encode to AAC");
           //ffmpeg -i file.wav -c:a aac -b:a 128k -f adts output.m4a
           String[] cmd = { "-i" , combinedwavTempFile.toString(), "-c:a", "aac", "-b:a", "128k", "-f", "adts", "-y",outputFile.toString()};
           ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   super.onStart();
                   percentProgress.setText("Normalizing volume\n"+"3/5");
               }

               @Override
               public void onSuccess(String message) {
                   super.onSuccess(message);
                   if (listener != null) {
                       listener.onSuccess(outputFile);
                   }
                   release();
               }
               @Override
               public void onFailure(String message) {
                   super.onFailure(message);
                   onError(message);
                   encodeWavToAAC();
               }
           });
       }

       /**
        * Uninitializes class
        */
       private void release() {
           if (listener != null) {
               listener.onFinish();
           }
           destroyTempFiles();
       }

       /**
        * Prepares temp required files by deleteing them if they exsist.
        * Files cannot exists before ffmpeg actions. FFMpeg automatically creates those files.
        */
       private void prepareTempFiles() {
           pcmtowavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_pcm.wav");
           mp3towavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_mp3.wav");
           combinedwavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_combined.wav");
           volumeChangedTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_volumeChanged.wav");

           destroyTempFiles();
       }

       /**
        * Destroys temp required files
        */
       private void destroyTempFiles() {

           pcmtowavTempFile.delete();
           mp3towavTempFile.delete();
           combinedwavTempFile.delete();
           volumeChangedTempFile.delete();
       }

       /**
        * Checks if all files are set, so we can process them
        * @return - all files ready
        */
       private boolean checkIfAllFilesPresent() {
           if(micPcmFile == null || backgroundMp3File == null || outputFile == null) {
               Log.e("AudioProcessor", "All files are not set! Set all files!");
               return false;
           }
           return true;
       }

       public void setOutputFile(File outputFile) {
           this.outputFile = outputFile;
       }

       public void setListener(AudioProcessorListener listener) {
           this.listener = listener;
       }

       public void setMicPcmFile(File micPcmFile) {


           this.micPcmFile = micPcmFile;
       }

       public void setBackgroundMp3File(File backgroundMp3File) {
           this.backgroundMp3File = backgroundMp3File;
       }


       public interface AudioProcessorListener {
           void onStart();
           void onSuccess(File output);
           void onError(String message);
           void onFinish();
       }
    }

    How I am usually testing it and getting the crashes is letting the AudioProcessor get to the 2nd method, which is convertMP3ToWav() and then close the application. When I start it back up again and start processing the files the application crashes.

    I have tried many ways and I thought about throwing the application back to start when it is minimized with this code in the Main Activity

    @Override
    protected void onUserLeaveHint()
    {
       if (Build.VERSION.SDK_INT >= 21) {
           finishAndRemoveTask();
       } else {
           finish();
       }
    }

    I thought that it would stop everything but it still kept crashing. After doing some debugging I found that even when I minimize the app and do the finishAndRemoveTask() the AudioProcessor is still working and it still does all of the ffmpeg commands and even calls the onSuccess()/onFinish() methods.

    How can I completely stop everything or at least stop and clear the AudioProcessor when the application is minimized ?

  • Play video using mse (media source extension) in google chrome

    23 août 2019, par liyuqihxc

    I’m working on a project that convert rtsp stream (ffmpeg) and play it on the web page (signalr + mse).

    So far it works pretty much as I expected on the latest version of edge and firefox, but not chrome.

    here’s the code

    public class WebmMediaStreamContext
    {
       private Process _ffProcess;
       private readonly string _cmd;
       private byte[] _initSegment;
       private Task _readMediaStreamTask;
       private CancellationTokenSource _cancellationTokenSource;

       private const string _CmdTemplate = "-i {0} -c:v libvpx -tile-columns 4 -frame-parallel 1 -keyint_min 90 -g 90 -f webm -dash 1 pipe:";

       public static readonly byte[] ClusterStart = { 0x1F, 0x43, 0xB6, 0x75, 0x01, 0x00, 0x00, 0x00 };

       public event EventHandler<clusterreadyeventargs> ClusterReadyEvent;

       public WebmMediaStreamContext(string rtspFeed)
       {
           _cmd = string.Format(_CmdTemplate, rtspFeed);
       }

       public async Task StartConverting()
       {
           if (_ffProcess != null)
               throw new InvalidOperationException();

           _ffProcess = new Process();
           _ffProcess.StartInfo = new ProcessStartInfo
           {
               FileName = "ffmpeg/ffmpeg.exe",
               Arguments = _cmd,
               UseShellExecute = false,
               CreateNoWindow = true,
               RedirectStandardOutput = true
           };
           _ffProcess.Start();

           _initSegment = await ParseInitSegmentAndStartReadMediaStream();
       }

       public byte[] GetInitSegment()
       {
           return _initSegment;
       }

       // Find the first cluster, and everything before it is the InitSegment
       private async Task ParseInitSegmentAndStartReadMediaStream()
       {
           Memory<byte> buffer = new byte[10 * 1024];
           int length = 0;
           while (length != buffer.Length)
           {
               length += await _ffProcess.StandardOutput.BaseStream.ReadAsync(buffer.Slice(length));
               int cluster = buffer.Span.IndexOf(ClusterStart);
               if (cluster >= 0)
               {
                   _cancellationTokenSource = new CancellationTokenSource();
                   _readMediaStreamTask = new Task(() => ReadMediaStreamProc(buffer.Slice(cluster, length - cluster).ToArray(), _cancellationTokenSource.Token), _cancellationTokenSource.Token, TaskCreationOptions.LongRunning);
                   _readMediaStreamTask.Start();
                   return buffer.Slice(0, cluster).ToArray();
               }
           }

           throw new InvalidOperationException();
       }

       private void ReadMoreBytes(Span<byte> buffer)
       {
           int size = buffer.Length;
           while (size > 0)
           {
               int len = _ffProcess.StandardOutput.BaseStream.Read(buffer.Slice(buffer.Length - size));
               size -= len;
           }
       }

       // Parse every single cluster and fire ClusterReadyEvent
       private void ReadMediaStreamProc(byte[] bytesRead, CancellationToken cancel)
       {
           Span<byte> buffer = new byte[5 * 1024 * 1024];
           bytesRead.CopyTo(buffer);
           int bufferEmptyIndex = bytesRead.Length;

           do
           {
               if (bufferEmptyIndex &lt; ClusterStart.Length + 4)
               {
                   ReadMoreBytes(buffer.Slice(bufferEmptyIndex, 1024));
                   bufferEmptyIndex += 1024;
               }

               int clusterDataSize = BitConverter.ToInt32(
                   buffer.Slice(ClusterStart.Length, 4)
                   .ToArray()
                   .Reverse()
                   .ToArray()
               );
               int clusterSize = ClusterStart.Length + 4 + clusterDataSize;
               if (clusterSize > buffer.Length)
               {
                   byte[] newBuffer = new byte[clusterSize];
                   buffer.Slice(0, bufferEmptyIndex).CopyTo(newBuffer);
                   buffer = newBuffer;
               }

               if (bufferEmptyIndex &lt; clusterSize)
               {
                   ReadMoreBytes(buffer.Slice(bufferEmptyIndex, clusterSize - bufferEmptyIndex));
                   bufferEmptyIndex = clusterSize;
               }

               ClusterReadyEvent?.Invoke(this, new ClusterReadyEventArgs(buffer.Slice(0, bufferEmptyIndex).ToArray()));

               bufferEmptyIndex = 0;
           } while (!cancel.IsCancellationRequested);
       }
    }
    </byte></byte></byte></clusterreadyeventargs>

    I use ffmpeg to convert the rtsp stream to vp8 WEBM byte stream and parse it to "Init Segment" (ebml head、info、tracks...) and "Media Segment" (cluster), then send it to browser via signalR

    $(function () {

       var mediaSource = new MediaSource();
       var mimeCodec = 'video/webm; codecs="vp8"';

       var video = document.getElementById('video');

       mediaSource.addEventListener('sourceopen', callback, false);
       function callback(e) {
           var sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
           var queue = [];

           sourceBuffer.addEventListener('updateend', function () {
               if (queue.length === 0) {
                   return;
               }

               var base64 = queue[0];
               if (base64.length === 0) {
                   mediaSource.endOfStream();
                   queue.shift();
                   return;
               } else {
                   var buffer = new Uint8Array(atob(base64).split("").map(function (c) {
                       return c.charCodeAt(0);
                   }));
                   sourceBuffer.appendBuffer(buffer);
                   queue.shift();
               }
           }, false);

           var connection = new signalR.HubConnectionBuilder()
               .withUrl("/signalr-video")
               .configureLogging(signalR.LogLevel.Information)
               .build();
           connection.start().then(function () {
               connection.stream("InitVideoReceive")
                   .subscribe({
                       next: function(item) {
                           if (queue.length === 0 &amp;&amp; !!!sourceBuffer.updating) {
                               var buffer = new Uint8Array(atob(item).split("").map(function (c) {
                                   return c.charCodeAt(0);
                               }));
                               sourceBuffer.appendBuffer(buffer);
                               console.log(blockindex++ + " : " + buffer.byteLength);
                           } else {
                               queue.push(item);
                           }
                       },
                       complete: function () {
                           queue.push('');
                       },
                       error: function (err) {
                           console.error(err);
                       }
                   });
           });
       }
       video.src = window.URL.createObjectURL(mediaSource);
    })

    chrome just play the video for 3 5 seconds and then stop for buffering, even though there are plenty of cluster transfered and inserted into SourceBuffer.

    here’s the information in chrome ://media-internals/

    Player Properties :

    render_id: 217
    player_id: 1
    origin_url: http://localhost:52531/
    frame_url: http://localhost:52531/
    frame_title: Home Page
    url: blob:http://localhost:52531/dcb25d89-9830-40a5-ba88-33c13b5c03eb
    info: Selected FFmpegVideoDecoder for video decoding, config: codec: vp8 format: 1 profile: vp8 coded size: [1280,720] visible rect: [0,0,1280,720] natural size: [1280,720] has extra data? false encryption scheme: Unencrypted rotation: 0°
    pipeline_state: kSuspended
    found_video_stream: true
    video_codec_name: vp8
    video_dds: false
    video_decoder: FFmpegVideoDecoder
    duration: unknown
    height: 720
    width: 1280
    video_buffering_state: BUFFERING_HAVE_NOTHING
    for_suspended_start: false
    pipeline_buffering_state: BUFFERING_HAVE_NOTHING
    event: PAUSE

    Log

    Timestamp       Property            Value
    00:00:00 00     origin_url          http://localhost:52531/
    00:00:00 00     frame_url           http://localhost:52531/
    00:00:00 00     frame_title         Home Page
    00:00:00 00     url                 blob:http://localhost:52531/dcb25d89-9830-40a5-ba88-33c13b5c03eb
    00:00:00 00     info                ChunkDemuxer: buffering by DTS
    00:00:00 35     pipeline_state      kStarting
    00:00:15 213    found_video_stream  true
    00:00:15 213    video_codec_name    vp8
    00:00:15 216    video_dds           false
    00:00:15 216    video_decoder       FFmpegVideoDecoder
    00:00:15 216    info                Selected FFmpegVideoDecoder for video decoding, config: codec: vp8 format: 1 profile: vp8 coded size: [1280,720] visible rect: [0,0,1280,720] natural size: [1280,720] has extra data? false encryption scheme: Unencrypted rotation: 0°
    00:00:15 216    pipeline_state      kPlaying
    00:00:15 213    duration            unknown
    00:00:16 661    height              720
    00:00:16 661    width               1280
    00:00:16 665    video_buffering_state       BUFFERING_HAVE_ENOUGH
    00:00:16 665    for_suspended_start         false
    00:00:16 665    pipeline_buffering_state    BUFFERING_HAVE_ENOUGH
    00:00:16 667    pipeline_state      kSuspending
    00:00:16 670    pipeline_state      kSuspended
    00:00:52 759    info                Effective playback rate changed from 0 to 1
    00:00:52 759    event               PLAY
    00:00:52 759    pipeline_state      kResuming
    00:00:52 760    video_dds           false
    00:00:52 760    video_decoder       FFmpegVideoDecoder
    00:00:52 760    info                Selected FFmpegVideoDecoder for video decoding, config: codec: vp8 format: 1 profile: vp8 coded size: [1280,720] visible rect: [0,0,1280,720] natural size: [1280,720] has extra data? false encryption scheme: Unencrypted rotation: 0°
    00:00:52 760    pipeline_state      kPlaying
    00:00:52 793    height              720
    00:00:52 793    width               1280
    00:00:52 798    video_buffering_state       BUFFERING_HAVE_ENOUGH
    00:00:52 798    for_suspended_start         false
    00:00:52 798    pipeline_buffering_state    BUFFERING_HAVE_ENOUGH
    00:00:56 278    video_buffering_state       BUFFERING_HAVE_NOTHING
    00:00:56 295    for_suspended_start         false
    00:00:56 295    pipeline_buffering_state    BUFFERING_HAVE_NOTHING
    00:01:20 717    event               PAUSE
    00:01:33 538    event               PLAY
    00:01:35 94     event               PAUSE
    00:01:55 561    pipeline_state      kSuspending
    00:01:55 563    pipeline_state      kSuspended

    Can someone tell me what’s wrong with my code, or dose chrome require some magic configuration to work ?

    Thanks 

    Please excuse my english :)