0

How can I stream video from byteArray

fun streamVideoListener(frame: ByteArray){
        // receiving H.264 frames every 100ms.
}

I tried FFmpeg library. merged 100 frames and make few seconds video and add it to ExoPlayer playlist. but performance is not good at all. I also tried NanoHttpd library. I can send a simple .mp4 video file and play it with vlc or MxPlayer, but don't know how to stream a growing video file (without refreshing page)

2 Answers2

1

You'll need to implement a custom DataSource implementing the com.google.android.exoplayer.upstream.DataSource interface or extend the BaseDataSource from exoplayer library. Store the byte array and in the read method provide the stored byte array. You can see usage in the RtmpDataSource class of the exoplayer library

0

You can directly use ByteArrayDataSource : https://github.com/google/ExoPlayer/issues/5571 once you have the byte array available for the video, you can pass it to create a DataSource using ByteArrayDataSource

private MediaSource createMediaSourceFromByteArray(byte[] data) {
ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(data);
DataSource.Factory factory = new DataSource.Factory() {
    @Override
    public DataSource createDataSource() {
        return byteArrayDataSource;
    }
};
MediaSource mediaSource = new ExtractorMediaSource.Factory(factory)
        .setExtractorsFactory(new DefaultExtractorsFactory())
        .createMediaSource(Uri.EMPTY);

return Objects.requireNonNull(mediaSource, "MediaSource cannot be null");

}

iBobb
  • 1,140
  • 1
  • 14
  • 35
deeppandya
  • 43
  • 1
  • 8