我有一个班级,用ExoPLayer观看rtmp流:
player = ExoPlayerFactory.newSimpleInstance(context)
val rtmpDataSourceFactory = RtmpDataSourceFactory()
val videoSource = ProgressiveMediaSource.Factory(rtmpDataSourceFactory)
.createMediaSource(Uri.parse(streamURL))
player.prepare(videoSource)
player.setVideoTextureView(playerView)
player.playWhenReady = trueplayerView是TextureView,而不是SurfaceView,因为我还需要从流中截取屏幕截图。
据我所知,ExoPlayer没有流记录的方法,只有下载,所以问题是-我如何记录rtmp流?我搜索了很多库和堆栈问题,但仍然找不到干净、正常的解决方案。
目前,我正在尝试通过基本的MediaRecorder记录数据流,并帮助安卓开发人员编写文档,但我仍然不明白,MediaRecorder是如何获得流数据的,或者至少是表面的。
val path = "${Environment.getExternalStorageDirectory()}${File.separator}${Environment.DIRECTORY_DCIM}${File.separator}${"FILE_NAME"}"
recorder = MediaRecorder().apply {
setVideoSource(MediaRecorder.VideoSource.SURFACE)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setOutputFile(path)
start()
}发布于 2019-10-31 16:21:40
我通过使用FFMpeg库找到了解决方案。如果有人需要它--添加这个Gradle依赖项:implementation 'com.writingminds:FFmpegAndroid:0.3.2
下面是代码:
// Build path for recorded video
val title = "/" + System.currentTimeMillis().toString() + ".mp4"
val targetFile = File(getExternalStoragePublicDirectory(DIRECTORY_DCIM).toString() + title)
// FFMpeg command for stream recording
val command = arrayOf("-i", streamURL, "-acodec", "copy", "-vcodec", "copy", targetFile.toString())
try {
// Load the binary
ffmpeg.loadBinary(object : LoadBinaryResponseHandler() {})
} catch (e: FFmpegNotSupportedException) {
e.printStackTrace()
}
try {
// Execute command
ffmpeg.execute(command, object : ExecuteBinaryResponseHandler() {})
} catch (e: FFmpegCommandAlreadyRunningException) {
e.printStackTrace()
}https://stackoverflow.com/questions/58488926
复制相似问题