本文整理汇总了Java中com.googlecode.mp4parser.authoring.tracks.AppendTrack类的典型用法代码示例。如果您正苦于以下问题:Java AppendTrack类的具体用法?Java AppendTrack怎么用?Java AppendTrack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AppendTrack类属于com.googlecode.mp4parser.authoring.tracks包,在下文中一共展示了AppendTrack类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeAudioFile
import com.googlecode.mp4parser.authoring.tracks.AppendTrack; //导入依赖的package包/类
private void mergeAudioFile(File recordedFile, File recordedFileTemp) throws IOException {
if (!recordedFile.exists()) {
recordedFileTemp.renameTo(new File(LocalMediaStorage.getOutputMediaFileUri(null, LocalMediaStorage.MEDIA_TYPE_AUDIO_RECORD).getPath()));
return;
}
final Movie movieA = MovieCreator.build(new FileDataSourceImpl(recordedFileTemp));
final Movie movieB = MovieCreator.build(new FileDataSourceImpl(recordedFile));
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(0), movieOneTracks.get(0)));
//}
final Container container = new DefaultMp4Builder().build(finalMovie);
File recordedFileMerged = new File(LocalMediaStorage.getOutputMediaFileUri(null, LocalMediaStorage.MEDIA_TYPE_AUDIO_RECORD_MERGED).getPath());
if (recordedFileMerged.exists()) {
recordedFileMerged.delete();
}
final FileOutputStream fos = new FileOutputStream(new File(String.format(recordedFileMerged.getPath())));
final WritableByteChannel bb = Channels.newChannel(fos);
container.writeContainer(bb);
fos.close();
recordedFile.delete();
recordedFileTemp.delete();
recordedFileMerged.renameTo(new File(LocalMediaStorage.getOutputMediaFileUri(null, LocalMediaStorage.MEDIA_TYPE_AUDIO_RECORD).getPath()));
}
示例2: crop
import com.googlecode.mp4parser.authoring.tracks.AppendTrack; //导入依赖的package包/类
private boolean crop() {
try {
// オリジナル動画を読み込み
String filePath = Environment.getExternalStorageDirectory() + "/sample1.mp4";
Movie originalMovie = MovieCreator.build(filePath);
// 分割
Track track = originalMovie.getTracks().get(0);
Movie movie = new Movie();
movie.addTrack(new AppendTrack(new CroppedTrack(track, 200, 400)));
// 出力
Container out = new DefaultMp4Builder().build(movie);
String outputFilePath = Environment.getExternalStorageDirectory() + "/output_crop.mp4";
FileOutputStream fos = new FileOutputStream(new File(outputFilePath));
out.writeContainer(fos.getChannel());
fos.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
示例3: append
import com.googlecode.mp4parser.authoring.tracks.AppendTrack; //导入依赖的package包/类
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();
}
示例4: combineVideoFiles
import com.googlecode.mp4parser.authoring.tracks.AppendTrack; //导入依赖的package包/类
public String combineVideoFiles(String directoryPath, String uplaodDirectoryName) throws IOException {
File file = new File(directoryPath);
String[] fileNames = file.list();
Arrays.sort(fileNames);
int filesCount = fileNames.length;
Movie[] movies = new Movie[filesCount];
for (int index = 0; index < filesCount; index++) {
String currentFilePath = String.format("%s%s%s", directoryPath, File.separator, fileNames[index]);
movies[index] = MovieCreator.build(currentFilePath);
}
List<Track> videoTracks = new LinkedList<>();
for (Movie movie : movies) {
for (Track track : movie.getTracks()) {
if (track.getHandler().equals("vide")) {
videoTracks.add(track);
}
}
}
Movie combinedMovie = new Movie();
Track[] tracksToCombine = videoTracks.toArray(new Track[videoTracks.size()]);
AppendTrack appendTrack = new AppendTrack(tracksToCombine);
combinedMovie.addTrack(appendTrack);
Mp4Builder videoBuilder = new DefaultMp4Builder();
Container combinedMovieContainer = videoBuilder.build(combinedMovie);
File mergedRecordsDirectory = new File(MERGED_RECORDS_DIR_NAME);
if (!mergedRecordsDirectory.exists()) {
mergedRecordsDirectory.mkdirs();
}
String timestamp = new SimpleDateFormat(TIMESTAMP_FORMAT).format(new Date());
uplaodDirectoryName = !uplaodDirectoryName.isEmpty() ? uplaodDirectoryName + "_" : uplaodDirectoryName;
String screenRecordFileName = String.format("%s%s%s%s%s%s_%s_screen_record.mp4",
SCREEN_RECORDS_LOCAL_DIR,
File.separator,
MERGED_RECORDS_DIR_NAME,
File.separator,
uplaodDirectoryName,
timestamp,
wrappedDevice.getSerialNumber());
RandomAccessFile randomAccessFile = new RandomAccessFile(screenRecordFileName, "rw");
FileChannel fileChannel = randomAccessFile.getChannel();
combinedMovieContainer.writeContainer(fileChannel);
fileChannel.close();
randomAccessFile.close();
return screenRecordFileName;
}
示例5: concatTwoVideos
import com.googlecode.mp4parser.authoring.tracks.AppendTrack; //导入依赖的package包/类
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;
}
}
示例6: append
import com.googlecode.mp4parser.authoring.tracks.AppendTrack; //导入依赖的package包/类
private boolean append() {
try {
// 複数の動画を読み込み
String f1 = Environment.getExternalStorageDirectory() + "/sample1.mp4";
String f2 = Environment.getExternalStorageDirectory() + "/sample2.mp4";
Movie[] inMovies = new Movie[]{
MovieCreator.build(f1),
MovieCreator.build(f2)};
// 1つのファイルに結合
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.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);
String outputFilePath = Environment.getExternalStorageDirectory() + "/output_append.mp4";
FileOutputStream fos = new FileOutputStream(new File(outputFilePath));
out.writeContainer(fos.getChannel());
fos.close();
} catch (Exception e) {
return false;
}
return true;
}