Cant append to video in Android

自古美人都是妖i 提交于 2019-12-11 13:59:06

问题


I am using an mp4 parser for appending video. My problem is that I'm not able to append videos. I am getting such errors as BufferUnderFlow Exception. Can anyone tell me where I might have made a mistake?

This is my code:

public class MainActivity extends Activity
{
    Button b1;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1 = (Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener()
        {

            @SuppressWarnings("resource")
            @Override
            public void onClick(View v)
            {
                try 
                {
                    String f1 = Environment.getExternalStorageDirectory()+ "/wish_by_video.mp4";
                    String f2 = Environment.getExternalStorageDirectory() + "/wish_by_video.mp4";
                    String f3 = Environment.getExternalStorageDirectory() + "/wish_by_video.mp4";

                    Movie[] inMovies = new Movie[]{
                            MovieCreator.build(new FileInputStream(f1).getChannel()),
                            MovieCreator.build(new FileInputStream(f2).getChannel()),
                            MovieCreator.build(new FileInputStream(f3).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);
                            }
                        }
                    }

                    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[3])));
                    }

                    IsoFile out = new DefaultMp4Builder().build(result);


                    @SuppressWarnings("resource")
                    FileChannel fc = new RandomAccessFile(String.format(Environment.getExternalStorageDirectory()+"output.mp4"), "rw").getChannel();
                    fc.position(0);
                    out.getBox(fc);
                    fc.close();

                } 
                catch (FileNotFoundException e) 
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });


    }
}

来源:https://stackoverflow.com/questions/17543829/cant-append-to-video-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!