sannies / mp4parser Goto Github PK
View Code? Open in Web Editor NEWA Java API to read, write and create MP4 files
License: Apache License 2.0
A Java API to read, write and create MP4 files
License: Apache License 2.0
i was trying to trim (cut) a mp4 video file, and i failed:). is there any examples available for me?
thanks a lot
I saw you pushed the library to Maven but there's no link in the readme.
Implement H265TrackImpl
The parameter segmentDurationInMs clearly states its milliseconds, but in DefaultMp4Builder#createEdts its interpreted as seconds:
(long) edit.getSegmentDuration() * movie.getTimescale()
muxing raw H264 with B-frames doesn't create correct ctts box
For the sample code like below, since lastTime == currentTime on initialization, the first sample will be skipped by all the "if (currentTime > lastTime ...", which would occur when startTime1 = 0. To fix, initialize lastTime to something < 0.
for (Track track : tracks) {
long currentSample = 0;
double currentTime = 0;
double lastTime = 0;
long startSample1 = -1;
long endSample1 = -1;
long startSample2 = -1;
long endSample2 = -1;
for (int i = 0; i < track.getSampleDurations().length; i++) {
long delta = track.getSampleDurations()[i];
if (currentTime > lastTime && currentTime <= startTime1) {
// current sample is still before the new starttime
startSample1 = currentSample;
}
handle single saio offset in traf
handle multiple saio offsets and multiple tracks per fragment
Hi,Sannies
This is the issus.I 'm trying to mux two acc to a mp4,but the generated mp4 only play m2.acc.
Please help me,thx.
String video1 = "F:/media/v1.mp4";
String track1 = "F:/media/m1.aac";
String track2 = "F:/media/m2.aac";
Movie m = MovieCreator.build(video1);
AACTrackImpl aac1 = new AACTrackImpl(new FileDataSourceImpl(track1));
AACTrackImpl aac2 = new AACTrackImpl(new FileDataSourceImpl(track2));
m.addTrack(aac1);
m.addTrack(aac2);
DefaultMp4Builder mp4Builder = new DefaultMp4Builder();
Container out = mp4Builder.build(m);
FileOutputStream fos = new FileOutputStream("output.mp4");
FileChannel fc = fos.getChannel();
out.writeContainer(fc);
fos.close();
Hey guys, thanks so much for putting this library together.
I've been struggling to get this to work on Android, my goal is to trim a video file that I pull up from res/raw. I noticed two things:
I haven't been able to find any sample code for this out there that works. The closest thing I've seen is this from dadachi, but it uses a seemingly old version of MovieCreator.build() that passes in a FileChannel:
Movie movie = MovieCreator.build(new FileInputStream(new File(folder.getPath() +
File.separator + "sample1" + ".mp4")).getChannel());
Here's that code:
https://github.com/dadachi/TestMp4parser/blob/master/src/org/bestforce/testmp4parser/ShortenExample.java
Any help is appreciated!
According to the duration documentation of the tkhd box, "[...] the value of this field is equal to the sum of the durations of all of the track’s edits. If there is no edit list, then the duration is the sum of the sample durations [...]"
Yet, DefaultMp4Builder delegates to Track#getDuration() for both, the tkhd and mdhd, always returning the total sample duration, thus not allowing edits to create a track that is shorter than the media.
I understand that position, where we will cut the video, must be the begin of an Iframe. But how should we do if Iframe interval is 10 seconds? What should we do if we want to crop the first 6 seconds of video?
Hi Sebastian,
We had a file with deprecated version of sgpd box, and didn't know that the version was deprecated and just got the message that the version was not supported. For clarity, I suggest that you change the error message in the SampleGroupDescriptionBox.java method _parseDetails():
if (this.getVersion() != 1) {
throw new RuntimeException("SampleGroupDescriptionBox are only supported in version 1");
}
to
if (this.getVersion() == 0) {
throw new RuntimeException("SampleGroupDescription version 0 is deprecated and not supported.")
} else if (this.getVersion != 1) {
throw new RuntimeException("SampleGroupDescriptionBox is only supported in version 1");
}
Regards,
Torbjörn
hai sannies,
I am getting null pointer exception at
at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl$SliceHeader.(H264TrackImpl.java:541)
for the below code,
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.h264"));
Movie movie = new Movie();
movie.addTrack(h264Track);
Container mp4file = new DefaultMp4Builder().build(movie);
FileChannel fc = new FileOutputStream(new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/decodingvideo.mp4")).getChannel();
mp4file.writeContainer(fc);
fc.close();
Please help me how to do this?
mp4parser needs to be able to wrap a normal avc1 track and convert it to an avc3 track (important for DASH and resolution change within adaptation set)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.googlecode.mp4parser.authoring.samples.DefaultMp4SampleList.(DefaultMp4SampleList.java:55)
at com.coremedia.iso.boxes.mdat.SampleList.(SampleList.java:33)
at com.googlecode.mp4parser.authoring.Mp4TrackImpl.(Mp4TrackImpl.java:60)
at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:57)
at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:38)
at com.googlecode.mp4parser.AppendExample.main(AppendExample.java:29)
The class PrintStructure in package com.google.code.mp4parser.example seems to have a bug.
The program is supposed to print an indented list of the boxes in the stream. For each box that is a container, it is supposed to parse the contents, and print an indented list of boxes inside. You would expect that the size of a container would correspond to the sum of the sizes of its "top level" constituents, plus 8 bytes. Here is the beginning of the output from the program, exhibiting the error:
ftyp@0 size: 24
mdat@24 size: 6930099
moov@6930123 size: 3765
mvhd@13860262 size: 108
udta@13860370 size: 38
©xyz@20790625 size: 30
trak@20790655 size: 2164
tkhd@27720948 size: 92
mdia@27721040 size: 2064
mdhd@34651433 size: 32
This output seems to indicate that the udta box of size 38 contains a ©xyz box of size 30 and a trak box of size 2164 -- which is impossible. And, notice that the udta box begins at an offset of 13,860,370. Well, the whole file is just 6,933,888 bytes long.
Hi,Sannies,
I try to use this method to create a Movie instance,but exception occurs.
Look forward to your replying,thx.
code:
String videoFile = "F:/media/v2.mp4";
String track1 = "F:/media/m3.aac";
String track2 = "F:/media/m4.aac";
Movie m = MovieCreator.build(videoFile);
Track aac1 = new AACTrackImpl(new FileDataSourceImpl(track1));
Track aac2 = new AACTrackImpl(new FileDataSourceImpl(track2));
m.addTrack(aac1);
m.addTrack(aac2);
DefaultMp4Builder mp4Builder = new DefaultMp4Builder();
Container out = mp4Builder.build(m);
FileOutputStream fos = new FileOutputStream("1.mp4");
FileChannel fc = fos.getChannel();
out.writeContainer(fc);
fos.close();
exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.googlecode.mp4parser.authoring.samples.DefaultMp4SampleList.(DefaultMp4SampleList.java:55)
at com.coremedia.iso.boxes.mdat.SampleList.(SampleList.java:33)
at com.googlecode.mp4parser.authoring.Mp4TrackImpl.(Mp4TrackImpl.java:60)
at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:57)
at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:38)
at com.googlecode.mp4parser.MuxMp4SourcesExample.main(MuxMp4SourcesExample.java:27)
I get the following error after mvn package
on current master b81092e
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project isoparser: Compilation failure: Compilation failure:
[ERROR] \git\mp4parser\isoparser\src\main\java\com\mp4parser\iso14496\part15\HEV
CConfigurationBox.java:[11,7] error: class HevcConfigurationBox is public, should be declared in a file named HevcConfigurationBox.java
[ERROR] \git\mp4parser\isoparser\src\main\java\com\mp4parser\iso14496\part15\HEVCDecoderConfigurationRecord.java:[28,7] error: class HevcDecoderConfigurationRec
ord is public, should be declared in a file named HevcDecoderConfigurationRecord.java
When you have a moment could you please release 1.0.5.4 to the maven repo. Thanks
I have an h.264 encoded file which looks good when I use ffmpeg to place it in an mp4 container, but when I use isoparser it doesnt look good at all. Heres the code that I used
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("dump.h264"));
Movie m = new Movie();
m.addTrack(h264Track);
Container out = new DefaultMp4Builder().build(m);
FileOutputStream fos = new FileOutputStream(new File("output.mp4"));
FileChannel fc = fos.getChannel();
out.writeContainer(fc);
fos.close();
Here is the ffmpeg command line:
ffmpeg -i dump.h264 -an -threads 0 ffoutput.mp4
Bad image: https://dl.dropboxusercontent.com/u/7316897/projects/h264/bad.png
Good image: https://dl.dropboxusercontent.com/u/7316897/projects/h264/good.png
Dump file for verification: https://dl.dropboxusercontent.com/u/7316897/projects/h264/dump.h264
I'm trying to append 2 mp4 audio tracks. Looks like IsoFile.getMovieBox() returns null at MovieCreator.java:51.
I'm using standard files generated by akamai for HLS streaming. Here's the link to one of the files https://dl.dropboxusercontent.com/u/1149078/segment1.mp4
I can see how to load/edit mp4s, but how do you write one with this library?
When using FragmentedMP4Builder for example, usually the resulting movie`s timescale gets adjusted to the timescale of the video track(s) which is okay.
But currently any edit list entries get copied from the source file into the resulting file. But then elst entries become invalid since duration values refer to movie timescale in mvhd which has acutally changed.
Possible to adjust the duration values in there according to the changed timescale value from mvhd?
Hi mate,
Great library!
I'm trying to crop an audio track to match a video duration and then mux together. At the moment I've just hard coded in 5 seconds for the audio duration, but it is coming out much shorter. I know it's to do with the sample length mismatch between the tracks but I just can't seem to work it out.
I've tried to follow your lead (in ShortenExample.java) but my audio track is always much shorter than expected. i.e. the endSample is not calculated properly.
This is my code, anything obviously wrong here?
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath();
String videoPath = path + "/" + "sas-video.mp4";
Movie orig_movie = MovieCreator.build(videoPath);
String filename = "finalaudiolong.aac";
File audioFile = new File(path, filename);
AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl(audioFile));
Track track = (Track) orig_movie.getTracks().get(0);
double startTime1 = 0;
double endTime1 = 5; //stop at 5 seconds
boolean timeCorrected = false;
if (track.getSyncSamples() != null && track.getSyncSamples().length > 0) {
if (timeCorrected) {
throw new RuntimeException("The startTime has already been corrected by another track with SyncSample. Not Supported.");
}
startTime1 = correctTimeToSyncSample(track, startTime1, false);
endTime1 = correctTimeToSyncSample(track, endTime1, true);
timeCorrected = true;
}
long currentSample = 0;
double currentTime = 0;
double lastTime = -1;
long startSample1 = -1;
long endSample1 = -1;
for (int i = 0; i < track.getSampleDurations().length; i++) {
long delta = track.getSampleDurations()[i];
if (currentTime > lastTime && currentTime <= startTime1) {
startSample1 = currentSample;
}
if (currentTime > lastTime && currentTime <= endTime1) {
endSample1 = currentSample;
}
lastTime = currentTime;
currentTime += (double) delta / (double) track.getTrackMetaData().getTimescale();
currentSample++;
}
CroppedTrack cropperAacTrack = new CroppedTrack(aacTrack, startSample1, endSample1);
Movie movie = new Movie();
movie.addTrack(track);
movie.addTrack(cropperAacTrack);
Container mp4file = new DefaultMp4Builder().build(movie);
FileChannel fc = new FileOutputStream(new File(path,"sas-video-with-audio.mp4")).getChannel();
mp4file.writeContainer(fc);
fc.close();
Hi, it looks like normal tag information can be read from audio files, album / artist / title etc, but I could not see a way to read chapter information (title and time) from m4b files. Is there a way to do this? If not, could it be added? I have not found any Android library capable of this. Would be super cool if mp4parser supported this!
Is it possible with mp4parser to read h.264's profile and it's level from an mp4 file? Can you provide an example?
Thank you.
Hi,
I was trying to run the SubTitleExample but I got this:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createStco(DefaultMp4Builder.java:477)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createStbl(DefaultMp4Builder.java:340)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createTrackBox(DefaultMp4Builder.java:301)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createMovieBox(DefaultMp4Builder.java:213)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.build(DefaultMp4Builder.java:115)
at com.googlecode.mp4parser.SubTitleExample.main(SubTitleExample.java:42)
After running git bisect
it seems this commit 7e2d5c4 introduced the issue:
commit 7e2d5c43cb8714e3f0493e9d50256d0e1f343be7
Author: Sebastian Annies <[email protected]>
Date: Wed Aug 20 20:22:03 2014 +0200
Made TwoSecondsIntersectionFinder work with samples much longer than two seconds (e.g. subtitles)
which added only one line. I'm not sure what does that line do but removing it from current master branch makes SubTitleExample run for me.
Best,
David
Hi
First of all I want to thank for this wonderful plugin for video operations. I am facing issue in rotating the video . The rotation works fine on android player but when I try to upload it in my computer and play it then player (windows media player || VLC) doesnt consider the rotation and the video is played inverted.
Below is my code which does the rotation of the video:-
//rotate the video
Matrix deg;
if(rotation.equals("270")) //if stream recorded from front camera
deg = Matrix.ROTATE_270;
else
deg = Matrix.ROTATE_90; //else stream is recorded from rear camera
File input = new File(tempOutput);
File output = new File(outFileName);
IsoFile isoFile = new IsoFile(input.getAbsolutePath());
Movie m = new Movie();
List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);
for (TrackBox trackBox : trackBoxes) {
trackBox.getTrackHeaderBox().setMatrix(deg);
m.addTrack(new Mp4TrackImpl("output1", trackBox) {
});
}
Container finalContainer = new DefaultMp4Builder().build(m);
@SuppressWarnings("resource")
FileChannel finalStream = new RandomAccessFile(output.getAbsolutePath(), "rw").getChannel();
finalContainer.writeContainer(finalStream);
finalStream.close();
isoFile.close();
This code works for android video player but doesnt support players like VLC or windows media player.
Am I missing something in the above code so that the video remains uniform in all the players.
Tks in advance.
Vilash
When parsing a IsoFile from an MemoryDataSourceImpl, I always get errors like:
java.lang.RuntimeException: java.lang.IllegalArgumentException: Bad position (limit 41958): 1769172853
at java.nio.Buffer.positionImpl(Buffer.java:364)
at java.nio.Buffer.position(Buffer.java:358)
at com.googlecode.mp4parser.MemoryDataSourceImpl.positio...
This seems to be caused by map(...) implementation changing the data's position.
Restoring the position fixes the issue:
public ByteBuffer map(long startPosition, long size) throws IOException {
int oldPosition = data.position();
data.position(l2i(startPosition));
ByteBuffer result = data.slice();
result.limit(l2i(size));
data.position(oldPosition);
return result;
}
Some basic questions:
Which tool to manage the library files with their dependencies?
How To install the library?
Sorry, I'm trying to explore your code on how it get H.264 video width and height. and I can't even find how to use the library to get that information.
I have try to cut a part of a video. The input video's time is 10 minutes.
startTime = 60
endTime = 300
=>The generated output's time must be 4 minutes length.
The output is generated but not extractly. Output video's time is 2 minutes.
Can you give me an method to fix it?
See attachment for an h264 raw data file. It process 300ish samples and then throws an exception indicating "buffer repositioning required".
Granted, there might be something wrong with the data, but it can be processed successfully through ffmpeg and passes diagnostics on another tool I am using. I'm still working dillegently to prove it isn't an issue on our end, but maybe there is a bug in mp4parser.
The only thing of note is that ffmpeg does complain about SEI unit sizes being truncated so perhaps that is an edge case mp4parser isn't handling, and hopefully something I can fix on this end too.
This is the code
H264TrackImpl videoTrack = new H264TrackImpl(new FileDataSourceImpl(inputFile.toFile()));
Movie movie = new Movie();
movie.addTrack(videoTrack);
Container mp4file = new DefaultMp4Builder().build(movie);
try(FileChannel fc = new FileOutputStream(destination.toFile()).getChannel()) {
mp4file.writeContainer(fc);
}
Here is the data file: https://www.dropbox.com/s/71qok2nvy7oczgj/1410461853638.h264?dl=0
Hi @sannies, I would like to discuss the possibility of remove the aspectj dependency.
I underestand the logic behind RequiresParseDetailAspect, but it seems to me that this could be implemented inside the ParserImpl. It would not be as lazy as possible but at the same time it would be more predictable.
I can go ahead with a PR, but I need to know if there is any other use case that I'm not aware of.
This removal would be very beneficial for keeping the library lightweight especially in android.
I'm new to this lib, and i want to cut videos and encode and decode a video from .MOV (ios) to .mp4
Can you post a sample code demonstrating the cutting of videos.
I'm using the latest build 1.0.5.3 jar package. the call stack is as following: video format is mpeg4
at com.googlecode.mp4parser.authoring.tracks.AppendTrack.getSyncSamples(AppendTrack.java:426)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createStss(DefaultMp4Builder.java:521)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createStbl(DefaultMp4Builder.java:336)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createTrackBox(DefaultMp4Builder.java:301)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createMovieBox(DefaultMp4Builder.java:213)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.build(DefaultMp4Builder.java:115)
at com.ss.android.newmedia.app.VideoMerger$1.run(VideoMerger.java:80)
at java.lang.Thread.run(Thread.java:841)
I have recorded videos using front and back camera simultaneously. When i combine all the videos to single one. Front camera videos showing as different rotation 270 back camera showing as 90. How to change all videos to same rotation. Please shootout me what i did wrong
public static final double[] matrix_0 = new double[] { 1.0, 0.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 0.0 };
public static final double[] matrix_90 = new double[] { 0.0, 1.0, -1.0,
0.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
public static final double[] matrix_180 = new double[] { -1.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
public static final double[] matrix_270 = new double[] { 0.0, -1.0, 1.0,
0.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
try {
File tempfile = new File(Environment
.getExternalStorageDirectory().getAbsolutePath()
+ "/Temp");
if (tempfile.isDirectory()) {
String[] list = tempfile.list();
inMovies = new Movie[list.length];
for (int i = 0; i < list.length; i++) {
inMovies[i] = MovieCreator.build(new FileInputStream(
new File(tempfile, list[i]).getAbsolutePath())
.getChannel());
}
}
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 (t.getHandler().equals("")) {
}
}
}
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()])));
}
IsoFile out = new DefaultMp4Builder().build(result);
TrackBox tb = out.getMovieBox().getBoxes(TrackBox.class).get(1);
TrackHeaderBox tkhd = tb.getTrackHeaderBox();
Log.i("TAG", "tkhd.getMatrix()" + tkhd.getMatrix());
tkhd.setMatrix(matrix_90);
long timestamp = new Date().getTime();
String timestampS = "" + timestamp;
File storagePath = new File(
Environment.getExternalStorageDirectory()
+ "/TempmergeVideo");
storagePath.mkdirs();
File myMovie = new File(storagePath, String.format(
"output-%s.mp4", timestampS));
mFileName = myMovie.getAbsolutePath();
FileOutputStream fos = new FileOutputStream(myMovie);
FileChannel fco = fos.getChannel();
fco.position(0);
out.getBox(fco);
fco.close();
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Hi guys. I downloaded latest version of your library from maven central as gradle dependency.
I trying to merge multiple videos into one, and got an exception from library
My code
try {
Movie movie = new Movie();
Log.e("PATH", Integer.toString(filePaths.size()));
for(String path : filePaths) {
Log.e("PATH", path);
H264TrackImpl track = new H264TrackImpl(new FileDataSourceImpl(path));
movie.addTrack(track);
}
Container out = new DefaultMp4Builder().build(movie);
FileOutputStream fos = new FileOutputStream(new File("h264_output.mp4"));
FileChannel fc = fos.getChannel();
out.writeContainer(fc);
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
And got exception:
Caused by: java.lang.IndexOutOfBoundsException: index=0, limit=0
at java.nio.Buffer.checkIndex(Buffer.java:150)
at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:158)
at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.readSamples(H264TrackImpl.java:341)
at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.parse(H264TrackImpl.java:112)
at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:103)
at com.myapp.activity.TestCompilationActivity.onCreate(TestCompilationActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5280)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5388)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:655)
at dalvik.system.NativeStart.main(Native Method)
Any suggestions ?
I'd like to be able to implement a DataSource which can be passed to the Track Impls that may have data pending semantics. Currently DataSource, and its use in the tack Impls, require the complete size of the data to be known in advanced. My use case is that I am streaming the data from a source. In that case, the size is unknown to me and so current DataSource semantics requires me to stream all the data from the source before processing it.
Am I missing something that should allow this?
If not, I propose a new constructor on the track Impls which would take in an NIO byte channel. Or alternatively, a new ByteBufferDataSource interface type which can be used to construct these Impls which would gracefully handle partial data until the ByteBufferDataSourceImpl indicates eof by some other means. That construction may not make sense for all Track types, but it would, for example for the H264 track.
i got error in this project like : No box object found for ftyp , what is the soluion of it ?
Coin content information box
https://gist.github.com/RenegadeEagle/3752b204e5974c2ab65a
So I have this code here. And I am attempting to combine all videos inside of my Videos folder, although it seems that the Audio is not Syncing correctly with all the videos.
Is there a reason for this? Maybe a fix? Thanks.
I'm getting these kinds of exceptions from various test programs. From trying to debug the issue, I get very strange behavior with the bit alignment when trying to read the audio files.
Exception in thread "main" java.io.IOException: Expected Start Word 0xfff at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.readADTSHeader(AACTrackImpl.java:293) at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.readSamples(AACTrackImpl.java:325) at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.(AACTrackImpl.java:142) at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.(AACTrackImpl.java:135)
I initially received a similar error with an mp3 test:
Exception in thread "main" java.io.IOException: Expected Start Word 0x7ff at com.googlecode.mp4parser.authoring.tracks.MP3TrackImpl.readMP3Header(MP3TrackImpl.java:200) at com.googlecode.mp4parser.authoring.tracks.MP3TrackImpl.readSamples(MP3TrackImpl.java:175) at com.googlecode.mp4parser.authoring.tracks.MP3TrackImpl.(MP3TrackImpl.java:64) at com.googlecode.mp4parser.authoring.tracks.MP3TrackImpl.(MP3TrackImpl.java:53) at Greg2.main(Greg2.java:26)
and it seemed that making test changes to the MP3TrackImpl.java class after the code causing the problem would affect earlier code. For example, if I commented out the line:
hdr.layer = brb.readBits(2); // C
The code would make it past the above code.
I was also playing around with the bits coming back from the line:
BitReaderBuffer brb = new BitReaderBuffer((ByteBuffer) bb.rewind()); int sync = brb.readBits(11); // A
and everything worked fine up to a >>> 4 on sync. However, if I did a >>> 5, the bits would then get scrambled. It is as if the jvm is improperly optimizing the code or messing up the memory alignment.
I've tested these things against multiple releases:
isoparser-1.0.3.11.jar isoparser-1.0.4.1.jar isoparser-1.0.4.2.jar
Any ideas?
my requirement is live streaming from ip cameras.
i am getting h.264 byte frames from server,then how to play h.264 byte frames in android?
thanks in advance
I'm trying to append one mp4 to another, and everything seems to work just fine. No exceptions, no crashing, nothing. However, my final output.mp4's filesize is correct(video 1 + video 2), but only ever plays video 1. The appended video never shows up in the final output, although the file size has doubled.
Here's my method for appending the videos
private void createFinalOutputVideo() {
CameraHelper helper = new CameraHelper(this);
File outFile = helper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO);
try {
Movie[] movies = new Movie[2];
movies[0] = MovieCreator.build(mVideoPath);
movies[1] = MovieCreator.build(mOutroPath);
Log.d("ShareActivity", "Video 1 path " + mVideoPath);
Log.d("ShareActivity", "Video 2 path " + mOutroPath);
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : movies) {
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);
FileChannel fc = new RandomAccessFile(String.format(outFile.getPath()), "rw").getChannel();
out.writeContainer(fc);
fc.close();
Toast.makeText(this, "Merge successful! Output path is " + outFile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error merging videos!", Toast.LENGTH_SHORT).show();
}
}
I'm using isoviewer-1.0.3.jar, btw
Any examples will be good. Thanks
hi,sannies,when I muxing an acc file(8seconds) into a mp4 file,a runtime exception (no box object found for fytp)happened ,can u help me ?waitting for your replay...
Further to my comment on issue #24, I created an example Android application that can reproduce the error on my device. I can't really guarantee it the same is the same issue as #24, so I am adding a separate ticket.
The error I am getting when running the Android app is:
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createStco(SourceFile:477)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createStbl(SourceFile:340)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createTrackBox(SourceFile:301)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.createMovieBox(SourceFile:213)
at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder.build(SourceFile:115)
The code for the app is at https://github.com/jmgirven/mp4parser_test.
The video I test with is GOPR1008.MP4 at https://github.com/jmgirven/mp4parser_test/tree/master/app/src/main/assets.
The main code is in https://github.com/jmgirven/mp4parser_test/blob/master/app/src/main/java/com/example/mp4parser/test/mp4parsertest.
If I use a start time of 5000ms and an end time of 8000ms, for example, the code runs find and edits the video to that length. However, if I change the end time to 10000ms, it fails with the above error. Can you reproduce this error?
The video is actually recorded with a GoPro Hero 4.
Thanks,
Jon.
Is that possible to insert more key frames to mp4 using this library?
Like ffmpeg -force_key_frames functions does.
e.g. insert a key frame every 1 second.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.