Skip to content

Commit d254f05

Browse files
committed
motion photo 兼容问题处理
1 parent 64ffa82 commit d254f05

File tree

2 files changed

+53
-56
lines changed

2 files changed

+53
-56
lines changed

build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ buildscript {
55
apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/gradle7_5/z_config/pack.gradle?q=3'
66
//apply from : 'https://raw.githubusercontent.com/hss01248/BaseAppAnalytics/master/remote.gradle'
77
apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/gradle7_5/deps/depsLastestChecker.gradle'
8-
//apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/gradle7_5/deps/uploadAllByMavenPublish.gradle?a=6'
8+
apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/gradle7_5/deps/uploadAllByMavenPublish.gradle?a=6'
99
apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/gradle7_5/z_config/git_branch_info.gradle'
1010

1111
//apply from: 'pack.gradle'
1212

1313
ext {
1414
// 快照版需要在版本号后面加-SNAPSHOT
1515
//groupId='com.xxx.yyy.mylib'
16-
// groupId='com.github.hss01248.ImageLoader'
17-
versionCode = '3.8.5.01'
16+
groupId='com.github.hss01248.ImageLoader'
17+
versionCode = '3.9.3.00'
1818
isPublisToLocal=false
1919
ignoreModules = "spiders"
2020

@@ -23,7 +23,8 @@ buildscript {
2323
publicUrl='https://nexus.hss01248.tech/#browse/browse:maven-public:'
2424

2525
utilcodeVersion='1.6.8'
26-
26+
uname='admin'
27+
pw='614511qa#'
2728

2829
}
2930

motion-photos/src/main/java/com/hss01248/motion_photos/MotionPhotoUtil.java

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,80 +19,77 @@ public static void setMotion(IMotion motion) {
1919
public static void main(String[] args) {
2020
String xiaomi = "/Users/hss/Documents/MVIMG_20240918_093751.jpg";
2121
String google = "/Users/hss/Documents/PXL_20240918_013738178.MP.jpg";
22-
boolean isMotionImage = isMotionImage(xiaomi,true);
23-
boolean is2 = isMotionImage(google,true);
22+
boolean isMotionImage = isMotionImage(xiaomi, true);
23+
boolean is2 = isMotionImage(google, true);
2424
}
2525

2626

27-
28-
public static boolean isMotionImage(String fileOrUriPath,boolean extractVideo){
29-
if(fileOrUriPath ==null || fileOrUriPath.equals("")){
27+
public static boolean isMotionImage(String fileOrUriPath, boolean extractVideo) {
28+
if (fileOrUriPath == null || fileOrUriPath.equals("")) {
3029
return false;
3130
}
3231
String videoPath = motion.mp4CacheFile(fileOrUriPath);
3332
File video = new File(videoPath);
34-
if(video.exists() && video.length()> 500){
35-
System.out.println("video 文件已经存在: "+videoPath);
33+
if (video.exists() && video.length() > 500) {
34+
System.out.println("video 文件已经存在: " + videoPath);
3635
return true;
3736
}
3837
try {
3938
long wholeFileLength = motion.length(fileOrUriPath);
4039
String xmp = motion.readXmp(fileOrUriPath);
41-
if(xmp ==null || xmp.equals("")){
40+
if (xmp == null || xmp.equals("")) {
4241
return false;
4342
}
44-
String androidXmp = "xmlns:GCamera=\"http://ns.google.com/photos/1.0/camera/\"";
43+
String androidXmp = "xmlns:GCamera=";
4544
String iosXmp = "iosxxx";
46-
if(!xmp.contains(androidXmp) && !xmp.contains(iosXmp)){
45+
if (!xmp.contains(androidXmp) && !xmp.contains(iosXmp)) {
4746
return false;
4847
}
49-
if(xmp.contains(androidXmp)){
50-
String xiaomiXmp = "xmlns:MiCamera=\"http://ns.xiaomi.com/photos/1.0/camera/\"";
51-
if(xmp.contains(xiaomiXmp)){
52-
String regex = "GCamera:MicroVideoOffset=\"(\\d+)\"";
48+
if (xmp.contains(androidXmp)) {
49+
String regex0 = "GCamera:MicroVideoOffset=\"(\\d+)\"";
5350
// 创建 Pattern 对象
54-
Pattern pattern = Pattern.compile(regex);
51+
Pattern pattern0 = Pattern.compile(regex0);
5552
// 创建 matcher 对象
56-
Matcher matcher = pattern.matcher(xmp);
53+
Matcher matcher0 = pattern0.matcher(xmp);
5754
// 查找并提取数字
58-
if (matcher.find()) {
59-
String number = matcher.group(1);
55+
if (matcher0.find()) {
56+
String number = matcher0.group(1);
6057
int length = Integer.parseInt(number);
6158
System.out.println("提取到的数字是: " + number);
62-
if(wholeFileLength <= length){
59+
if (wholeFileLength <= length) {
6360
System.out.println("文件大小小于视频文件大小, xmp显示是动态图,但实际不是 " + fileOrUriPath);
6461
return false;
6562
}
6663
//提取视频文件
67-
if(extractVideo){
68-
extractMp4FromMotionPhoto(fileOrUriPath,motion.mp4CacheFile(fileOrUriPath),wholeFileLength -length,length);
64+
if (extractVideo) {
65+
extractMp4FromMotionPhoto(fileOrUriPath, motion.mp4CacheFile(fileOrUriPath), wholeFileLength - length, length);
6966
}
7067

7168
return true;
7269
} else {
73-
System.out.println("没有找到匹配的模式。");
74-
}
75-
}else {
76-
String regex = "<Container:Item\\s+Item:Mime=\"video/mp4\"\\s+Item:Semantic=\"MotionPhoto\"\\s+Item:Length=\"(\\d+)\"\\s+Item:Padding=\"(\\d+)\"\\s*/>";
77-
78-
Pattern pattern = Pattern.compile(regex);
79-
Matcher matcher = pattern.matcher(xmp);
80-
if (matcher.find()) {
81-
String length = matcher.group(1);
82-
String padding = matcher.group(2);
83-
System.out.println("length: "+length+", padding:"+padding);
84-
int len = Integer.parseInt(length);
85-
int pad = Integer.parseInt(padding);
86-
if(wholeFileLength <= len + pad){
87-
System.out.println("文件大小小于视频文件大小2, xmp显示是动态图,但实际不是 " + fileOrUriPath);
88-
return false;
89-
}
90-
//提取视频文件
91-
if(extractVideo){
92-
extractMp4FromMotionPhoto(fileOrUriPath,motion.mp4CacheFile(fileOrUriPath),wholeFileLength -(len+pad),len);
70+
String regex = "<Container:Item\\s+Item:Mime=\"video/mp4\"\\s+Item:Semantic=\"MotionPhoto\"\\s+Item:Length=\"(\\d+)\"\\s+Item:Padding=\"(\\d+)\"\\s*/>";
71+
Pattern pattern = Pattern.compile(regex);
72+
Matcher matcher = pattern.matcher(xmp);
73+
if (matcher.find()) {
74+
String length = matcher.group(1);
75+
String padding = matcher.group(2);
76+
System.out.println("length: " + length + ", padding:" + padding);
77+
int len = Integer.parseInt(length);
78+
int pad = Integer.parseInt(padding);
79+
if (wholeFileLength <= len + pad) {
80+
System.out.println("文件大小小于视频文件大小2, xmp显示是动态图,但实际不是 " + fileOrUriPath);
81+
return false;
82+
}
83+
//提取视频文件
84+
if (extractVideo) {
85+
extractMp4FromMotionPhoto(fileOrUriPath, motion.mp4CacheFile(fileOrUriPath), wholeFileLength - (len + pad), len);
86+
}
87+
return true;
88+
89+
} else {
90+
// System.out.println("没有找到匹配的模式。");
9391
}
94-
return true;
95-
}
92+
9693
}
9794
}
9895

@@ -104,26 +101,25 @@ public static boolean isMotionImage(String fileOrUriPath,boolean extractVideo){
104101
}
105102

106103

107-
public static String getMotionVideoPath(String filePath){
108-
boolean isMotionImage = isMotionImage(filePath,true);
109-
if(!isMotionImage){
104+
public static String getMotionVideoPath(String filePath) {
105+
boolean isMotionImage = isMotionImage(filePath, true);
106+
if (!isMotionImage) {
110107
return null;
111108
}
112-
return motion.mp4CacheFile(filePath);
109+
return motion.mp4CacheFile(filePath);
113110
}
114111

115112

116-
117-
static void extractMp4FromMotionPhoto(String inputFile, String outputFile, long startBytes,long length) throws IOException {
113+
static void extractMp4FromMotionPhoto(String inputFile, String outputFile, long startBytes, long length) throws IOException {
118114
RandomAccessFile raf = null;
119115
RandomAccessFile rafOutput = null;
120116
try {
121117
// 打开输出 MP4 文件
122118
File out = new File(outputFile);
123-
if(!out.exists()){
119+
if (!out.exists()) {
124120
out.createNewFile();
125-
}else {
126-
if(length == out.length()){
121+
} else {
122+
if (length == out.length()) {
127123
return;
128124
}
129125
out.delete();

0 commit comments

Comments
 (0)