0
votes

I am using below command to add Fade In Fade Out effect to my video

{"-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};

I received below error-

"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"

Why is causing this error in above command?Any help will be welcome.

1
As the log says, H.263 does not support resolutions above 2048x1152. Your source stream is 1920x1080 but it's 90 deg rotated so ffmpeg is auto-rotating it to 1080x1920 which does not meet the limits. You can add a scale filter after the fade to downsize.Gyan
@Gyan Okay..so i want that if resolution is 2048x1152 or below it should not scale my video..but if its above than it should scale down my video..will adding scale='min(2048,iw)':'min(1152,ih)' meets my requirement and resolve my issue?Like-{"-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,scale='min(2048,iw)':'min(1152,ih)'", outputPath};varmashrivastava
scale='if(lte(iw,2048)*lte(ih,1152),iw,if(gt(dar,2048/1152),2048,oh*dar))':'if(lte(iw,2048)*lte(ih,1152),ih,if(gt(dar,2048/1152),ow/dar,1152))'Gyan
@Gyan Glad if you can post it as an answer with explanation so that i can understand properly and accept it as correct answer.What is "dar" in parameters?varmashrivastava

1 Answers

1
votes

As the log says, H.263 does not support resolutions above 2048x1152. Your source stream is 1920x1080 but it's 90 deg rotated so ffmpeg is auto-rotating it to 1080x1920 which does not meet the limits. You can add a scale filter after the fade to conditionally downsize.

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))'

What the x and y exprs do is first check if the input is greater than 2048x1152. If no, keep original resolution. If yes, check display ratio of input. If greater than 2048:1152, downsize width to 2048 and proportionally resize height, else downsize height to 1152 and proportionally resize width. dar stands for display aspect ratio.