combining mpeg4 videos with mp4Parser - android yields still video
Asked Answered
P

1

6

I am using the mp4Parser isoviewer-1.0-RC-35.jar to combine clips recorded with the android MediaRecorder. The clips seem to get combined correctly by listening to the audio tracks, but the video stays on one frame and the time code stays at zero on play back.

Media Recorder Code at time individual clips are created

mediaRecorder = new MediaRecorder();

        myCamera.lock();

        myCamera.unlock();

        String clipLocation = file.getAbsolutePath();
        _moviePaths.add(clipLocation);
        // Please maintain sequence of following code.

        // If you change sequence it will not work.
        mediaRecorder.setCamera(myCamera);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

        if (facingBack) {
            mediaRecorder.setOrientationHint(90);
        } else {
            mediaRecorder.setOrientationHint(270);
        }

        // Log.v("cam","supported vid sizes: "+
        // myCamera.getParameters().getSupportedVideoSizes());
        CamcorderProfile profile = CamcorderProfile
                .get(CamcorderProfile.QUALITY_720P);

        // mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
         //mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        // mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mediaRecorder.setMaxDuration(g.kMaxVideoDurationInMiliseconds);// 15seconds
        mediaRecorder.setProfile(profile);
        mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
        mediaRecorder.setOutputFile(path + filename);
        mediaRecorder.prepare();
        startTimer();
        mediaRecorder.start();

    }

Method i am using to combine the clips:

protected void combineClips() throws IOException{

        for(int i=0; i<_moviePaths.size();i++){

                Movie tm = MovieCreator.build(_moviePaths.get(i));
                _clips.add(tm);

        }

         List<Track> videoTracks = new LinkedList<Track>();
         List<Track> audioTracks = new LinkedList<Track>();

            for (Movie m : _clips) {
                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();
            Log.v("cam", "adding:"+audioTracks.size()+" audio tracks and "+videoTracks.size()+" video tracks");
            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(videoFolder.getPath()+"/output.mp4"), "rw").getChannel();
            out.writeContainer(fc);
            fc.close();

    }
Percussion answered 24/2, 2014 at 13:46 Comment(0)
P
7

Apparently the problem had something to do with the library: isoviewer-1.0-RC-35.jar. I replaced it with isoviewer-1.0-RC-27.jar and now everything is just dandy!

Percussion answered 24/2, 2014 at 14:24 Comment(2)
thanks man. It solved my problem...definately deserved an upvote But have you noticed,a blank screen appears when we shift from one video to another in final output.mp4 ... have you figured out any way to overcome thatHereof
@Percussion while combine front facing recorded video and back facing recorded into single file. Out file showing different rotation. How to change both videos same rotation? I was struggling last three days. Please help meGuereza

© 2022 - 2024 — McMap. All rights reserved.