video - Android Studio:逐帧从 res/raw/ 目录中读取 .mp4
问题描述
对于我的应用程序,我需要将位于我的 res/raw/ 目录中的视频文件的单个图像加载到图像列表/数组中。从这个图像列表/数组中,我需要选择一些不合适的内容,这些内容将存储到一个新的视频文件中,该文件也位于 res/raw/目录中。
问题是我无法找到我的视频的路径。如果我尝试使用:
文件 f = new Flie("app/res/raw/test.mp4");
我得到错误:找不到文件。
我尝试使用 Uri 像:
字符串视频路径="android.resource://" + getPackageName()+ R.raw.test; 文件 f = new Flie(videopath.toString());
但这也不起作用。
这是我需要的伪代码:
List<Picture> video = new ArrayList<Picture>();
File file = new file("path_to_file/test.mp4");
FrameGrab grab = FrameGrab.createFrameGrab(NIOUtils.readableChannel(file));
Picture picture;
while (null != (picture = grab.getNativeFrame())) {
video.add(picture);
}
List<picture> video_new = new ArrayList<picture>();
int[] idx = {1,2,4,6,8 ...}
for(int i= 0; i<idx.length; i++){
picture= video.get(idx[i]);
video_new.add(picture);
}
//stores the new video into the same path but with a different name
storefile("path_to_file/test_new.mp4", video_new);
解决方案
看起来您的文件路径中可能缺少斜杠。
尝试改变:
String videopath ="android.resource://" + getPackageName()+ R.raw.test
至:
String videopath ="android.resource://" + getPackageName()+ "/" + R.raw.test
使用它来访问和播放视频如下所示:
VideoView view = (VideoView)findViewById(R.id.videoView);
String videopath ="android.resource://" + getPackageName()+ "/" + R.raw.test
view.setVideoURI(Uri.parse(videopath));
view.start();
笔记
为了从媒体文件(例如视频)中提取帧,Android 提供了 MediaMetadataRetriever 类
推荐阅读
- objective-c - 为什么我不能在我的方法中修改对象
- android - 如何查看活动中的推体?
- serialization - 序列化和流式传输之间有什么关系?
- ocaml - 让 rec 获取值,让 rec 获取 ocaml 中的函数
- nginx - Nginx 请求在尝试连接时给出 ERR_INCOMPLETE_CHUNKED_ENCODING
- applozic - 在 Applozic conversatin 选项卡中显示搜索选项
- java - 如何打开 Maven Spring Web 应用程序?
- jenkins - 如何在 Jenkins 中运行 Nightwatch 测试?
- python - Python:如何删除重复项?
- java - 防止在恢复出厂设置中卸载应用程序