5
5
package org .monte .media .quicktime ;
6
6
7
7
import org .monte .media .av .Format ;
8
- import org .monte .media .av .FormatKeys .MediaType ;
9
- import org .monte .media .io .IOStreams ;
10
8
import org .monte .media .io .ImageOutputStreamAdapter ;
11
9
import org .monte .media .math .Rational ;
12
10
29
27
import static org .monte .media .av .FormatKeys .EncodingKey ;
30
28
import static org .monte .media .av .FormatKeys .FrameRateKey ;
31
29
import static org .monte .media .av .FormatKeys .MIME_QUICKTIME ;
30
+ import static org .monte .media .av .FormatKeys .MediaType ;
32
31
import static org .monte .media .av .FormatKeys .MediaTypeKey ;
33
32
import static org .monte .media .av .FormatKeys .MimeTypeKey ;
34
33
import static org .monte .media .av .codec .audio .AudioFormatKeys .ByteOrderKey ;
@@ -350,7 +349,7 @@ public int addAudioTrack(String compressionType, //
350
349
* encoded with lossless encoders such as the PNG format. <p> The default
351
350
* value is 0.97.
352
351
*
353
- * @param newValue
352
+ * @param newValue the new value
354
353
*/
355
354
public void setCompressionQuality (int track , float newValue ) {
356
355
VideoTrack vt = (VideoTrack ) tracks .get (track );
@@ -374,14 +373,14 @@ public float getCompressionQuality(int track) {
374
373
* write all samples as sync samples. n = sync every n-th sample.
375
374
*/
376
375
public void setSyncInterval (int track , int i ) {
377
- (( VideoTrack ) tracks .get (track ) ).syncInterval = i ;
376
+ tracks .get (track ).syncInterval = i ;
378
377
}
379
378
380
379
/**
381
380
* Gets the sync interval from the specified video track.
382
381
*/
383
382
public int getSyncInterval (int track ) {
384
- return (( VideoTrack ) tracks .get (track ) ).syncInterval ;
383
+ return tracks .get (track ).syncInterval ;
385
384
}
386
385
387
386
/**
@@ -653,7 +652,7 @@ public void writeSample(int track, InputStream in, long duration, boolean isSync
653
652
ensureStarted ();
654
653
long offset = getRelativeStreamPosition ();
655
654
OutputStream mdatOut = mdatAtom .getOutputStream ();
656
- IOStreams . copy ( in , mdatOut );
655
+ in . transferTo ( mdatOut );
657
656
long length = getRelativeStreamPosition () - offset ;
658
657
t .addSample (new Sample (duration , offset , length ), 1 , isSync );
659
658
}
@@ -1018,10 +1017,8 @@ private void writeEpilog() throws IOException {
1018
1017
}
1019
1018
1020
1019
// Optional color table atom
1021
- for (int i = 0 , n = tracks .size (); i < n ; i ++) {
1022
- Track t = tracks .get (i );
1023
- if (t instanceof VideoTrack ) {
1024
- VideoTrack vt = (VideoTrack ) t ;
1020
+ for (Track t : tracks ) {
1021
+ if (t instanceof VideoTrack vt ) {
1025
1022
if (vt .videoColorTable != null ) {
1026
1023
vt .writeColorTableAtom (moovAtom );
1027
1024
break ;
@@ -1158,10 +1155,10 @@ protected void writeTrackAtoms(int trackIndex, CompositeAtom moovAtom, Date modi
1158
1155
// See Figure 2-8 for an illustration of a matrix structure:
1159
1156
// http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap2/chapter_3_section_3.html#//apple_ref/doc/uid/TP40000939-CH204-32967
1160
1157
1161
- d .writeFixed16D16 (t .mediaType == MediaType .VIDEO ? (( VideoTrack ) t ) .width : 0 ); // width
1158
+ d .writeFixed16D16 (t .mediaType == MediaType .VIDEO ? t .width : 0 ); // width
1162
1159
// A 32-bit fixed-point number that specifies the width of this track in pixels.
1163
1160
1164
- d .writeFixed16D16 (t .mediaType == MediaType .VIDEO ? (( VideoTrack ) t ) .height : 0 ); // height
1161
+ d .writeFixed16D16 (t .mediaType == MediaType .VIDEO ? t .height : 0 ); // height
1165
1162
// A 32-bit fixed-point number that indicates the height of this track in pixels.
1166
1163
1167
1164
/* Edit Atom ========= */
@@ -1202,10 +1199,10 @@ protected void writeTrackAtoms(int trackIndex, CompositeAtom moovAtom, Date modi
1202
1199
d .writeFixed16D16 (1 ); // mediaRate
1203
1200
} else {
1204
1201
d .writeUInt (elist .length ); // numberOfEntries
1205
- for (int i = 0 ; i < elist . length ; ++ i ) {
1206
- d .writeUInt (elist [ i ] .trackDuration ); // trackDuration
1207
- d .writeUInt (elist [ i ] .mediaTime ); // mediaTime
1208
- d .writeUInt (elist [ i ] .mediaRate ); // mediaRate
1202
+ for (Edit edit : elist ) {
1203
+ d .writeUInt (edit .trackDuration ); // trackDuration
1204
+ d .writeUInt (edit .mediaTime ); // mediaTime
1205
+ d .writeUInt (edit .mediaRate ); // mediaRate
1209
1206
}
1210
1207
}
1211
1208
@@ -1265,7 +1262,7 @@ protected void writeTrackAtoms(int trackIndex, CompositeAtom moovAtom, Date modi
1265
1262
// A 16-bit integer that specifies the media’s playback quality—that is,
1266
1263
// its suitability for playback in a given environment.
1267
1264
1268
- /**
1265
+ /*
1269
1266
* Media Handler Reference Atom -------
1270
1267
*/
1271
1268
leaf = new DataAtom ("hdlr" );
@@ -1336,14 +1333,9 @@ protected void writeMediaInformationAtoms(int trackIndex, CompositeAtom mdiaAtom
1336
1333
1337
1334
/* Video or Audio media information atom -------- */
1338
1335
switch (t .mediaType ) {
1339
- case VIDEO :
1340
- writeVideoMediaInformationHeaderAtom (trackIndex , minfAtom );
1341
- break ;
1342
- case AUDIO :
1343
- writeSoundMediaInformationHeaderAtom (trackIndex , minfAtom );
1344
- break ;
1345
- default :
1346
- throw new UnsupportedOperationException ("Media type " + t .mediaType + " not supported yet." );
1336
+ case VIDEO -> writeVideoMediaInformationHeaderAtom (trackIndex , minfAtom );
1337
+ case AUDIO -> writeSoundMediaInformationHeaderAtom (trackIndex , minfAtom );
1338
+ default -> throw new UnsupportedOperationException ("Media type " + t .mediaType + " not supported yet." );
1347
1339
}
1348
1340
1349
1341
@@ -1920,7 +1912,7 @@ public void toWebOptimizedMovie(File outputFile, boolean compressHeader) throws
1920
1912
}
1921
1913
}
1922
1914
1923
- if (maxIteration < 0 || buf .size () == 0 ) {
1915
+ if (buf .size () == 0 ) {
1924
1916
compressHeader = false ;
1925
1917
System .err .println ("WARNING QuickTimeWriter failed to compress header." );
1926
1918
} else {
@@ -1952,7 +1944,6 @@ public void toWebOptimizedMovie(File outputFile, boolean compressHeader) throws
1952
1944
daos .write (0 );
1953
1945
}
1954
1946
}
1955
-
1956
1947
}
1957
1948
if (!compressHeader ) {
1958
1949
out = new FileImageOutputStream (outputFile );
0 commit comments