com.googlecode.mp4parser.authoring.Movie Java Examples
The following examples show how to use
com.googlecode.mp4parser.authoring.Movie.
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: DownloadFinishedReceiver.java From YouTube-In-Background with MIT License | 6 votes |
private void mergeMp4(String inFilePathAudio, String inFilePathVideo) { String path = inFilePathVideo.substring(0, inFilePathVideo.lastIndexOf("/")); try { Movie video = MovieCreator.build(inFilePathVideo); Movie audio = MovieCreator.build(inFilePathAudio); video.addTrack(audio.getTracks().get(0)); Container out = new DefaultMp4Builder().build(video); long currentMillis = System.currentTimeMillis(); FileOutputStream fos = new FileOutputStream(new File(path + TEMP_FILE_NAME + currentMillis + ".mp4")); out.writeContainer(fos.getChannel()); fos.close(); File inAudioFile = new File(inFilePathAudio); inAudioFile.delete(); File inVideoFile = new File(inFilePathVideo); if (inVideoFile.delete()) { File tempOutFile = new File(path + TEMP_FILE_NAME + currentMillis + ".mp4"); tempOutFile.renameTo(inVideoFile); } } catch (IOException e) { e.printStackTrace(); } }
Example #2
Source File: Mp4ParserWrapper.java From continuous-audiorecorder with BSD 2-Clause "Simplified" License | 6 votes |
public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final Movie movieA = MovieCreator.build(new FileDataSourceImpl(secondFile)); final Movie movieB = MovieCreator.build(new FileDataSourceImpl(firstFile)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieA.getTracks(); final List<Track> movieTwoTracks = movieB.getTracks(); for (int i = 0; i < movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final Container container = new DefaultMp4Builder().build(finalMovie); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); final WritableByteChannel bb = Channels.newChannel(fos); container.writeContainer(bb); fos.close(); }
Example #3
Source File: FileUtil.java From FimiX8-RE with MIT License | 5 votes |
public static void mergeMultipleVideoFile(String outPath, String videoPath1, String videoPath2) { try { List<String> fileList = new ArrayList(); List<Movie> movieList = new ArrayList(); fileList.add(videoPath1); fileList.add(videoPath2); for (String filePath : fileList) { movieList.add(MovieCreator.build(filePath)); } List<Track> videoTracks = new LinkedList(); List<Track> audioTracks = new LinkedList(); for (Movie movie : movieList) { for (Track track : movie.getTracks()) { if (track.getHandler().equals("soun")) { audioTracks.add(track); } if (track.getHandler().equals("vide")) { videoTracks.add(track); } } } Movie result = new Movie(); if (audioTracks.size() > 0) { result.addTrack(new AppendTrack((Track[]) audioTracks.toArray(new Track[audioTracks.size()]))); } if (videoTracks.size() > 0) { result.addTrack(new AppendTrack((Track[]) videoTracks.toArray(new Track[videoTracks.size()]))); } writeMergeNewFile(outPath, result); deleteFile(new File(videoPath1)); deleteFile(new File(videoPath2)); fileList.clear(); movieList.clear(); } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: StatusSavingService.java From WhatsAppStatusSaver with Apache License 2.0 | 5 votes |
private void mergeAllVideos(ArrayList<String> statuses) { String destinationFilename = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/WhatsAppSaver" + File.separatorChar + System.currentTimeMillis() + ".mp4"; try { // Movie movie = MovieCreator.build(statuses.get(0)); LinkedList<Track> allTracks = new LinkedList<>(); // movie.setTracks(new LinkedList<Track>()); for (int i = 0; i < statuses.size(); i++) { Log.i(TAG, "Video status ::" + statuses.get(i)); String vidPath = statuses.get(i); Movie countVideo = MovieCreator.build(vidPath); // allTracks.addAll(countVideo.getTracks()); Container mp4file = new DefaultMp4Builder().build(countVideo); FileChannel fc = new FileOutputStream(new File(destinationFilename)).getChannel(); mp4file.writeContainer(fc); fc.close(); } // Movie movie = new Movie(); // movie.setTracks(allTracks); // // Container mp4file = new DefaultMp4Builder().build(movie); // FileChannel fc = new FileOutputStream(new File(destinationFilename)).getChannel(); // mp4file.writeContainer(fc); // fc.close(); // IsoFile out = (IsoFile) new DefaultMp4Builder().build(movie); // FileOutputStream fos = new FileOutputStream(new File(destinationFilename)); // out.getBox(fos.getChannel()); // fos.close(); } catch (IOException e) { e.printStackTrace(); } // IsoFile out = new DefaultMp4Builder().build(video); // FileOutputStream fos = new FileOutputStream(new File(String.format("output.mp4"))); // out.getBox(fos.getChannel()); // fos.close(); }
Example #5
Source File: DownloadFinishedReceiver.java From YouTube-In-Background with MIT License | 5 votes |
private void convertM4a(String inFilePath, String title, String artist) { String path = inFilePath.substring(0, inFilePath.lastIndexOf("/")); try { Movie inAudio = MovieCreator.build(inFilePath); Container out = new DefaultMp4Builder().build(inAudio); if (title != null && artist != null) { writeMetaData(out, artist, title); } long currentMillis = System.currentTimeMillis(); FileOutputStream fos = new FileOutputStream(new File(path + TEMP_FILE_NAME + currentMillis + ".m4a")); out.writeContainer(fos.getChannel()); fos.close(); File inFile = new File(inFilePath); if (inFile.delete()) { File tempOutFile = new File(path + TEMP_FILE_NAME + currentMillis + ".m4a"); tempOutFile.renameTo(inFile); } } catch (IOException e) { e.printStackTrace(); } }
Example #6
Source File: FileUtil.java From FimiX8-RE with MIT License | 4 votes |
private static void writeMergeNewFile(java.lang.String r5, com.googlecode.mp4parser.authoring.Movie r6) { /* r2 = 0; r4 = new com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder; Catch:{ Exception -> 0x0023 } r4.<init>(); Catch:{ Exception -> 0x0023 } r0 = r4.build(r6); Catch:{ Exception -> 0x0023 } r3 = new java.io.FileOutputStream; Catch:{ Exception -> 0x0023 } r3.<init>(r5); Catch:{ Exception -> 0x0023 } r4 = r3.getChannel(); Catch:{ Exception -> 0x0041, all -> 0x003e } r0.writeContainer(r4); Catch:{ Exception -> 0x0041, all -> 0x003e } if (r3 == 0) goto L_0x0044; L_0x0018: r3.close(); Catch:{ Exception -> 0x001d } r2 = r3; L_0x001c: return; L_0x001d: r1 = move-exception; r1.printStackTrace(); r2 = r3; goto L_0x001c; L_0x0023: r1 = move-exception; L_0x0024: r1.printStackTrace(); Catch:{ all -> 0x0032 } if (r2 == 0) goto L_0x001c; L_0x0029: r2.close(); Catch:{ Exception -> 0x002d } goto L_0x001c; L_0x002d: r1 = move-exception; r1.printStackTrace(); goto L_0x001c; L_0x0032: r4 = move-exception; L_0x0033: if (r2 == 0) goto L_0x0038; L_0x0035: r2.close(); Catch:{ Exception -> 0x0039 } L_0x0038: throw r4; L_0x0039: r1 = move-exception; r1.printStackTrace(); goto L_0x0038; L_0x003e: r4 = move-exception; r2 = r3; goto L_0x0033; L_0x0041: r1 = move-exception; r2 = r3; goto L_0x0024; L_0x0044: r2 = r3; goto L_0x001c; */ throw new UnsupportedOperationException("Method not decompiled: com.fimi.kernel.utils.FileUtil.writeMergeNewFile(java.lang.String, com.googlecode.mp4parser.authoring.Movie):void"); }
Example #7
Source File: VideoPartMergeTask.java From VideoRecorder with Apache License 2.0 | 4 votes |
@Override protected File doInBackground(MultiPartRecorder.Part... lists) { if (LogUtil.LOG_ENABLE) { for (MultiPartRecorder.Part list : lists) { LogUtil.logd("VideoPartMergeTask", list.toString()); } } try { if (lists.length == 0) throw new IllegalArgumentException("传入的视频块列表是空的"); if (mMergeListener != null) mMergeListener.onStart(); //检查视频块是否全都录制结束了 int timeout = 0; while (!checkVideoPartRecordFinish(lists) && timeout < mTimeout) { timeout += 50; SystemClock.sleep(50); } if (timeout > mTimeout) { throw new IllegalStateException("有视频块还没有结束录制 , 不能开始合并视频"); } if (lists.length == 1) {//只有一个视频片段 if (lists[0].file.renameTo(mOutPutFile)) { if (mMergeListener != null) mMergeListener.onSuccess(mOutPutFile); } else { if (mMergeListener != null) mMergeListener.onError(new IllegalStateException("只有一个视频片段,在将这个视频片段移动到目标位置时出现了错误")); } } else { String[] videoUris = new String[lists.length]; for (int i = 0; i < lists.length; i++) { videoUris[i] = lists[i].file.getAbsolutePath(); } List<Movie> inMovies = new ArrayList<>(videoUris.length); for (String videoUri : videoUris) { inMovies.add(MovieCreator.build(videoUri)); } 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); } } } Movie result = new Movie(); if (!audioTracks.isEmpty()) { result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()]))); } if (!videoTracks.isEmpty()) { result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()]))); } Container out = new DefaultMp4Builder().build(result); startCheckProgressThread(out); FileChannel fc = new RandomAccessFile(mOutPutFile, "rw").getChannel(); out.writeContainer(fc); fc.close(); if (mMergeListener != null) mMergeListener.onSuccess(mOutPutFile); } } catch (Exception e) { mDeletePartFile = false;//发生错误时不删除视频 if (mMergeListener != null) mMergeListener.onError(e); } deleteTempPartFile(lists); return mOutPutFile; }
Example #8
Source File: StatusSavingService.java From WhatsAppStatusSaver with Apache License 2.0 | 4 votes |
/** * * @param statuses ArrayList of paths of statuses selected * newMergeMethod */ private void newMergeMethod(ArrayList<String> statuses){ int count = statuses.size(); String paths[] = new String[count]; Movie[] inMovies = new Movie[count]; try { for (int i = 0; i < count; i++) { inMovies[i] = MovieCreator.build(statuses.get(i)); } Log.i(TAG, "Video statuses to be merged ::" + inMovies.length); LinkedList<Track> videoTracks = new LinkedList<>(); LinkedList<Track> audioTracks = new LinkedList<>(); 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); } } } Movie result = new Movie(); // for(Track track: audioTracks){ // result.addTrack(new AppendTrack(track)); // } // for(Track track: videoTracks){ // result.addTrack(new AppendTrack(track)); // } 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()]))); } Log.i(TAG, "number of first track is :" + inMovies[0].getTracks().size()); Log.i(TAG, "number of second track is :" + inMovies[1].getTracks().size()); Log.i(TAG, "number of tracks is :" + result.getTracks().size()); BasicContainer out = (BasicContainer) new DefaultMp4Builder() .build(result); @SuppressWarnings("resource") String destinationFilename = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/WhatsAppSaver" + File.separatorChar + System.currentTimeMillis() + ".mp4"; FileChannel fc = new RandomAccessFile(destinationFilename,"rw").getChannel(); out.writeContainer(fc); fc.close(); } catch (IOException ie){ ie.printStackTrace(); } }
Example #9
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 #10
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; } }
Example #11
Source File: DashMediaExtractor.java From MediaPlayer-Extended with Apache License 2.0 | 4 votes |
/** * Handles a segment by merging it with the init segment into a temporary file. */ private void handleSegment(byte[] mediaSegment, CachedSegment cachedSegment) throws IOException { File segmentFile = getTempFile(mContext, "seg" + cachedSegment.representation.id + "-" + cachedSegment.segment.range + ""); long segmentPTSOffsetUs = 0; if(mMp4Mode) { /* The MP4 iso format needs special treatment because the Android MediaExtractor/MediaCodec * does not support the fragmented MP4 container format. Each segment therefore needs * to be joined with the init fragment and converted to a "conventional" unfragmented MP4 * container file. */ IsoFile baseIsoFile = new IsoFile(new MemoryDataSourceImpl(mInitSegments.get(cachedSegment.representation).asByteBuffer())); IsoFile fragment = new IsoFile(new MemoryDataSourceImpl(mediaSegment)); /* The PTS in a converted MP4 always start at 0, so we read the offset from the segment * index box and work with it at the necessary places to adjust the local PTS to global * PTS concerning the whole stream. */ List<SegmentIndexBox> segmentIndexBoxes = fragment.getBoxes(SegmentIndexBox.class); if(segmentIndexBoxes.size() > 0) { SegmentIndexBox sidx = segmentIndexBoxes.get(0); segmentPTSOffsetUs = (long) ((double) sidx.getEarliestPresentationTime() / sidx.getTimeScale() * 1000000); } /* If there is no segment index box to read the PTS from, we calculate the PTS offset * from the info given in the MPD. */ else { segmentPTSOffsetUs = cachedSegment.number * cachedSegment.representation.segmentDurationUs; } Movie mp4Segment = new Movie(); for(TrackBox trackBox : baseIsoFile.getMovieBox().getBoxes(TrackBox.class)) { mp4Segment.addTrack(new Mp4TrackImpl(null, trackBox, fragment)); } Container mp4SegmentContainer = new DefaultMp4Builder().build(mp4Segment); // always create new instance to avoid memory leaks! FileOutputStream fos = new FileOutputStream(segmentFile, false); mp4SegmentContainer.writeContainer(fos.getChannel()); fos.close(); } else { // merge init and media segments into file BufferedSink segmentFileSink = Okio.buffer(Okio.sink(segmentFile)); segmentFileSink.write(mInitSegments.get(cachedSegment.representation)); segmentFileSink.write(mediaSegment); segmentFileSink.close(); } cachedSegment.file = segmentFile; cachedSegment.ptsOffsetUs = segmentPTSOffsetUs; }