1
1
package com .cloudwebrtc .webrtc .record ;
2
2
3
+ import android .graphics .Bitmap ;
4
+ import android .graphics .BitmapFactory ;
3
5
import android .graphics .ImageFormat ;
6
+ import android .graphics .Matrix ;
4
7
import android .graphics .Rect ;
5
8
import android .graphics .YuvImage ;
6
9
import android .os .Handler ;
@@ -66,9 +69,12 @@ public void onFrame(VideoFrame videoFrame) {
66
69
videoTrack .removeSink (this );
67
70
});
68
71
try {
69
- if (!file .exists ())
72
+ if (!file .exists ()) {
73
+ //noinspection ResultOfMethodCallIgnored
74
+ file .getParentFile ().mkdirs ();
70
75
//noinspection ResultOfMethodCallIgnored
71
76
file .createNewFile ();
77
+ }
72
78
} catch (IOException io ) {
73
79
callback .error ("IOException" , io .getLocalizedMessage (), io );
74
80
return ;
@@ -79,6 +85,23 @@ public void onFrame(VideoFrame videoFrame) {
79
85
100 ,
80
86
outputStream
81
87
);
88
+ switch (videoFrame .getRotation ()) {
89
+ case 0 :
90
+ break ;
91
+ case 90 :
92
+ case 180 :
93
+ case 270 :
94
+ Bitmap original = BitmapFactory .decodeFile (file .toString ());
95
+ Matrix matrix = new Matrix ();
96
+ matrix .postRotate (videoFrame .getRotation ());
97
+ Bitmap rotated = Bitmap .createBitmap (original , 0 , 0 , original .getWidth (), original .getHeight (), matrix , true );
98
+ FileOutputStream rotatedOutputStream = new FileOutputStream (file );
99
+ rotated .compress (Bitmap .CompressFormat .JPEG , 100 , rotatedOutputStream );
100
+ break ;
101
+ default :
102
+ // Rotation is checked to always be 0, 90, 180 or 270 by VideoFrame
103
+ throw new RuntimeException ("Invalid rotation" );
104
+ }
82
105
callback .success (null );
83
106
} catch (IOException io ) {
84
107
callback .error ("IOException" , io .getLocalizedMessage (), io );
@@ -89,4 +112,4 @@ public void onFrame(VideoFrame videoFrame) {
89
112
}
90
113
}
91
114
92
- }
115
+ }
0 commit comments