@@ -19,80 +19,77 @@ public static void setMotion(IMotion motion) {
19
19
public static void main (String [] args ) {
20
20
String xiaomi = "/Users/hss/Documents/MVIMG_20240918_093751.jpg" ;
21
21
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 );
24
24
}
25
25
26
26
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 ("" )) {
30
29
return false ;
31
30
}
32
31
String videoPath = motion .mp4CacheFile (fileOrUriPath );
33
32
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 );
36
35
return true ;
37
36
}
38
37
try {
39
38
long wholeFileLength = motion .length (fileOrUriPath );
40
39
String xmp = motion .readXmp (fileOrUriPath );
41
- if (xmp ==null || xmp .equals ("" )){
40
+ if (xmp == null || xmp .equals ("" )) {
42
41
return false ;
43
42
}
44
- String androidXmp = "xmlns:GCamera=\" http://ns.google.com/photos/1.0/camera/ \" " ;
43
+ String androidXmp = "xmlns:GCamera=" ;
45
44
String iosXmp = "iosxxx" ;
46
- if (!xmp .contains (androidXmp ) && !xmp .contains (iosXmp )){
45
+ if (!xmp .contains (androidXmp ) && !xmp .contains (iosXmp )) {
47
46
return false ;
48
47
}
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+)\" " ;
53
50
// 创建 Pattern 对象
54
- Pattern pattern = Pattern .compile (regex );
51
+ Pattern pattern0 = Pattern .compile (regex0 );
55
52
// 创建 matcher 对象
56
- Matcher matcher = pattern .matcher (xmp );
53
+ Matcher matcher0 = pattern0 .matcher (xmp );
57
54
// 查找并提取数字
58
- if (matcher .find ()) {
59
- String number = matcher .group (1 );
55
+ if (matcher0 .find ()) {
56
+ String number = matcher0 .group (1 );
60
57
int length = Integer .parseInt (number );
61
58
System .out .println ("提取到的数字是: " + number );
62
- if (wholeFileLength <= length ){
59
+ if (wholeFileLength <= length ) {
63
60
System .out .println ("文件大小小于视频文件大小, xmp显示是动态图,但实际不是 " + fileOrUriPath );
64
61
return false ;
65
62
}
66
63
//提取视频文件
67
- if (extractVideo ){
68
- extractMp4FromMotionPhoto (fileOrUriPath ,motion .mp4CacheFile (fileOrUriPath ),wholeFileLength -length ,length );
64
+ if (extractVideo ) {
65
+ extractMp4FromMotionPhoto (fileOrUriPath , motion .mp4CacheFile (fileOrUriPath ), wholeFileLength - length , length );
69
66
}
70
67
71
68
return true ;
72
69
} 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("没有找到匹配的模式。");
93
91
}
94
- return true ;
95
- }
92
+
96
93
}
97
94
}
98
95
@@ -104,26 +101,25 @@ public static boolean isMotionImage(String fileOrUriPath,boolean extractVideo){
104
101
}
105
102
106
103
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 ) {
110
107
return null ;
111
108
}
112
- return motion .mp4CacheFile (filePath );
109
+ return motion .mp4CacheFile (filePath );
113
110
}
114
111
115
112
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 {
118
114
RandomAccessFile raf = null ;
119
115
RandomAccessFile rafOutput = null ;
120
116
try {
121
117
// 打开输出 MP4 文件
122
118
File out = new File (outputFile );
123
- if (!out .exists ()){
119
+ if (!out .exists ()) {
124
120
out .createNewFile ();
125
- }else {
126
- if (length == out .length ()){
121
+ } else {
122
+ if (length == out .length ()) {
127
123
return ;
128
124
}
129
125
out .delete ();
0 commit comments