android4.2 图库修剪视频后,详细信息中不显示时长
2013-08-15 10:22
183 查看
原因:
视频修改完成后没有获取剪辑视频时间,并插入数据库
TrimVideo.java
public void run() {
try {
double trimVideoDuration =
TrimVideoUtils.startTrim(mSrcFile, mDstFile, mTrimStartTime, mTrimEndTime);
// Update the database for adding a new video file.
insertContent(mDstFile, (int)(trimVideoDuration * 1000));
} catch (IOException e) {
.................
private Uri insertContent(File file,
int duration) {
long nowInMs = System.currentTimeMillis();
long nowInSec = nowInMs / 1000;
final ContentValues values = new ContentValues(13);
values.put(Video.Media.TITLE, mSaveFileName);
values.put(Video.Media.DISPLAY_NAME, file.getName());
values.put(Video.Media.MIME_TYPE, "video/mp4");
values.put(Video.Media.DATE_TAKEN, nowInMs);
values.put(Video.Media.DATE_MODIFIED, nowInSec);
values.put(Video.Media.DATE_ADDED, nowInSec);
values.put(Video.Media.DATA, file.getAbsolutePath());
values.put(Video.Media.SIZE, file.length());
values.put(Video.Media.DURATION, duration);
// Copy the data taken and location info from src.
TrimVideoUtils.java
public static double startTrim(File src, File dst, int startMs, int endMs) throws IOException
....
double TrimVideoStartTime = Double.MAX_VALUE;
double TrimVideoEndTime = 0;
for (Track track : tracks) {
long currentSample = 0;
double currentTime = 0;
long startSample = -1;
long endSample = -1;
double trackStartTime = 0;
double trackEndTime = 0;
.......
if (currentTime <= startTime) {
// current sample is still before the new starttime
startSample = currentSample;
trackStartTime = currentTime;
}
if (currentTime <= endTime) {
// current sample is after the new start time and still before the new endtime
endSample = currentSample;
trackEndTime = currentTime;
} else {
// current sample is after the end of the cropped video
break;
}
currentTime += (double) entry.getDelta() / (double) track.getTrackMetaData().getTimescale();
currentSample++;
}
}
TrimVideoStartTime = Math.min(TrimVideoStartTime, trackStartTime);
TrimVideoEndTime = Math.max(TrimVideoEndTime,trackEndTime);
movie.addTrack(new CroppedTrack(track, startSample, endSample));
}
IsoFile out = new DefaultMp4Builder().build(movie);
if (!dst.exists()) {
dst.createNewFile();
}
FileOutputStream fos = new FileOutputStream(dst);
FileChannel fc = fos.getChannel();
out.getBox(fc); // This one build up the memory.
fc.close();
fos.close();
randomAccessFile.close();
return TrimVideoEndTime - TrimVideoStartTime;
}
视频修改完成后没有获取剪辑视频时间,并插入数据库
TrimVideo.java
public void run() {
try {
double trimVideoDuration =
TrimVideoUtils.startTrim(mSrcFile, mDstFile, mTrimStartTime, mTrimEndTime);
// Update the database for adding a new video file.
insertContent(mDstFile, (int)(trimVideoDuration * 1000));
} catch (IOException e) {
.................
private Uri insertContent(File file,
int duration) {
long nowInMs = System.currentTimeMillis();
long nowInSec = nowInMs / 1000;
final ContentValues values = new ContentValues(13);
values.put(Video.Media.TITLE, mSaveFileName);
values.put(Video.Media.DISPLAY_NAME, file.getName());
values.put(Video.Media.MIME_TYPE, "video/mp4");
values.put(Video.Media.DATE_TAKEN, nowInMs);
values.put(Video.Media.DATE_MODIFIED, nowInSec);
values.put(Video.Media.DATE_ADDED, nowInSec);
values.put(Video.Media.DATA, file.getAbsolutePath());
values.put(Video.Media.SIZE, file.length());
values.put(Video.Media.DURATION, duration);
// Copy the data taken and location info from src.
TrimVideoUtils.java
public static double startTrim(File src, File dst, int startMs, int endMs) throws IOException
....
double TrimVideoStartTime = Double.MAX_VALUE;
double TrimVideoEndTime = 0;
for (Track track : tracks) {
long currentSample = 0;
double currentTime = 0;
long startSample = -1;
long endSample = -1;
double trackStartTime = 0;
double trackEndTime = 0;
.......
if (currentTime <= startTime) {
// current sample is still before the new starttime
startSample = currentSample;
trackStartTime = currentTime;
}
if (currentTime <= endTime) {
// current sample is after the new start time and still before the new endtime
endSample = currentSample;
trackEndTime = currentTime;
} else {
// current sample is after the end of the cropped video
break;
}
currentTime += (double) entry.getDelta() / (double) track.getTrackMetaData().getTimescale();
currentSample++;
}
}
TrimVideoStartTime = Math.min(TrimVideoStartTime, trackStartTime);
TrimVideoEndTime = Math.max(TrimVideoEndTime,trackEndTime);
movie.addTrack(new CroppedTrack(track, startSample, endSample));
}
IsoFile out = new DefaultMp4Builder().build(movie);
if (!dst.exists()) {
dst.createNewFile();
}
FileOutputStream fos = new FileOutputStream(dst);
FileChannel fc = fos.getChannel();
out.getBox(fc); // This one build up the memory.
fc.close();
fos.close();
randomAccessFile.close();
return TrimVideoEndTime - TrimVideoStartTime;
}
相关文章推荐
- 显示详细信息
- 鼠标滑过按钮显示详细信息
- 我的电脑 默认 显示 详细信息
- 让IIS 7显示ASP的详细错误信息-无论什么样的代码错误,只显示“500 - 内部服务器错误解决
- android 图库中对非mp4格式的视频去掉"修剪"功能选项
- js实现鼠标移上去显示详细信息
- HappyIdiom之六(2)点击动物类列表中的每一项以对话框的形式显示该成语的详细信息
- 商品浏览系统之商品详细信息显示页面实现
- sql函数分割字符串,游标显示详细信息
- 点击后跳转显示详细信息
- Win10 Mobile预览版10549:显示连接移动热点设备的详细信息
- 让IIS 7显示ASP的详细错误信息
- 点击cell显示cell的详细信息,再次…
- Win7系统下更改MP3音乐信息让其显示更多详细信息
- 在Windows 2008 IIS7中如何显示ASP的详细错误信息
- 让windows文件全部默认以“详细信息”显示
- jquery与DataGrid实现点击列名显示/隐藏详细信息
- 获取dataview显示的文件的详细信息
- [实用修改]帖子评价详细信息显示 For Dvbbs7.1SP1 0716
- JS操作DOM点击图片弹出层显示大图片和详细信息