Android MP4Parser无法播放视频 [英] Android MP4Parser cannot play video

查看:186
本文介绍了Android MP4Parser无法播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MP4Parser 将简单的3秒外线视频添加到现有视频中,但是由于某种原因,合并发生后,我无法播放视频.尝试从我的图库播放视频时,出现臭名昭著的抱歉,无法播放此视频"错误.任何人都有类似的经验吗?我正在运行4.4 KitKat的HTC One上进行测试

I'm attempting to append a simple, 3 second outro video to an existing video using MP4Parser, but for some reason I cannot play the video after the merge happens. I'm getting the infamous "Sorry, this video cannot be played" error when trying to play the video from my gallery. Anyone have similar experience doing this? I'm testing on an HTC One running 4.4 KitKat

这是我的方法,可将.mp4片段合并为一个片段,该片段取自MP4Parser本身的AppendExample.

Here's my method to merge to .mp4 clips into a single one, taken from the AppendExample from MP4Parser itself.

   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();
    }


}

有没有人遇到过MP4Parser这个问题?如果塞巴斯蒂安能在这里鸣叫,那将是很棒的.

Has anyone ever had this issue with MP4Parser? Would be great if Sebastian could chime in here.

推荐答案

我一直在使用 https://github .com/hoolrory/AndroidVideoSamples 调整内部使用mp4parser的视频的大小.样本可以调整视频大小,但没有声音.因此,我添加了一种混合方式,可以将曲目添加到视频中.但随后,视频将出现错误,并在最后显示无法播放此视频"消息.

I have been using https://github.com/hoolrory/AndroidVideoSamples for resizing Videos which uses mp4parser internally. The samples have a way to resize the video but it will not have the sound. So I added a mix to add tracks into the video. But then the video will error out with "Can't play this video" message at the end.

希望能有所帮助.

这篇关于Android MP4Parser无法播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆