Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to play multiple files with RtspServerFromFile #1487

Open
hjywyj opened this issue May 25, 2024 · 9 comments
Open

How to play multiple files with RtspServerFromFile #1487

hjywyj opened this issue May 25, 2024 · 9 comments

Comments

@hjywyj
Copy link

hjywyj commented May 25, 2024

I have four mp4 files: record1.mp4, record2.mp4, record3.mp4, record4.mp4
Currently I want to implement it, given a fileList=[record1.mp4,record2.mp4]
Use RtspServerFromFile to ignore the first 15 seconds from record1.mp4 and start the output stream. After record1.mp4 has finished playing, continue to record2.mp4.
How should it be implemented and prepareVideo again?

@pedroSG94
Copy link
Owner

pedroSG94 commented May 25, 2024

Hello,

Currently it is not supported. To do that you need stop stream totally and start again with the new video file.
The reason to no support this is because you could use different video/audio file config and in this case you can't handle with that. For example:
If you use 2 files totally different like 1280x720 video with audio 44100 sample rate stereo channel and other file with 640x480 video and audio 32000 mono channel.
You can't continue with the second file because you have the stream and encoders configured for the first file. I'm not totally sure how to handle this feature so it is not developed for now.

Should I develop the way to do it but only supported files with the same configuration?

@pedroSG94
Copy link
Owner

pedroSG94 commented May 25, 2024

For now, you can try join all files in one (you will need find a library for it) and then use the result in the library to stream

@hjywyj
Copy link
Author

hjywyj commented May 25, 2024

I'm sorry, I didn't take into account the problem of different bitrates, but are files with the same bitrate OK?
Your library is great. I used it to record video surveillance for 24 hours and save the file every hour.
The problem we are currently encountering is that multiple video files are pushed to one stream and can only be interrupted and then started again. So I would like to ask if there is any smoother switching method.

@hjywyj
Copy link
Author

hjywyj commented May 25, 2024

For now, you can try join all files in one (you will need find a library for it) and then use the result in the library to stream

This is a good approach, but it consumes storage space.

@pedroSG94
Copy link
Owner

For now, you can try join all files in one (you will need find a library for it) and then use the result in the library to stream

This is a good approach, but it consumes storage space.

Yes, but this is the only way for now. I will mark this issue as enhancement and develop the way to stream multiples files but only if that files are identical in config (video and audio). The files will require:

  • Same video resolution, audio samplerate and audio channels

I'm not sure if throw a crash in prepareVideo or prepareAudio if you are using different files with different config or just return false in the method.
What do you think is a better idea?

@hjywyj
Copy link
Author

hjywyj commented May 30, 2024

For now, you can try join all files in one (you will need find a library for it) and then use the result in the library to stream

This is a good approach, but it consumes storage space.

Yes, but this is the only way for now. I will mark this issue as enhancement and develop the way to stream multiples files but only if that files are identical in config (video and audio). The files will require:

  • Same video resolution, audio samplerate and audio channels

I'm not sure if throw a crash in prepareVideo or prepareAudio if you are using different files with different config or just return false in the method. What do you think is a better idea?

Yes, I think it's a better idea.I can't think of any other better solution. Thanks!

@pedroSG94
Copy link
Owner

pedroSG94 commented Jun 26, 2024

Hello,

This feature was added to RootEncoder in the last commit.
In the next release I will add this feature to RTSP-Server

Usage example:

  • First of all remove loop mode:
genericFromFile.setLoopMode(false)
  • Use onVideoDecoderFinished or onAudioDecoderFinished callbacks (you need choose one) to detect the end of the file and replace the current file with other file:
  override fun onVideoDecoderFinished() {
    genericFromFile.replaceVideoFile(path)
    genericFromFile.replaceAudioFile(path)
    //resync file to avoid audio and video sync issues (recommended because video or audio could take different time to start)
    genericFromFile.reSyncFile()
  }

@hjywyj
Copy link
Author

hjywyj commented Jun 27, 2024

Hello,
Thank you very much
I think I need to study the "reSyncFile" method. I am not sure if it will cause video stream lag due to high time consumption when running on low-end devices. Thank you again

@pedroSG94
Copy link
Owner

reSyncFile is optional but I recommend you use it if you can after change the file.
You can use it only on high-end devices if you want.
Also you can check the time in audio and video and only resync if the difference is high. Something like this:

val vTime = genericFromFile.getVideoTime()
val aTime = genericFromFile.getAudioTime()
if (abs(vTime - aTime) >= 0.5) { //async by 0.5s
genericFromFile.reSyncFile()
}

0.5 is a random value (in seconds), you should check the values and use a value that adjust to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants