Movie object created with MovieCreator.build() returns always 0 tracks

347 views
Skip to first unread message

nalitzis

unread,
Jun 8, 2012, 6:25:09 AM6/8/12
to mp4parser-discussion
Hi! my purpose is to mix a mp4 file with an aac audio. I'm using
https://github.com/timsu/android-aac-enc that basically wraps
mp4parser lib.

My target is to mux a mp4 file with an aac audio file.


String inFile =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/count-
video.mp4";
InputStream input = new FileInputStream(infile);
Movie video = MovieCreator.build(Channels.newChannel(input));

String AAC_FILE_IN =
Environment.getExternalStorageDirectory().getAbsolutePath() +"/
out.aac";
InputStream inputAudio = new FileInputStream(AAC_FILE_IN);
PushbackInputStream pbi = new PushbackInputStream(inputAudio, 100);
Track audioTrack = new AACTrackImpl(pbi);
video.addTrack(audioTrack);



but I obtain always a mp4 with only the audio track. The Movie object
contains always 0 tracks. the method getBoxes below infact returns
always an empty list.

public static Movie build(ReadableByteChannel channel) throws
IOException {
IsoFile isoFile = new IsoFile(channel);
Movie m = new Movie();
List<TrackBox> trackBoxes =
isoFile.getMovieBox().getBoxes(TrackBox.class);
for (TrackBox trackBox : trackBoxes) {
m.addTrack(new Mp4TrackImpl(trackBox));
}
return m;
}

Can you suggest me how to deal with this problem and why it returns
always 0 tracks ? I've tried many mp4 files but same results. Thanks
for your good work.

Sebastian Annies

unread,
Jun 8, 2012, 6:35:13 AM6/8/12
to mp4parser-...@googlegroups.com
I'm not sure if you just didn't give the full code in the email but if you did you missed writing the file! 

video.addTrack(audioTrack);  just adds the track to the object representation of the video and not to the file on the disk. 

You will need to write the video back to disk. For example: 

        IsoFile out = new DefaultMp4Builder().build(video);
        FileOutputStream fos = new FileOutputStream(new File("output.mp4"));
        out.getBox(fos.getChannel());
        fos.close();

Now try to open output.mp4. It should contain both tracks. 

I hope I didn't misunderstand you. A full working example (let's say a main method that I can compile and run) really helps me to understand want you are trying  to achieve.

Best Regards,
Sebastian

2012/6/8 nalitzis <adolfo....@gmail.com>

nalitzis

unread,
Jun 8, 2012, 8:47:08 AM6/8/12
to mp4parser-discussion
Hi Sebastian thanks for the quick answer!

You are right.. I forgot to post it on the email.
This is the code I use:
String MP4_FILE =
Environment.getExternalStorageDirectory().getAbsolutePath() +"/
video.mp4";
IsoFile out = new DefaultMp4Builder().build(video);
FileOutputStream output = new FileOutputStream(MP4_FILE);
out.getBox(output.getChannel());
output.close();

If you want I can send you the outputFile and the Java class I use..
VLC tells me that it has 1 stream, which is correctly of type Audio
(code MPEG AAC Audio mp4a).

Thanks,

Adolfo

On 8 Giu, 12:35, Sebastian Annies <sebastian.ann...@gmail.com> wrote:
> I'm not sure if you just didn't give the full code in the email but if you
> did you missed writing the file!
>
> video.addTrack(audioTrack);  just adds the track to the object
> representation of the video and not to the file on the disk.
>
> You will need to write the video back to disk. For example:
>
>         IsoFile out = new DefaultMp4Builder().build(video);
>         FileOutputStream fos = new FileOutputStream(new File("output.mp4"));
>         out.getBox(fos.getChannel());
>         fos.close();
>
> Now try to open output.mp4. It should contain both tracks.
>
> I hope I didn't misunderstand you. A full working example (let's say a main
> method that I can compile and run) really helps me to understand want you
> are trying  to achieve.
>
> Best Regards,
> Sebastian
>
> 2012/6/8 nalitzis <adolfo.bulf...@gmail.com>
>
>
>
>
>
>
>
> > Hi! my purpose is to mix a mp4 file with an aac audio. I'm using
> >https://github.com/timsu/android-aac-encthat basically wraps

nalitzis

unread,
Jun 8, 2012, 9:00:19 AM6/8/12
to mp4parser-discussion
In class Main.java:

private String MP4_FILE =
Environment.getExternalStorageDirectory().getAbsolutePath() +"/
video.mp4";

    private String MP4_FILE_IN =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/count-
video.mp4";
    private String AAC_FILE_IN =
Environment.getExternalStorageDirectory().getAbsolutePath() +"/
out.aac";


private void convert(){

    try {
    new AACWithM4A().convert(this, MP4_FILE_IN, AAC_FILE_IN,
MP4_FILE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


class AACWithM4A.java:

public class AACWithM4A {

private static final String TAG = "AACWithM4A";

private static Context context;

public static Context getContext() {
return context;
}

public void convert(Context context, String infile, String
inFileAudio, String outfile) throws IOException {

AACWithM4A.context = context;


InputStream input = new FileInputStream(infile);
InputStream inputAudio = new FileInputStream(inFileAudio);
Movie video =
MovieCreator.build(Channels.newChannel(input));


PushbackInputStream pbi = new
PushbackInputStream(inputAudio, 100);
Track audioTrack = new AACTrackImpl(pbi);
video.addTrack(audioTrack);

IsoFile out = new DefaultMp4Builder().build(video);
FileOutputStream output = new
FileOutputStream(outfile);
out.getBox(output.getChannel());
output.close();
> > >https://github.com/timsu/android-aac-encthatbasically wraps

Sebastian Annies

unread,
Jun 8, 2012, 9:03:30 AM6/8/12
to mp4parser-...@googlegroups.com
Send me all you got. It's quicker that way.

2012/6/8 nalitzis <adolfo....@gmail.com>

thadpe...@gmail.com

unread,
Jun 21, 2013, 5:43:49 PM6/21/13
to mp4parser-...@googlegroups.com
Sorry for double posting this in another thread i did not find this thread when i did my first 2+hrs of searching but found it today. i posted nearly the exact same issue  with my code in the following link
https://groups.google.com/forum/#!topic/mp4parser-discussion/dYFKesjwIyw

I am also very interesting in what is being done wrong.
Reply all
Reply to author
Forward
0 new messages