This repository was archived by the owner on May 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathMainActivity.java
More file actions
144 lines (131 loc) · 5.86 KB
/
MainActivity.java
File metadata and controls
144 lines (131 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.code;
import android.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import org.ffmpeg.android.R;
import org.ffmpeg.android.test.MixTest;
import java.io.File;
import java.io.FileOutputStream;
import butterknife.ButterKnife;
import butterknife.InjectView;
/**
* @author Chad
* @title com.code
* @description
* @modifier
* @date
* @since 16/5/31 上午12:04
**/
public class MainActivity extends Activity {
@InjectView(R.id.text_mix)
Button textMix;
String mp4FilePath = "/storage/emulated/0/.mofunshow/movies/90331/20160529171913002801000325.mp4";
String bgMp3FilePath = "/storage/emulated/0/.mofunshow/movies/90331/20160520191953876045000830.aac";
String jsonFilePath = "/storage/emulated/0/.mofunshow/movies/90331/20160520192149267651000519.json";
String bgWavFilePath = "/storage/emulated/0/.mofunshow/movies/90331/2015082214101800000358814.wav";
String mp4OutPath = "/storage/emulated/0/.mofunshow/movies/90331/test_out.mp4";
String mp4AllPath = "/storage/emulated/0/.mofunshow/movies/90331/test_out_all.mp4";
String pngPath = "/storage/emulated/0/.mofunshow/movies/90331/1.png";
String pngTempPath = "/storage/emulated/0/.mofunshow/movies/90331/temp.png";
String tempPath = "/storage/emulated/0/ffmpeg/";
@InjectView(R.id.test_merge)
Button testMerge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
ButterKnife.inject(this);
new File(tempPath).mkdirs();
File[] files = new File("/system/fonts/").listFiles();
for (File file : files) {
String fileName = file.getName().toLowerCase();
if (fileName.contains("miui")) {
if (fileName.toLowerCase().equals("miui-regular")) {
Config.SYSTEM_DEFAULT_FONT_PATH = file.getAbsolutePath();
break;
}
Config.SYSTEM_DEFAULT_FONT_PATH = file.getAbsolutePath();
break;
}
}
textMix.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// List<DialogItem> dialog_list;
// dialog_list = new Gson().fromJson(FileUtil.readJsonFile(jsonFilePath), new TypeToken<ArrayList<DialogItem>>() {}.getType());
// try {
// MixTest.test(tempPath,mp4FilePath,bgMp3FilePath,new Clip(mp4OutPath),getApplicationContext());
// } catch (Exception e) {
// e.printStackTrace();
// }
// try {
// List<String> list = new ArrayList<String>();
// list.add(getImageFileFromVideo(mp4FilePath,pngTempPath));
// MixTest.testJpegToMp4(mp4FilePath,tempPath,list,mp4OutPath,getApplicationContext());
// } catch (Exception e) {
// e.printStackTrace();
// }
try {
MixTest.testMakeLastFrameFilter(getImageFileFromVideo(mp4FilePath, pngTempPath), getTimeLengthFromVideo(mp4FilePath), mp4FilePath, tempPath, mp4OutPath, getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
}
});
testMerge.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
// MixTest.testMergeMp4(mp4FilePath, mp4OutPath, tempPath, mp4AllPath, getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Bitmap getBitmapsFromVideo(String mp4FilePath) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(mp4FilePath);
// 取得视频的长度(单位为毫秒)
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
// 取得视频的长度(单位为秒)
int seconds = Integer.valueOf(time) / 1000;
// 得到每一秒时刻的bitmap比如第一秒,第二秒
bitmap = retriever.getFrameAtTime(seconds * 1000 * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
return bitmap;
}
public long getTimeLengthFromVideo(String mp4FilePath) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(mp4FilePath);
// 取得视频的长度(单位为毫秒)
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
// 取得视频的长度(单位为秒)
int milins = Integer.valueOf(time);
return milins;
}
public String getImageFileFromVideo(String mp4FilePath, String outPath) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(mp4FilePath);
// 取得视频的长度(单位为毫秒)
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
// 取得视频的长度(单位为秒)
int millSeconds = Integer.valueOf(time);
int seconds = millSeconds / 1000;
// 得到每一秒时刻的bitmap比如第一秒,第二秒
bitmap = retriever.getFrameAtTime(millSeconds * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(outPath);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return outPath;
}
}