FFMPEG输出文件不包含任何流[Android]视频concat

时间:2016-06-14 23:05:46

标签: android video ffmpeg

我一直在尝试合并(连接)两个相同高度和宽度的mp4视频,但会出现一些错误。它说输出文件没有任何流。 请帮忙。 代码如下:

/gfs\./

logcat的:

String[] arg = new String[]{
                ActualVideoFile.getAbsolutePath(), path
        };
        String list = generateList(arg);
        String[] command = new String[]{
                " -f concat -i " + list + " -c:v copy " + mergedVideo.getAbsolutePath()
        };
        try {
            ffmpeg.execute(command, new FFmpegExecuteResponseHandler() {
                @Override
                public void onSuccess(String message) {
                    Log.e("SUCCESS", message);
                }

                @Override
                public void onProgress(String message) {
                    Log.e("onProgress", message);
                }

                @Override
                public void onFailure(String message) {
                    Log.e("onFailure", message);
                }

                @Override
                public void onStart() {
                    Log.e("onStart", "start");
                }

                @Override
                public void onFinish() {
                    Log.e("FINISH", "FINISHED");

                }
            });
        } catch (FFmpegCommandAlreadyRunningException e) {
            e.printStackTrace();
        }

任何帮助将不胜感激 感谢

2 个答案:

答案 0 :(得分:3)

这是我的完整代码段。我正在为视频添加图片叠加层。为了测试,我将视频和图像保存在资源文件夹

    File myDirectory = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/");
    File outputDirectory = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/video" + System.currentTimeMillis() + ".mp4");



    Log.d("directory path",Environment.getExternalStorageDirectory() + "/EditedVideo_2/");


    if (!myDirectory.exists())
    {
        myDirectory.mkdirs();
    }

    File f = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/sample.mp4");
    if (!f.exists()) try
    {

        InputStream is = getAssets().open("sample.mp4");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();


        FileOutputStream fos = new FileOutputStream(f);
        fos.write(buffer);
        fos.close();
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }


    Log.d("Path = ",f.getPath());



   File imageFile = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/ic_launcher.png");
    if (!imageFile.exists()) try
    {

        InputStream is = getAssets().open("ic_launcher.png");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();


        FileOutputStream fos = new FileOutputStream(imageFile);
        fos.write(buffer);
        fos.close();
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }




    FFmpeg ffmpeg = FFmpeg.getInstance(this);


    try {
        ffmpeg.loadBinary(new LoadBinaryResponseHandler()
        {

            @Override
            public void onStart()
            {
                Log.d("Event ","onStart");
            }

            @Override
            public void onFailure()
            {
                Log.d("Event ","onFailure");
            }

            @Override
            public void onSuccess()
            {
                Log.d("Event ","onSuccess");
            }

            @Override
            public void onFinish()
            {
                Log.d("Event ","onFinish");
            }
        });
    } catch (FFmpegNotSupportedException e) {
        // Handle if FFmpeg is not supported by device
    }





    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        //String[] cmd = {"-version"};



        String[] cmd = {"-i",""+f.getPath(),"-i",""+imageFile.getPath(),"-filter_complex","overlay=10:main_h-overlay_h-10",outputDirectory.getPath()};
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler()
        {

            @Override
            public void onStart()
            {
                Log.d("Event ","onStart");
            }

            @Override
            public void onProgress(String message)
            {
                Log.d("Event ","onProgress - "+message);

            }

            @Override
            public void onFailure(String message)
            {
                Log.d("Event ","onFailure - "+message);
            }

            @Override
            public void onSuccess(String message)
            {
                Log.d("Event ","onSuccess - "+message);
            }

            @Override
            public void onFinish()
            {
                Log.d("Event ","onFinish");
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }

答案 1 :(得分:1)

有同样的问题。原来它是命令的构建方式。

这是不正确的,因为您需要分割每个命令:

String[] command = new String[]{" -f concat -i " + list + " -c:v copy " + mergedVideo.getAbsolutePath();

Chirag您的回答是:

String[] cmd = {"-i",""+f.getPath(),"-i",""+imageFile.getPath(),"-filter_complex","overlay=10:main_h-overlay_h-10",outputDirectory.getPath()};

希望这有帮助。