如何根据视频的播放时间偏移量获取视频的字节偏移量?例如,给定视频的播放时间偏移量为 15 秒,我想知道那一秒的字节偏移量。
这样做的原因是因为我希望能够从视频中“修剪”剪辑。我希望能够保存从 00:00:20 到 00:00:35 的视频 fragment 。
目前,这是我所拥有的 - 但这会将整个视频从 url 保存到设备:
URL url = new URL(http_url_path);
URLConnection ucon = url.openConnection();
// Define InputStreams to read from the URLConnection.
// uses 5KB download buffer
InputStream is = ucon.getInputStream();
BufferedInputStream in = new BufferedInputStream(is, BUFFER_SIZE);
FileOutputStream out = new FileOutputStream(file);
byte[] buff = new byte[BUFFER_SIZE];
int len = 0;
while ((len = in.read(buff)) != -1) {
out.write(buff, 0, len);
}
最佳答案
如果你不介意在最近的关键帧(a/k/a 同步帧)剪切,你可以使用 MediaExtractor提取帧,使用 getSampleTime()
检查 PTS,和 MediaMuxer将它放回原处,去掉不需要的框架。
视频必须以关键帧开始,因此您不能在任意点剪切流,除非您愿意重新编码该 GOP。
MP4 视频文件不仅仅是一系列帧(我假设您不是在处理原始 H.264 数据)。 MediaMuxer 将负责重写 header 和其他支持数据。
关于android - Android中如何根据Video的播放时间偏移获取字节偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905664/