我有 org.webrtc.VideoFrame
帧流。
帧一帧一帧地到来。 是否有任何库或工具可以将帧动态转换为流?
我可以成功地将 VideoFrames 转换为字节数组。 (类似于将其用于图像的这个问题) Android org.webrtc.VideoRenderer.I420Frame arrays to PreviewCallback.onPreviewFrame byte[]
我想创建可播放的流视频,但是当我尝试播放使用 FileOutputStream
或任何其他可以传递给 FFMPEG 的流创建的视频时,它是不可播放的,所以它似乎需要muxer 来创建它?
private fun addMetaDataToVideo() {
val file = File(context.getExternalFilesDir(Environment.DIRECTORY_DCIM).toString() + "/"
+"KYR", "${videoNamePrefix}}.mp4")
val out = FileOutputStream(file)
listOfFrames.forEach { out.write(it) }
out.close()
addMetaDataToVideo(file)
}
private fun addMetaDataToVideo(videoFile: File) {
val values = ContentValues(3)
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4")
// values.put(MediaStore.Video.Media.DURATION, getVideoDuration(videoFile))
values.put(MediaStore.Video.Media.DATA, videoFile.absolutePath)
context.contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values)
}
最佳答案
使用 ffmpeg 是最常用的方法。 你能把你的框架放到某种图像数组中吗? BufferedImage 或类似的东西?获得图像后,您可以使用以下行。就像这里解释的那样:https://hamelot.io/visualization/using-ffmpeg-to-convert-a-set-of-images-into-a-video/
尝试将您的帧写入 BufferedImage,
ffmpeg -r 60 -f image2 -s 1920x1080 -i pic%04d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4
关于java - 从字节/帧 Java/Android 创建可播放的视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62343813/