com.coremedia.iso.boxes.MovieHeaderBox Java Examples
The following examples show how to use
com.coremedia.iso.boxes.MovieHeaderBox.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessVideoUtils.java From patrol-android with GNU General Public License v3.0 | 4 votes |
public static void startTrim(File src, File dst, double startTime, double endTime) throws IOException { FileDataSourceImpl file = new FileDataSourceImpl(src); Movie movie = MovieCreator.build(file); List<Track> tracks = movie.getTracks(); movie.setTracks(new LinkedList<Track>()); Log.d(TAG, "startTrim: " + startTime + " " + endTime); for (Track track : tracks) { long currentSample = 0; double currentTime = 0; long startSample = -1; long endSample = -1; for (int i = 0; i < track.getSampleDurations().length; i++) { if (currentTime <= startTime) { // current sample is still before the new starttime startSample = currentSample; } if (currentTime <= endTime) { // current sample is after the new start time and still before the new endtime endSample = currentSample; } else { // current sample is after the end of the cropped video break; } currentTime += (double) track.getSampleDurations()[i] / (double) track.getTrackMetaData().getTimescale(); currentSample++; } movie.addTrack(new CroppedTrack(track, startSample, endSample)); } Container out = new DefaultMp4Builder().build(movie); MovieHeaderBox mvhd = Path.getPath(out, "moov/mvhd"); mvhd.setMatrix(Matrix.ROTATE_180); if (!dst.exists()) { dst.createNewFile(); } FileOutputStream fos = new FileOutputStream(dst); WritableByteChannel fc = fos.getChannel(); try { out.writeContainer(fc); }catch (Exception e){ e.printStackTrace(); } finally { fc.close(); fos.close(); file.close(); } }
Example #2
Source File: ProcessVideoUtils.java From patrol-android with GNU General Public License v3.0 | 4 votes |
public static boolean concatTwoVideos(File src1, File src2, File dst) { try { FileDataSourceImpl file1 = new FileDataSourceImpl(src1); FileDataSourceImpl file2 = new FileDataSourceImpl(src2); Movie result = new Movie(); Movie movie1 = MovieCreator.build(file1); Movie movie2 = MovieCreator.build(file2); Movie[] inMovies = new Movie[]{ movie1, movie2 }; List<Track> videoTracks = new LinkedList<Track>(); List<Track> audioTracks = new LinkedList<Track>(); for (Movie m : inMovies) { for (Track t : m.getTracks()) { if (t.getHandler().equals("soun")) { audioTracks.add(t); } if (t.getHandler().equals("vide")) { videoTracks.add(t); } } } if (audioTracks.size() > 0) { result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()]))); } if (videoTracks.size() > 0) { result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()]))); } Container out = new DefaultMp4Builder().build(result); MovieHeaderBox mvhd = Path.getPath(out, "moov/mvhd"); mvhd.setMatrix(Matrix.ROTATE_180); if (!dst.exists()) { dst.createNewFile(); } FileOutputStream fos = new FileOutputStream(dst); WritableByteChannel fc = fos.getChannel(); try { out.writeContainer(fc); } finally { fc.close(); fos.close(); file1.close(); file2.close(); } return true; } catch (IOException e) { e.printStackTrace(); return false; } }