本文整理汇总了Java中com.coremedia.iso.boxes.Container.writeContainer方法的典型用法代码示例。如果您正苦于以下问题:Java Container.writeContainer方法的具体用法?Java Container.writeContainer怎么用?Java Container.writeContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.coremedia.iso.boxes.Container
的用法示例。
在下文中一共展示了Container.writeContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertM4a
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
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();
}
}
示例2: mergeMp4
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
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();
}
}
示例3: mergeAudioFile
import com.coremedia.iso.boxes.Container; //导入方法依赖的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()));
}
示例4: makeMP4
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
/**
* Creates an MP4 file out of encoded h.264 bytes.
*
* @throws IOException
*/
public static void makeMP4() throws IOException {
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("dump.h264"));
//AACTrackImpl aacTrack = new AACTrackImpl(new FileInputStream("/home/sannies2/Downloads/lv.aac").getChannel());
Movie m = new Movie();
m.addTrack(h264Track);
//m.addTrack(aacTrack);
Container out = new DefaultMp4Builder().build(m);
FileOutputStream fos = new FileOutputStream(new File("h264_output.mp4"));
FileChannel fc = fos.getChannel();
out.writeContainer(fc);
fos.close();
}
示例5: muxerFileDebug
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
public static void muxerFileDebug(){
try
{
File input = new File(SDCardUtils.getExternalSdCardPath() + "/a.h264");
File output = new File(SDCardUtils.getExternalSdCardPath() + "/b.mp4");
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(input), "eng", UriParser.videoQuality.framerate, 1);
Movie m = new Movie();
m.addTrack(h264Track);
m.setMatrix(Matrix.ROTATE_90);
Container out = new DefaultMp4Builder().build(m);
MovieHeaderBox mvhd = Path.getPath(out, "moov/mvhd");
mvhd.setMatrix(Matrix.ROTATE_90);
TrackBox trackBox = Path.getPath(out, "moov/trak");
TrackHeaderBox tkhd = trackBox.getTrackHeaderBox();
tkhd.setMatrix(Matrix.ROTATE_90);
FileChannel fc = new FileOutputStream(output.getAbsolutePath()).getChannel();
out.writeContainer(fc);
fc.close();
}
catch (IOException e) {
Log.e("test", "some exception", e);
}
}
示例6: convertM4a
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
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();
}
}
示例7: mergeMp4
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
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();
}
}
示例8: crop
import com.coremedia.iso.boxes.Container; //导入方法依赖的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;
}
示例9: append
import com.coremedia.iso.boxes.Container; //导入方法依赖的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();
}
示例10: startTrim
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
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();
}
}
示例11: muxMp4WithVideoAndAudio
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
private void muxMp4WithVideoAndAudio() {
String audio = audioFile.getAbsolutePath();
String video = videoFile.getAbsolutePath();
try {
Movie countVideo = MovieCreator.build(video);
Movie countAudio = MovieCreator.build(audio);
Track audioTrack = countAudio.getTracks().get(0);
countVideo.addTrack(audioTrack);
{
Container out = new DefaultMp4Builder().build(countVideo);
FileOutputStream fos = new FileOutputStream(new File(
FileUtil.getCacheDirectory(VideoRecordActivity.this, true),
"output.mp4"));
out.writeContainer(fos.getChannel());
fos.close();
}
//{
// FragmentedMp4Builder fragmentedMp4Builder = new FragmentedMp4Builder();
// fragmentedMp4Builder.setIntersectionFinder(new SyncSampleIntersectFinderImpl(countVideo, null, -1));
// Container out = fragmentedMp4Builder.build(countVideo);
// FileOutputStream fos = new FileOutputStream(new File("output-frag.mp4"));
// out.writeContainer(fos.getChannel());
// fos.close();
//}
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: subTitle
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
private boolean subTitle() {
try {
// オリジナル動画を読み込み
String filePath = Environment.getExternalStorageDirectory() + "/sample1.mp4";
Movie countVideo = MovieCreator.build(filePath);
// SubTitleを追加
TextTrackImpl subTitleEng = new TextTrackImpl();
subTitleEng.getTrackMetaData().setLanguage("eng");
subTitleEng.getSubs().add(new TextTrackImpl.Line(0, 1000, "Five"));
subTitleEng.getSubs().add(new TextTrackImpl.Line(1000, 2000, "Four"));
subTitleEng.getSubs().add(new TextTrackImpl.Line(2000, 3000, "Three"));
subTitleEng.getSubs().add(new TextTrackImpl.Line(3000, 4000, "Two"));
subTitleEng.getSubs().add(new TextTrackImpl.Line(4000, 5000, "one"));
countVideo.addTrack(subTitleEng);
// 出力
Container container = new DefaultMp4Builder().build(countVideo);
String outputFilePath = Environment.getExternalStorageDirectory() + "/output_subtitle.mp4";
FileOutputStream fos = new FileOutputStream(outputFilePath);
FileChannel channel = fos.getChannel();
container.writeContainer(channel);
fos.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
示例13: handleSegment
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
/**
* 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;
}
示例14: main
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, ParsingException {
URL anchor = SmoothStreamingTrackTest.class.getProtectionDomain().getCodeSource().getLocation();
Movie m = new Movie();
m.addTrack(new SmoothStreamingTrack(new File(anchor.getFile(), "testdata/Manifest").toURI(), "video", "70090"));
DefaultMp4Builder builder = new DefaultMp4Builder();
Container out = builder.build(m);
RandomAccessFile raf = new RandomAccessFile("output.mp4", "rw");
FileChannel fc = raf.getChannel();
out.writeContainer(fc);
raf.close();
}
示例15: main
import com.coremedia.iso.boxes.Container; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("data.h264"));
//AACTrackImpl aacTrack = new AACTrackImpl(new FileInputStream("/home/sannies2/Downloads/lv.aac").getChannel());
Movie m = new Movie();
m.addTrack(h264Track);
//m.addTrack(aacTrack);
//{
Container out = new DefaultMp4Builder().build(m);
FileOutputStream fos = new FileOutputStream(new File("CPR_h264_output.mp4"));
FileChannel fc = fos.getChannel();
out.writeContainer(fc);
fos.close();
// }
}