我一直在研究FFMPEG,这确实不是一件容易的事,因为我已经成功完成了一些工作。我完成了使用ffmpeg连接两个视频但不知何故,当涉及到两个以上时它不起作用。所以我找到了一些命令来完成我的任务。
我做的是合并两个视频:
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-strict", "experimental", "-filter_complex",
"[0:v]scale=1920x1080,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
"-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", savingPath};
上述内容适用于两个视频。我尝试更改三个视频的代码,但它不起作用。
我在上面的代码中所做的是:
但它没有合并,并在我的LogCat中给了我这个错误:
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
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Duration: 00:02:47.09, start: 0.000000, bitrate: 245 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 112 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2013-12-15 13:11:41
Duration: 00:03:51.08, start: 0.000000, bitrate: 1693 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1498 kb/s, 25 fps, 25 tbr, 50 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default)
Metadata:
creation_time : 2013-12-15 13:11:41
handler_name : IsoMedia File Produced by Google, 5-11-2011
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2015-05-30 02:06:06
Duration: 00:04:48.48, start: 0.000000, bitrate: 3608 kb/s
Stream #2:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x480, 3478 kb/s, 30.28 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2015-05-30 02:06:06
handler_name : VideoHandle
encoder :
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 125 kb/s (default)
Metadata:
creation_time : 2015-05-30 02:06:06
handler_name : SoundHandle
[Parsed_setsar_1 @ 0xa9ea9220] num:den syntax is deprecated, please use num/den or named options instead
[Parsed_setsar_4 @ 0xa9ea9310] num:den syntax is deprecated, please use num/den or named options instead
[Parsed_setsar_1 @ 0xa9ea92c0] num:den syntax is deprecated, please use num/den or named options instead
[Parsed_setsar_4 @ 0xa9ea93b0] num:den syntax is deprecated, please us
我已经尝试了另外一个可以连接两个视频的命令,但它仍不适用于两个以上的视频:
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i", "/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4", "-strict", "experimental", "-filter_complex",
"[0:v]scale=480x640,setsar=1:1[v0];[1:v]scale=480x640,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=3:v=1:a=1",
"-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "480x640", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", savingPath};
您可以在上面的代码中清楚地看到我已尝试将此功能用于三个视频,但仍然没有运气。非常感谢您的帮助。感谢。
EDITS
在遵循Lord Neckbeard评论部分的建议之后,我在我的代码中使用了他的建议但是在这之后仍然没有运气,但是控制台的输出已经改变了,这是命令我使用过:
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i", "/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4", "-strict", "experimental", "-filter_complex",
"[0:v]scale=480x640,setsar=1[v0];[1:v]scale=480x640,setsar=1[v1];[v0][0:a][v1][1:a] concat=n=3:v=1:a=1",
"-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "480x640", "-vcodec", "libx264","-crf","27","-preset", "ultrafast", savingPath};
在这里您可以清楚地看到我使用 setsar = 1 并仅使用 -crf 。
日志是:
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
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Duration: 00:02:47.09, start: 0.000000, bitrate: 245 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 112 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2013-12-15 13:11:41
Duration: 00:03:51.08, start: 0.000000, bitrate: 1693 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1498 kb/s, 25 fps, 25 tbr, 50 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default)
Metadata:
creation_time : 2013-12-15 13:11:41
handler_name : IsoMedia File Produced by Google, 5-11-2011
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2015-05-30 02:06:06
Duration: 00:04:48.48, start: 0.000000, bitrate: 3608 kb/s
Stream #2:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x480, 3478 kb/s, 30.28 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2015-05-30 02:06:06
handler_name : VideoHandle
encoder :
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 125 kb/s (default)
Metadata:
creation_time : 2015-05-30 02:06:06
handler_name : SoundHandle
[Parsed_concat_4 @ 0xa7ea91d0] Input link in2:v0 parameters (size 720x480, SAR 0:1) do not match the corresponding output link in0:v0 parameters (480x640, SAR 1:1)
[Parsed_concat_4 @ 0xa7ea91d0] Failed to configure output pad on Parsed_concat_4
Error configuring complex filters.
Invalid argument
注意: 我尝试过使用setsar = 1/1,但结果仍然相同。
答案 0 :(得分:1)
您省略了第三个输入的过滤链,但没有为concat提供足够的输入。将命令更改为:
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i", "/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4", "-filter_complex",
"[0:v]scale=480x640,setsar=1[v0];[1:v]scale=480x640,setsar=1[v1];[2:v]scale=480x640,setsar=1[v2];[v0][0:a][v1][1:a][v2][2:a]concat=n=3:v=1:a=1",
"-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "480x640", "-vcodec", "libx264","-crf","27","-preset", "ultrafast", savingPath};
我唯一做的就是删除-strict experimental
。只有旧版本才需要。我把其他一切都保留了下来。
答案 1 :(得分:1)
String cmd[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i",
"/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i",
"/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i",
"/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-filter_complex",
"[0:v]scale=480x640,setsar=1[v0];[1:v]scale=480x640,setsar=1[v1];[2:v]scale=480x640,setsar=1[v2];[3:v]scale=480x640,setsar=1[v3];[v0][0:a][v1][1:a][v2][2:a][v3][3:a]concat=n=4:v=1:a=1",
"-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "480x640", "-vcodec", "libx264","-crf","27","-preset", "ultrafast", outputFile};