打开输出流 #0:0 的编码器时出现淡入淡出视频错误 - 可能参数不正确,例如 bit_rate、速率、宽度或高度
Fade Video-Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
我正在使用以下命令为我的视频添加淡入淡出效果
{"-y", "-ss", "" + startMs / 1000, "-t", "" + (endMs - startMs) / 1000, "-i", inputPath, "-acodec", "copy", "-vf", "fade=t=in:st=0:d=5,fade=t=out:st=" + String.valueOf((endMs - startMs) / 1000 - 5) + ":d=5", outputPath};
我收到以下错误-
"Failure3.3 5 .3gpffmpeg version n3.0.1 Copyright (c) 2000-2016 the
FFmpeg developers\n built with gcc 4.8 (GCC)\n 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=\n libavutil 55. 17.103 / 55. 17.103\n libavcodec 57. 24.102 / 57. 24.102\n libavformat 57. 25.100 /
57. 25.100\n libavdevice 57. 0.101 / 57. 0.101\n libavfilter 6. 31.100 / 6. 31.100\n libswscale 4. 0.100 / 4. 0.100\n libswresample 2. 0.101 / 2. 0.101\n libpostproc 54. 0.100 /
54. 0.100\nInput #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/VID_20180825_071734915.3gp':\n
Metadata:\n major_brand : 3gp4\n minor_version : 0\n
compatible_brands: isom3gp4\n creation_time : 2018-08-25
01:47:47\n com.android.version: 8.0.0\n Duration: 00:00:10.83,
start: 0.000000, bitrate: 17217 kb/s\n Stream #0:0(eng): Video:
h264 (High) (avc1 / 0x31637661), yuv420p(tv, unknown/bt470bg/unknown),
1920x1080, 16756 kb/s, SAR 1:1 DAR 16:9, 29.49 fps, 29.58 tbr, 90k
tbn, 180k tbc (default)\n Metadata:\n rotate : 90\n
creation_time : 2018-08-25 01:47:47\n handler_name :
VideoHandle\n Side data:\n displaymatrix: rotation of -90.00
degrees\n Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D),
48000 Hz, mono, fltp, 128 kb/s (default)\n Metadata:\n
creation_time : 2018-08-25 01:47:47\n handler_name :
SoundHandle\n[h263 @ 0xf49ff400] H.263 does not support resolutions
above 2048x1152\nOutput #0, 3gp, to
'/storage/emulated/0/Movies/fade_video.3gp':\n Metadata:\n
major_brand : 3gp4\n minor_version : 0\n
compatible_brands: isom3gp4\n com.android.version: 8.0.0\n
Stream #0:0(eng): Video: h263, none, q=2-31, 128 kb/s, SAR 1:1 DAR
0:0, 29.58 fps (default)\n Metadata:\n handler_name :
VideoHandle\n creation_time : 2018-08-25 01:47:47\n
encoder : Lavc57.24.102 h263\n Stream #0:1(eng): Audio: aac
(LC) (mp4a / 0x6134706D), 48000 Hz, mono, 128 kb/s (default)\n
Metadata:\n creation_time : 2018-08-25 01:47:47\n
handler_name : SoundHandle\nStream mapping:\n Stream #0:0 -> #0:0
(h264 (native) -> h263 (native))\n Stream #0:1 -> #0:1 (copy)\nError
while opening encoder for output stream #0:0 - maybe incorrect
parameters such as bit_rate, rate, width or height\n"
为什么在上面的命令中会导致这个错误?欢迎任何帮助。
如日志所述,H.263 不支持 2048x1152 以上的分辨率。您的源流是 1920x1080,但它旋转了 90 度,因此 ffmpeg 将它自动旋转到 1080x1920,这不符合限制。您可以在淡入淡出后添加缩放过滤器以有条件地缩小尺寸。
scale='if(lte(iw,2048)*lte(ih,1152),iw,if(gt(dar,2048/1152),2048,2*trunc(oh*dar/2)))':'if(lte(iw,2048)*lte(ih,1152),ih,if(gt(dar,2048/1152),2*trunc(ow/dar/2),1152))'
x 和 y 表达式所做的是首先检查输入是否大于 2048x1152。如果不是,保持原来的分辨率。如果是,检查输入的显示比例。如果大于 2048:1152,则将宽度缩小到 2048 并按比例调整高度,否则将高度缩小到 1152 并按比例调整宽度。 dar
代表显示宽高比。
我正在使用以下命令为我的视频添加淡入淡出效果
{"-y", "-ss", "" + startMs / 1000, "-t", "" + (endMs - startMs) / 1000, "-i", inputPath, "-acodec", "copy", "-vf", "fade=t=in:st=0:d=5,fade=t=out:st=" + String.valueOf((endMs - startMs) / 1000 - 5) + ":d=5", outputPath};
我收到以下错误-
"Failure3.3 5 .3gpffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers\n built with gcc 4.8 (GCC)\n 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=\n libavutil 55. 17.103 / 55. 17.103\n libavcodec 57. 24.102 / 57. 24.102\n libavformat 57. 25.100 / 57. 25.100\n libavdevice 57. 0.101 / 57. 0.101\n libavfilter 6. 31.100 / 6. 31.100\n libswscale 4. 0.100 / 4. 0.100\n libswresample 2. 0.101 / 2. 0.101\n libpostproc 54. 0.100 / 54. 0.100\nInput #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/VID_20180825_071734915.3gp':\n Metadata:\n major_brand : 3gp4\n minor_version : 0\n
compatible_brands: isom3gp4\n creation_time : 2018-08-25 01:47:47\n com.android.version: 8.0.0\n Duration: 00:00:10.83, start: 0.000000, bitrate: 17217 kb/s\n Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, unknown/bt470bg/unknown), 1920x1080, 16756 kb/s, SAR 1:1 DAR 16:9, 29.49 fps, 29.58 tbr, 90k tbn, 180k tbc (default)\n Metadata:\n rotate : 90\n
creation_time : 2018-08-25 01:47:47\n handler_name : VideoHandle\n Side data:\n displaymatrix: rotation of -90.00 degrees\n Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 128 kb/s (default)\n Metadata:\n
creation_time : 2018-08-25 01:47:47\n handler_name : SoundHandle\n[h263 @ 0xf49ff400] H.263 does not support resolutions above 2048x1152\nOutput #0, 3gp, to '/storage/emulated/0/Movies/fade_video.3gp':\n Metadata:\n
major_brand : 3gp4\n minor_version : 0\n
compatible_brands: isom3gp4\n com.android.version: 8.0.0\n
Stream #0:0(eng): Video: h263, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 29.58 fps (default)\n Metadata:\n handler_name : VideoHandle\n creation_time : 2018-08-25 01:47:47\n
encoder : Lavc57.24.102 h263\n Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, 128 kb/s (default)\n
Metadata:\n creation_time : 2018-08-25 01:47:47\n
handler_name : SoundHandle\nStream mapping:\n Stream #0:0 -> #0:0 (h264 (native) -> h263 (native))\n Stream #0:1 -> #0:1 (copy)\nError while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height\n"
为什么在上面的命令中会导致这个错误?欢迎任何帮助。
如日志所述,H.263 不支持 2048x1152 以上的分辨率。您的源流是 1920x1080,但它旋转了 90 度,因此 ffmpeg 将它自动旋转到 1080x1920,这不符合限制。您可以在淡入淡出后添加缩放过滤器以有条件地缩小尺寸。
scale='if(lte(iw,2048)*lte(ih,1152),iw,if(gt(dar,2048/1152),2048,2*trunc(oh*dar/2)))':'if(lte(iw,2048)*lte(ih,1152),ih,if(gt(dar,2048/1152),2*trunc(ow/dar/2),1152))'
x 和 y 表达式所做的是首先检查输入是否大于 2048x1152。如果不是,保持原来的分辨率。如果是,检查输入的显示比例。如果大于 2048:1152,则将宽度缩小到 2048 并按比例调整高度,否则将高度缩小到 1152 并按比例调整宽度。 dar
代表显示宽高比。