使用ffmpeg的Android视频裁剪

我正在使用https://github.com/WritingMinds/ffmpeg-android-java使用以下命令裁剪视频:

execFFmpegCommand(" -i " + in + " -filter:v " + "crop=" + 240 + ":" + 120 + ":" + 100 + ":" + 100 + " -c:a copy " + out);

其中“ in”是输入文件,“ out”是输出文件.

我遇到了很多相同的问题,却找不到所需的解决方案.我还尝试了以下通过搜索发现的命令:

execFFmpegCommand(" -i " + in + " -filter:v " + "crop=" + 240 + ":" + 120 + ":" + 100 + ":" + 100 + " -c:a copy " + out);

我在这里遇到的主要错误是:输出文件#0不包含任何流

private void execFFmpegCommand(final String command) {
    try {
        ffmpeg.execute(new String[]{command}, new ExecuteBinaryResponseHandler() {
            @Override
            public void onFailure(String s) {
                Log.d(TAG, "FAILED with output : " + s);
                progressDialog.dismiss();

            }

            @Override
            public void onSuccess(String s) {
                Log.d(TAG, "SUCCESS with output : " + s);
            }

            @Override
            public void onProgress(String s) {
                Log.d(TAG, "Started command : ffmpeg " + command);
                Log.d(TAG, "progress : " + s);
            }

            @Override
            public void onStart() {
                Log.d(TAG, "Started command : ffmpeg " + command);
                progressDialog.show();
            }

            @Override
            public void onFinish() {
                Log.d(TAG, "Finished command : ffmpeg " + command);
                progressDialog.dismiss();

            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // do nothing for now
    }
}

LogCat是:

 D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.209 17283-17866/com.myapp D/FFmpeg: Running publishing updates method
08-12 11:16:03.231 17283-17283/com.myapp W/MediaRecorder: mediarecorder went away with unhandled events
08-12 11:16:03.232 17283-17283/com.myapp W/MediaRecorder: mediarecorder went away with unhandled events
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: progress : ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: progress :   built with gcc 4.8 (GCC)
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: progress :   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=
08-12 11:16:03.355 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libavutil      55. 17.103 / 55. 17.103
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libavcodec     57. 24.102 / 57. 24.102
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libavformat    57. 25.100 / 57. 25.100
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libavdevice    57.  0.101 / 57.  0.101
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libavfilter     6. 31.100 /  6. 31.100
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libswscale      4.  0.100 /  4.  0.100
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libswresample   2.  0.101 /  2.  0.101
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress :   libpostproc    54.  0.100 / 54.  0.100
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress : Output #0, mp4, to ' -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4':
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: Started command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4
08-12 11:16:03.356 17283-17283/com.myapp D/ffmpeg: progress : Output file #0 does not contain any stream
08-12 11:16:03.357 17283-17283/com.myapp D/ffmpeg: FAILED with output : 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 ' -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4':
                                                          Output file #0 does not contain any stream
08-12 11:16:03.370 17283-17283/com.myapp D/ffmpeg: Finished command : ffmpeg  -i /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980754658.mp4 -vf crop=240:120:100:100 -c:a copy /storage/emulated/0/Android/data/com.myapp/Files/Video/myapp1470980763106_vid.mp4

解决方法:

我终于想通了
该命令应作为数组传递.

  String[] cmd = {"-i", in, "-filter:v", "crop=" + 240 + ":" + 120 + ":" + 100 + ":" + 100, "-c:a", "copy", out};

    execFFmpegCommand(cmd);
上一篇:c-裁剪功能BitBlt(…)


下一篇:VM打开虚拟机文件报错