android - FFMPEG 输出文件不包含任何流 [Android] video concat

标签 android video ffmpeg

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

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

日志:

E/onFailure: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
                                                            built with gcc 4.8 (GCC)
                                                            configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
                                                            libavutil      55. 17.103 / 55. 17.103
                                                            libavcodec     57. 24.102 / 57. 24.102
                                                            libavformat    57. 25.100 / 57. 25.100
                                                            libavdevice    57.  0.101 / 57.  0.101
                                                            libavfilter     6. 31.100 /  6. 31.100
                                                            libswscale      4.  0.100 /  4.  0.100
                                                            libswresample   2.  0.101 /  2.  0.101
                                                            libpostproc    54.  0.100 / 54.  0.100
                                                          Output #0, mp4, to ' -f concat -i /data/data/com.myapp/cache/ffmpeg-list-768575373.txt -c:v copy /storage/emulated/0/myapp/MergedVideos/1465426928071_Video.mp4':
                                                          Output file #0 does not contain any stream

任何帮助将不胜感激 谢谢

最佳答案

这是我的完整代码 fragment 。我正在向视频添加图像叠加层。为了测试,我将视频和图像保存在 Assets 文件夹中

    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
    }

关于android - FFMPEG 输出文件不包含任何流 [Android] video concat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37823539/

相关文章:

java - 在异步任务中不断出现空指针异常

android - 如何在 string.xml 文件中放入 "-"

iOS AVFoundation - 以 60 fps 的速度将视频转换为图像

c++ - 奇怪的枚举名称冲突

android - Flutter - 'enableInteractiveSelection' 不适用于 EditableText

Android Listview 标题和部分月份和日期列表

javascript - 使用ajax将Flash视频加载到div中

html - 不支持 "type"的指定 "video/mp4"属性

javascript - 有没有办法随机播放碎片化的 mp4?

ffmpeg - 使用 ffmpeg 从图像序列制作视频时覆盖完整视频长度