I am using below command to add transitions effect between videos using overlays such that when one videos is about to finish, the overlay gets visible. Before showing overlays, I have to add padding and concatenate videos make one single video and then display overlays.:
ffmpeg
-i input1.mp4
-i input2.mp4
-i input3.mp4
-i transition1.mp4
-i transition2.mp4
-filter_complex
"[0:v]pad=width=1080:height=1920:x=(1080-iw)*0.5:y=(1920-ih)*0.5:color=black[video0];
[1:v]pad=width=1080:height=1920:x=(1080-iw)*0.5:y=(1920-ih)*0.5:color=black[video1];
[2:v]pad=width=1080:height=1920:x=(1080-iw)*0.5:y=(1920-ih)*0.5:color=black[video2];
[video0][video1][video2]concat=n=3:v=1:a=0[outv];
[3:v]colorkey=0x00d800:0.1[t0];
[t0]scale=w=1080:h=1920[tr0];
[4:v]colorkey=0x00d800:0.1[t1];
[t1]scale=w=1080:h=1920[tr1];
[outv][tr0]overlay=0:0:enable='between(t\,7\,9)'[out0];
[out0][tr1]overlay=0:0:enable='between(t\,12\,15)'[out1];
[0:a][1:a][2:a]concat=n=3:v=0:a=1[audio]"
-vsync 0 -c:v libx264 -pix_fmt yuv420p -map [out1] -map [audio] -preset ultrafast output.mp4
But above command does not show any overlay video. If I remove enable=between(t, start, end) from overlay parameters, all the overlay gets displayed at video start. I am very beginner to video editing and to FFMpeg. Can anybody guide me what I am doing wrong here?
Here is the log from console:
ffmpeg version v4.4-dev-416
I/mobile-ffmpeg: Copyright (c) 2000-2020 the FFmpeg developers
built with Android (6454773 based on r365631c2) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489587874b2a325e7a516b99d838599c6f) (based on LLVM 9.0.8svn)
configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --extra-libs='-L/home/taner/Projects/mobile-ffmpeg/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --target-os=android --enable-neon --enable-asm --enable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-static --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libshine --enable-libspeex --enable-libwavpack --enable-libkvazaar --enable-libx264 --enable-gpl --enable-libxvid --enable-gpl --enable-libx265 --enable-gpl --enable-libvidstab --enable-gpl --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libaom --enable-libtwolame --disable-sdl2 --enable-libvo-amrwbenc --enable-zlib --enable-mediacodec
libavutil 56. 55.100 / 56. 55.100
libavcodec 58. 96.100 / 58. 96.100
libavformat 58. 48.100 / 58. 48.100
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
I/mobile-ffmpeg: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input1.mp4':
Metadata:
major_brand :
mp42
minor_version :
0
compatible_brands:
isommp42
creation_time :
2020-08-12T17:21:49.000000Z
com.android.version:
9
Duration:
I/mobile-ffmpeg: 00:00:08.12
, start:
0.000000
, bitrate:
17298 kb/s
Stream #0:0
(eng)
: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 16309 kb/s
, SAR 1:1 DAR 16:9
,
28.70 fps,
29.50 tbr,
90k tbn,
60 tbc
(default)
Metadata:
rotate :
90
creation_time :
2020-08-12T17:21:49.000000Z
handler_name :
VideoHandle
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1
I/mobile-ffmpeg: (eng)
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
(default)
Metadata:
creation_time :
2020-08-12T17:21:49.000000Z
handler_name :
SoundHandle
I/mobile-ffmpeg: Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'input2.mp4':
Metadata:
major_brand :
isom
minor_version :
512
compatible_brands:
isomiso2avc1mp41
encoder :
Lavf57.25.100
I/mobile-ffmpeg: Duration:
00:00:05.97
, start:
0.000000
, bitrate:
770 kb/s
Stream #1:0
(und)
: Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 128 kb/s
(default)
Metadata:
handler_name :
SoundHandler
Stream #1:1
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 368x480, 608 kb/s
,
27.29 fps,
I/mobile-ffmpeg: 120 tbr,
12k tbn,
60 tbc
(default)
Metadata:
handler_name :
VideoHandler
I/mobile-ffmpeg: Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'input3.mp4':
Metadata:
major_brand :
isom
minor_version :
512
compatible_brands:
isomiso2avc1mp41
I/mobile-ffmpeg: encoder :
Lavf55.19.104
Duration:
00:00:13.05
, start:
0.000000
, bitrate:
2453 kb/s
Chapter #2:0:
start 0.000000,
end 13.033000
Metadata:
title :
Stream #2:0
(und)
: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
(default)
I/mobile-ffmpeg: Metadata:
handler_name :
SoundHandler
Stream #2:1
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 640x480, 2320 kb/s
,
25 fps,
25 tbr,
1200k tbn,
50 tbc
(default)
Metadata:
handler_name :
VideoHandler
Stream #2:2
(eng)
: Data: bin_data (text / 0x74786574), 0 kb/s
I/mobile-ffmpeg: Metadata:
handler_name :
SubtitleHandler
I/mobile-ffmpeg: Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'transition1.mp4':
Metadata:
major_brand :
mp42
minor_version :
0
I/mobile-ffmpeg: compatible_brands:
mp41isom
creation_time :
2020-08-17T09:24:04.000000Z
Duration:
00:00:02.22
, start:
0.000000
, bitrate:
2445 kb/s
Stream #3:0
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2414 kb/s
,
30 fps,
30 tbr,
30k tbn,
60 tbc
(default)
I/mobile-ffmpeg: Metadata:
creation_time :
2020-08-17T09:24:04.000000Z
handler_name :
VideoHandler
encoder :
AVC Coding
Stream #3:1
(und)
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 79 kb/s
(default)
Metadata:
creation_time :
I/mobile-ffmpeg: 2020-08-17T09:24:04.000000Z
handler_name :
I/mobile-ffmpeg: SoundHandler
I/mobile-ffmpeg: Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'transition2.mp4':
Metadata:
major_brand :
mp42
minor_version :
0
compatible_brands:
mp41isom
creation_time :
2020-08-17T09:21:33.000000Z
Duration:
00:00:02.22
, start:
0.000000
, bitrate:
2331 kb/s
I/mobile-ffmpeg: Stream #4:0
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2298 kb/s
,
30 fps,
30 tbr,
30k tbn,
60 tbc
(default)
Metadata:
creation_time :
2020-08-17T09:21:33.000000Z
handler_name :
VideoHandler
encoder :
AVC Coding
Stream #4:1
(und)
I/mobile-ffmpeg: : Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 79 kb/s
(default)
Metadata:
creation_time :
2020-08-17T09:21:33.000000Z
handler_name :
SoundHandler
I/mobile-ffmpeg: Stream mapping:
Stream #0:0 (h264) -> pad
Stream #0:1 (aac) -> concat:in0:a0
Stream #1:0 (aac) -> concat:in1:a0
Stream #1:1 (h264) -> pad
Stream #2:0 (aac) -> concat:in2:a0
Stream #2:1 (h264) -> pad
Stream #3:0 (h264) -> colorkey
Stream #4:0 (h264) -> colorkey
I/mobile-ffmpeg: overlay
-> Stream #0:0 (libx264)
concat
-> Stream #0:1 (aac)
Press [q] to stop, [?] for help
W/mobile-ffmpeg: [graph 0 input from stream 0:0 # 0x73485c3fc0] sws_param option is deprecated and ignored
[graph 0 input from stream 1:1 # 0x73485c4140] sws_param option is deprecated and ignored
[graph 0 input from stream 2:1 # 0x73485c4200] sws_param option is deprecated and ignored
[graph 0 input from stream 3:0 # 0x73485c42c0] sws_param option is deprecated and ignored
W/mobile-ffmpeg: [graph 0 input from stream 4:0 # 0x73485c4380] sws_param option is deprecated and ignored
W/mobile-ffmpeg: [swscaler # 0x7324db9000] No accelerated colorspace conversion found from yuv420p to argb.
W/mobile-ffmpeg: [swscaler # 0x7324876000] No accelerated colorspace conversion found from yuv420p to argb.
I/mobile-ffmpeg: [libx264 # 0x7332f9a500] using SAR=1/1
W/mobile-ffmpeg: [libx264 # 0x7332f9a500] MB rate (8160000000) > level limit (16711680)
I/mobile-ffmpeg: [libx264 # 0x7332f9a500] using cpu capabilities: ARMv8 NEON
I/mobile-ffmpeg: [libx264 # 0x7332f9a500] profile Constrained Baseline, level 6.2, 4:2:0, 8-bit
[libx264 # 0x7332f9a500] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
I/mobile-ffmpeg: Output #0, mp4, to 'output.mp4':
Metadata:
I/mobile-ffmpeg: major_brand :
mp42
minor_version :
0
compatible_brands:
isommp42
com.android.version:
9
encoder :
Lavf58.48.100
Chapter #0:0:
start 0.000000,
end 13.033000
Metadata:
title :
Stream #0:0
I/mobile-ffmpeg: : Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1
,
1000k tbn,
1000k tbc
(default)
Metadata:
encoder :
Lavc58.96.100 libx264
Side data:
cpb:
bitrate max/min/avg: 0/0/0 buffer size: 0
vbv_delay: N/A
Stream #0:1
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
(default)
Metadata:
I/mobile-ffmpeg: encoder :
Lavc58.96.100 aac
E/Progress: Progress: 3.6918316
D/mobile-ffmpeg: Progress: frame: 1, time: 1002, Pct: 0.036918
I/mobile-ffmpeg: frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:01.00 bitrate= 0.5kbits/s speed=1.13x
The overlay filter syncs both inputs by timestamps, so that second X of the overlay video is printed on top of second X of the main video. So, with a arg of overlay=0:0:enable='between(t\,7\,9)', ffmpeg will start by aiming to overlay overlay frame with timestamp 7.00 on top of main video with timestamp 7.00. If the overlay video is not that long, there won't be any effect.
The overlay video timestamps need to be modified to create the required sync.
[3:v]colorkey=0x00d800:0.1,scale=w=1080:h=1920,setpts=PTS-STARTPTS+7/TB[tr0];
The setpts shifts the first transition stream to start with timestamp 7. This can now be overlaid with enable='between(t\,7\,9)'.
Related
I'm stuck with merging multiple videos with audio. This used to work on most videos I merged before but with some videos, I get the "More than 1000 frames duplicated" warning, and the output video is broken (some videos won't play, just static picture and the sound is misaligned).
All videos are in the same format afaik. The only difference I see is that some are "yuvj420p(pc)" and most are "yuv420p". But I tried merging without those with "yuvj420p(pc)" and it didn't help.
Already tried adding "-vsync vfr", didn't help too.
Interestingly — if I remove the second or the last input video, no warning is given and it all works.
The command I use:
ffmpeg -i intro.mp4 \
-i 2043651222.mp4 \
-i 2668231460.mp4 \
-i 2342967217.mp4 \
-i 2345792509.mp4 \
-i 2764881879.mp4 \
-i 3127825310.mp4 \
-i 3058954129.mp4 \
-i 2533841315.mp4 \
-i 2334544474.mp4 \
-i 2493440007.mp4 \
-filter_complex \
"[0][1]xfade=transition=fade:duration=0.5:offset=3.5000000[V01]; \
[V01][2]xfade=transition=fade:duration=0.5:offset=7.67000[V02]; \
[V02][3]xfade=transition=fade:duration=0.5:offset=27.21000[V03]; \
[V03][4]xfade=transition=fade:duration=0.5:offset=37.01000[V04]; \
[V04][5]xfade=transition=fade:duration=0.5:offset=54.11000[V05]; \
[V05][6]xfade=transition=fade:duration=0.5:offset=56.63000[V06]; \
[V06][7]xfade=transition=fade:duration=0.5:offset=80.49000[V07]; \
[V07][8]xfade=transition=fade:duration=0.5:offset=107.23000[V08]; \
[V08][9]xfade=transition=fade:duration=0.5:offset=110.12000[V09]; \
[V09][10]xfade=transition=fade:duration=0.5:offset=118.31000,format=yuv420p[video]; \
[0:a]aresample=async=1:first_pts=0,apad,atrim=0:4[A0]; \
[1:a]aresample=async=1:first_pts=0,apad,atrim=0:4.67[A1]; \
[2:a]aresample=async=1:first_pts=0,apad,atrim=0:20.04[A2]; \
[3:a]aresample=async=1:first_pts=0,apad,atrim=0:10.3[A3]; \
[4:a]aresample=async=1:first_pts=0,apad,atrim=0:17.6[A4]; \
[5:a]aresample=async=1:first_pts=0,apad,atrim=0:3.02[A5]; \
[6:a]aresample=async=1:first_pts=0,apad,atrim=0:24.36[A6]; \
[7:a]aresample=async=1:first_pts=0,apad,atrim=0:27.24[A7]; \
[8:a]aresample=async=1:first_pts=0,apad,atrim=0:3.39[A8]; \
[9:a]aresample=async=1:first_pts=0,apad,atrim=0:8.69[A9]; \
[10:a]aresample=async=1:first_pts=0,apad,atrim=0:14.88[A10]; \
[A0][A1]acrossfade=d=0.5:c1=tri:c2=tri[A0001]; \
[A0001][A2]acrossfade=d=0.5:c1=tri:c2=tri[A0002]; \
[A0002][A3]acrossfade=d=0.5:c1=tri:c2=tri[A0003]; \
[A0003][A4]acrossfade=d=0.5:c1=tri:c2=tri[A0004]; \
[A0004][A5]acrossfade=d=0.5:c1=tri:c2=tri[A0005]; \
[A0005][A6]acrossfade=d=0.5:c1=tri:c2=tri[A0006]; \
[A0006][A7]acrossfade=d=0.5:c1=tri:c2=tri[A0007]; \
[A0007][A8]acrossfade=d=0.5:c1=tri:c2=tri[A0008]; \
[A0008][A9]acrossfade=d=0.5:c1=tri:c2=tri[A0009]; \
[A0009][A10]acrossfade=d=0.5:c1=tri:c2=tri[audio] \
" -map "[video]" -map "[audio]" -movflags +faststart 'compiled.mp4'
Full log:
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.62)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'intro.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:00:04.00, start: 0.000000, bitrate: 98 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 85 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2043651222.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:04.67, start: 0.000000, bitrate: 471 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 720x1280 [SAR 1:1 DAR 9:16], 333 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '2668231460.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:20.04, start: 0.000000, bitrate: 1882 kb/s
Stream #2:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 720x1280, 1685 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 191 kb/s (default)
Metadata:
handler_name : Core Media Audio
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '2342967217.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:10.30, start: 0.000000, bitrate: 446 kb/s
Stream #3:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 367 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from '2345792509.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:17.60, start: 0.000000, bitrate: 2546 kb/s
Stream #4:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 720x1280, 2342 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #4:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 199 kb/s (default)
Metadata:
handler_name : Core Media Audio
Input #5, mov,mp4,m4a,3gp,3g2,mj2, from '2764881879.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:03.02, start: 0.000000, bitrate: 1293 kb/s
Stream #5:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 720x1280, 1110 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #5:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 178 kb/s (default)
Metadata:
handler_name : Core Media Audio
Input #6, mov,mp4,m4a,3gp,3g2,mj2, from '3127825310.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:24.36, start: 0.000000, bitrate: 401 kb/s
Stream #6:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 323 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #6:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #7, mov,mp4,m4a,3gp,3g2,mj2, from '3058954129.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:27.24, start: 0.000000, bitrate: 1723 kb/s
Stream #7:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 720x1280, 1519 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #7:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 194 kb/s (default)
Metadata:
handler_name : Core Media Audio
Input #8, mov,mp4,m4a,3gp,3g2,mj2, from '2533841315.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:03.39, start: 0.000000, bitrate: 1807 kb/s
Stream #8:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 720x1280, 1657 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #8:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 150 kb/s (default)
Metadata:
handler_name : Core Media Audio
Input #9, mov,mp4,m4a,3gp,3g2,mj2, from '2334544474.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:08.69, start: 0.000000, bitrate: 2675 kb/s
Stream #9:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 720x1280, 2500 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #9:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 180 kb/s (default)
Metadata:
handler_name : Core Media Audio
Input #10, mov,mp4,m4a,3gp,3g2,mj2, from '2493440007.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:14.88, start: 0.000000, bitrate: 966 kb/s
Stream #10:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280, 889 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : Core Media Video
Stream #10:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
Metadata:
handler_name : Core Media Audio
File 'compiled.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 (aac) -> aresample
Stream #0:1 (h264) -> xfade:main
Stream #1:0 (h264) -> xfade:xfade
Stream #1:1 (aac) -> aresample
Stream #2:0 (h264) -> xfade:xfade
Stream #2:1 (aac) -> aresample
Stream #3:0 (h264) -> xfade:xfade
Stream #3:1 (aac) -> aresample
Stream #4:0 (h264) -> xfade:xfade
Stream #4:1 (aac) -> aresample
Stream #5:0 (h264) -> xfade:xfade
Stream #5:1 (aac) -> aresample
Stream #6:0 (h264) -> xfade:xfade
Stream #6:1 (aac) -> aresample
Stream #7:0 (h264) -> xfade:xfade
Stream #7:1 (aac) -> aresample
Stream #8:0 (h264) -> xfade:xfade
Stream #8:1 (aac) -> aresample
Stream #9:0 (h264) -> xfade:xfade
Stream #9:1 (aac) -> aresample
Stream #10:0 (h264) -> xfade:xfade
Stream #10:1 (aac) -> aresample
format -> Stream #0:0 (libx264)
acrossfade -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[swscaler # 0x7ff21ef72000] deprecated pixel format used, make sure you did set range correctly
[libx264 # 0x7ff227827800] using SAR=1/1
[libx264 # 0x7ff227827800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x7ff227827800] profile High, level 3.1, 4:2:0, 8-bit
[libx264 # 0x7ff227827800] 264 - core 160 r3011M cde9a93 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'compiled.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 720x1280 [SAR 1:1 DAR 9:16], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
encoder : Lavc58.91.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.91.100 aac
More than 1000 frames duplicated 1024kB time=00:00:47.41 bitrate= 176.9kbits/s dup=597 drop=996 speed=5.81x
[mp4 # 0x7ff227815200] Starting second pass: moving the moov atom to the beginning of the filep=1954 speed=4.07x
frame= 3989 fps=121 q=-1.0 Lsize= 13252kB time=00:02:12.98 bitrate= 816.3kbits/s dup=1946 drop=1954 speed=4.05x
video:11094kB audio:2036kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.927680%
[libx264 # 0x7ff227827800] frame I:23 Avg QP:14.09 size: 69236
[libx264 # 0x7ff227827800] frame P:1195 Avg QP:18.60 size: 6527
[libx264 # 0x7ff227827800] frame B:2771 Avg QP:21.69 size: 710
[libx264 # 0x7ff227827800] consecutive B-frames: 3.3% 11.5% 2.6% 82.6%
[libx264 # 0x7ff227827800] mb I I16..4: 36.4% 41.9% 21.7%
[libx264 # 0x7ff227827800] mb P I16..4: 3.1% 6.0% 1.1% P16..4: 15.4% 5.5% 2.9% 0.0% 0.0% skip:66.0%
[libx264 # 0x7ff227827800] mb B I16..4: 0.1% 0.1% 0.0% B16..8: 10.2% 0.6% 0.0% direct: 0.4% skip:88.5% L0:42.8% L1:53.3% BI: 3.8%
[libx264 # 0x7ff227827800] 8x8 transform intra:55.8% inter:63.6%
[libx264 # 0x7ff227827800] coded y,uvDC,uvAC intra: 25.6% 42.8% 14.5% inter: 2.7% 2.5% 0.0%
[libx264 # 0x7ff227827800] i16 v,h,dc,p: 45% 22% 14% 19%
[libx264 # 0x7ff227827800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 38% 19% 28% 3% 2% 3% 2% 3% 2%
[libx264 # 0x7ff227827800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 17% 15% 6% 7% 8% 5% 6% 4%
[libx264 # 0x7ff227827800] i8c dc,h,v,p: 55% 15% 23% 7%
[libx264 # 0x7ff227827800] Weighted P-Frames: Y:2.0% UV:1.7%
[libx264 # 0x7ff227827800] ref P L0: 68.4% 13.3% 14.4% 3.9% 0.1%
[libx264 # 0x7ff227827800] ref B L0: 86.0% 12.0% 2.1%
[libx264 # 0x7ff227827800] ref B L1: 96.9% 3.1%
[libx264 # 0x7ff227827800] kb/s:683.43
[aac # 0x7ff22781fc00] Qavg: 2168.180
I think I know why this is happening. I also got the same error when trying to merge 11 files using the xfade filter.
I used ffprobe to get the length of the video like this:
ffprobe -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries format=duration video.MP4
and got: 9.003000. So I set offset=8.003.
In fact, the duration of the video stream should be defined as follows:
ffprobe -v quiet -select_streams v:0 -print_format compact=print_section=0:nokey=1:escape=csv -show_entries stream=duration video.MP4
then got: 8.000000. And I had to set offset=7.
Because audio and video durations often differ:
ffprobe -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries stream=duration video.MP4
gave this: 8.000000 9.002667
If the duration differs by more than one second, then the process is interrupted (for duration =1) due to the fact that offset exceeds the duration of the video stream.
I am trying to concatenate 3 videos of different resolutions and overlaying 2 videos as transition effects(though the chroma key color removal is not yet implemented) between videos using below command:
ffmpeg
-i input1.mp4
-i input2.mp4
-i input3.mp4
-i transition1.mp4
-i transition2.mp4
-filter_complex
"[0:v]pad=width=1080:height=1920:x=(1080-iw)*0.5:y=(1920-ih)*0.5:color=black[video0];
[1:v]pad=width=1080:height=1920:x=(1080-iw)*0.5:y=(1920-ih)*0.5:color=black[video1];
[2:v]pad=width=1080:height=1920:x=(1080-iw)*0.5:y=(1920-ih)*0.5:color=black[video2];
[video0][video1][video2]concat=n=3:v=1:a=0[outv];
[3:v]scale=w=1080:h=1920[t0];
[4:v]scale=w=1080:h=1920[t1];
[outv][t0]overlay=enable='between(t,6.6045,9.6335)'[out0];
[out0][t1]overlay=enable='between(t,12.5655,15.6165)'[out1];
[0:a][1:a][2:a]concat=n=3:v=0:a=1[audio]"
-c:v libx264 -pix_fmt yuv420p -map [out1] -map [audio] -preset ultrafast output.mp4
I get success only with few videos. Most of the times the command execution never stops. It keeps on appending something to the output video file even for hours. Here is the output from console:
ffmpeg version v4.4-dev-416
Copyright (c) 2000-2020 the FFmpeg developers
built with Android (6454773 based on r365631c2) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489587874b2a325e7a516b99d838599c6f) (based on LLVM 9.0.8svn)
configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --extra-libs='-L/home/taner/Projects/mobile-ffmpeg/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --target-os=android --enable-neon --enable-asm --enable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-static --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libshine --enable-libspeex --enable-libwavpack --enable-libkvazaar --enable-libx264 --enable-gpl --enable-libxvid --enable-gpl --enable-libx265 --enable-gpl --enable-libvidstab --enable-gpl --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libaom --enable-libtwolame --disable-sdl2 --enable-libvo-amrwbenc --enable-zlib --enable-mediacodec
libavutil 56. 55.100 / 56. 55.100
libavcodec 58. 96.100 / 58. 96.100
libavformat 58. 48.100 / 58. 48.100
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input1.mp4':
Metadata:
major_brand :
mp42
minor_version :
0
compatible_brands:
isommp42
creation_time :
2020-08-12T17:21:49.000000Z
com.android.version:
9
Duration:
00:00:08.12
, start:
0.000000
, bitrate:
17298 kb/s
Stream #0:0
(eng)
: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 16309 kb/s
, SAR 1:1 DAR 16:9
,
28.70 fps,
29.50 tbr,
90k tbn,
60 tbc
(default)
Metadata:
rotate :
90
creation_time :
handler_name :
VideoHandle
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1
(eng)
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
(default)
Metadata:
creation_time :
2020-08-12T17:21:49.000000Z
handler_name :
SoundHandle
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'input2.mp4':
Metadata:
major_brand :
isom
minor_version :
512
compatible_brands:
isomiso2avc1mp41
encoder :
Lavf57.25.100
Duration:
00:00:05.97
, start:
0.000000
, bitrate:
770 kb/s
Stream #1:0
(und)
: Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 128 kb/s
(default)
Metadata:
handler_name :
SoundHandler
Stream #1:1
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 368x480, 608 kb/s
,
27.29 fps,
120 tbr,
12k tbn,
60 tbc
(default)
Metadata:
handler_name :
VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'input3.mp4':
Metadata:
major_brand :
isom
minor_version :
512
compatible_brands:
isomiso2avc1mp41
encoder :
Lavf55.19.104
Duration:
00:00:13.05
, start:
0.000000
, bitrate:
2453 kb/s
Chapter #2:0:
start 0.000000,
end 13.033000
Metadata:
title :
Stream #2:0
(und)
: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
(default)
Metadata:
handler_name :
SoundHandler
Stream #2:1
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 640x480, 2320 kb/s
,
25 fps,
25 tbr,
1200k tbn,
50 tbc
(default)
Metadata:
handler_name :
VideoHandler
Stream #2:2
(eng)
: Data: bin_data (text / 0x74786574), 0 kb/s
Metadata:
handler_name :
SubtitleHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'transition1.mp4':
Metadata:
major_brand :
mp42
minor_version :
0
compatible_brands:
mp41isom
creation_time :
2020-08-17T09:31:23.000000Z
Duration:
00:00:03.03
, start:
0.000000
, bitrate:
6263 kb/s
Stream #3:0
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 6307 kb/s
,
30 fps,
30 tbr,
30k tbn,
60 tbc
(default)
Metadata:
creation_time :
handler_name :
VideoHandler
encoder :
AVC Coding
Stream #3:1
(und)
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 79 kb/s
(default)
Metadata:
creation_time :
2020-08-17T09:31:23.000000Z
handler_name :
SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'transition2.mp4':
Metadata:
major_brand :
mp42
minor_version : 0
compatible_brands:
mp41isom
creation_time :
2020-08-17T09:30:33.000000Z
Duration:
00:00:03.05
, start:
0.000000
, bitrate:
7828 kb/s
Stream #4:0
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 7873 kb/s
,
30 fps,
30 tbr,
30k tbn,
60 tbc
(default)
Metadata:
creation_time :
2020-08-17T09:30:33.000000Z
handler_name :
VideoHandler
encoder :
AVC Coding
Stream #4:1
(und)
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 79 kb/s
(default)
Metadata:
creation_time :
2020-08-17T09:30:33.000000Z
handler_name :
SoundHandler
Stream mapping:
Stream #0:0 (h264) -> pad
Stream #0:1 (aac) -> concat:in0:a0
Stream #1:0 (aac) -> concat:in1:a0
Stream #1:1 (h264) -> pad
Stream #2:0 (aac) -> concat:in2:a0
Stream #2:1 (h264) -> pad
Stream #3:0 (h264) -> scale
Stream #4:0 (h264) -> scale
overlay
-> Stream #0:0 (libx264)
concat
-> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 # 0x733a19a900] sws_param option is deprecated and ignored
[graph 0 input from stream 1:1 # 0x733a19aa80] sws_param option is deprecated and ignored
[graph 0 input from stream 2:1 # 0x733a19ab40] sws_param option is deprecated and ignored
[graph 0 input from stream 3:0 # 0x733a19ac00] sws_param option is deprecated and ignored
[graph 0 input from stream 4:0 # 0x733a19acc0] sws_param option is deprecated and ignored
[mp4 # 0x733a679400] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
[libx264 # 0x733a1b0600] using SAR=1/1
[libx264 # 0x733a1b0600] MB rate (8160000000) > level limit (16711680)
[libx264 # 0x733a1b0600] using cpu capabilities: ARMv8 NEON
[libx264 # 0x733a1b0600] profile Constrained Baseline, level 6.2, 4:2:0, 8-bit
[libx264 # 0x733a1b0600] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'output.mp4':
Metadata:
major_brand :
mp42
minor_version :
0
compatible_brands:
isommp42
com.android.version:
9
encoder :
Lavf58.48.100
Chapter #0:0:
start 0.000000,
end 13.033000
Metadata:
title :
Stream #0:0
: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1
,
1000k tbn,
1000k tbc
(default)
Metadata:
encoder :
Lavc58.96.100 libx264
Side data:
cpb:
bitrate max/min/avg: 0/0/0 buffer size: 0
vbv_delay: N/A
Stream #0:1
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
(default)
Metadata:
encoder :
Lavc58.96.100 aac
E/Progress: Progress: 3.6918316
D/mobile-ffmpeg: Progress: frame: 1, time: 1002, Pct: 0.036918
frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:01.00 bitrate= 0.5kbits/s speed=1.79x
More than 1000 frames duplicated
I even tried command without overlay and audio parts but result was same. I am working on Android app and using below ffmpeg wrapper library:
https://github.com/tanersener/mobile-ffmpeg
The concat filter can reset the frame rate of the output video stream to the stream time base. This can cause mass frame duplication, which will slow down ffmpeg a lot, making it look like ffmpeg is stuck.
Add -vsync 0 to prevent frame duplication.
I use ffmpeg to do frame decimation, millions of video
I have to use nvidia gpu card (tesla P4) to optimize performance
my ffmpeg command is
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i ./a.mp4 -c:v nvenc -vf "scale_npp=format=yuv444p" -r 1 ./\%08d.raw
but the output data format is weird, I don't know what the format is and how to decode it
I want to know how to decode these data or how to output ream rawdata, can anybody help me?
Log:
built with gcc 8.2.0 (GCC)
configuration: --cc=/opt/compiler/gcc-8.2/bin/gcc --disable-x86asm --enable-cuda --enable-cuvid --enable-nvenc --enable-nvdec --enable-nonfree --enable-libnpp --enable-libx264 --enable-gpl --enable-debug=3 --disable-optimizations --disable-stripping --extra-cflags='-I/home/work/cuda-10.0/include -g3' --extra-ldflags=-L/home/work/cuda-10.0/lib64 --prefix=/home/work/ffmpeg
libavutil 56. 36.101 / 56. 36.101
libavcodec 58. 65.100 / 58. 65.10
libavformat 58. 35.101 / 58. 35.101
libavdevice 58. 9.101 / 58. 9.101
libavfilter 7. 69.101 / 7. 69.101
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './a.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Duration: 00:50:41.28, start: 0.000000, bitrate: 862 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 >[SAR 1:1 DAR 16:9], 825 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 29 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> h264 (nvenc))
Stream #0:1 -> #1:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #1, wav, to './audio.wav':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
ISFT : Lavf58.35.101
Stream #1:0(eng): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, mono, s16, 256 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.65.100 pcm_s16le
[nvenc # 0x44bbc40] This encoder is deprecated, use 'h264_nvenc' instead
Output #0, image2, to './%08d.raw':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.35.101
Stream #0:0(eng): Video: h264 (nvenc) (High 4:4:4 Predictive), cuda, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 2000 kb/s, 1 fps, 1 tbn, 1 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.65.100 nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: N/A
frame= 3043 fps= 52 q=4.0 Lsize=N/A time=00:50:43.00 bitrate=N/A dup=0 drop=72984 speed=52.3x
video:245435kB audio:6250kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
I have 5 mp4 input videos (audio+video) that I want to 'join' into a single output video with a crossfade effect in between each pair of videos.
I want to 'crossfade' both the audio and the video, with a transition of 0.4s.
(Not an actual crossfade, more like video-2 fades in over video-1, video-1 does not need to fade out, but this is not the problem)
I'm using ffmpeg-4.1.3-win64-static
I have followed many tutorials and answers from here, but there are so many different ways to do it...
Each one of the 5 videos is 1.024s long, duration obtained with ffprobe
ffprobe.exe -i "0.mp4" -show_entries format=duration -v quiet -of csv="p=0"
This is the command for both audio and video:
(I've reformatted the command so it is easier to read, it is issued as a single line in the command prompt)
ffmpeg.exe -y -i "0.mp4" -i "1.mp4" -i "2.mp4" -i "3.mp4" -i "4.mp4"
-filter_complex "
[0:v]setpts=PTS-STARTPTS[v1];
[1:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(0.6/TB)[v2];
[2:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(1.2/TB)[v3];
[3:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(1.8/TB)[v4];
[4:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(2.4/TB)[v5];
[v1][v2]overlay[u1];[u1][v3]overlay[u2];[u2][v4]overlay[u3];[u3][v5]overlay,format=yuv420p[v];
[0][1]acrossfade=d=0.4[a0];
[a0][2]acrossfade=d=0.4[a1];
[a1][3]acrossfade=d=0.4[a2];
[a2][4]acrossfade=d=0.4[a]
" -map [v] -map [a] "output.mp4"
When I do both audio and video into a single output file, output.mp4 can not be played on VLC, this is the vlc log:
main debug: `file:///C:/project/input-videos/output.mp4' gives access `file' demux `any' path `/C:project/input-videos/output.mp4'
main debug: creating demux: access='file' demux='any' location='/C:/project/input-videos/output.mp4' file='C:\project\input-videos\output.mp4'
main debug: looking for access_demux module matching "file": 15 candidates
main debug: no access_demux modules matched
main debug: creating access: file:///C:/project/input-videos/output.mp4
main debug: (path: C:\project\input-videos\output.mp4)
main debug: looking for access module matching "file": 26 candidates
main debug: using access module "filesystem"
main debug: looking for stream_filter module matching "prefetch,cache_read": 24 candidates
cache_read debug: Using stream method for AStream*
cache_read debug: starting pre-buffering
cache_read error: cannot pre fill buffer
main debug: looking for meta fetcher module matching "any": 1 candidates
main debug: no stream_filter modules matched
main warning: cannot insert stream filter prefetch,cache_read
main debug: looking for stream_filter module matching "any": 24 candidates
playlist debug: not enough data
...
This is the output from ffmpeg:
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.3.1 (GCC) 20190414
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '0.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
location-eng : +52.6899-001.8293/
location : +52.6899-001.8293/
Duration: 00:00:01.02, start: 0.000000, bitrate: 13821 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2224x1080 [SAR 1:1 DAR 278:135], 14002 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandle
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
location-eng : +53.4256-001.3580/
location : +53.4256-001.3580/
Duration: 00:00:01.02, start: 0.000000, bitrate: 7094 kb/s
Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2224x1080 [SAR 1:1 DAR 278:135], 7113 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandle
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
location-eng : +53.3927-001.5044/
location : +53.3927-001.5044/
Duration: 00:00:01.02, start: 0.000000, bitrate: 7367 kb/s
Stream #2:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2224x1080 [SAR 1:1 DAR 278:135], 7394 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Metadata:
handler_name : SoundHandle
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
location-eng : +53.3927-001.5044/
location : +53.3927-001.5044/
Duration: 00:00:01.02, start: 0.000000, bitrate: 8145 kb/s
Stream #3:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2224x1080 [SAR 1:1 DAR 278:135], 8192 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandle
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from '4.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
location-eng : +53.3927-001.5044/
location : +53.3927-001.5044/
Duration: 00:00:01.02, start: 0.000000, bitrate: 6241 kb/s
Stream #4:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2224x1080 [SAR 1:1 DAR 278:135], 6241 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #4:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Metadata:
handler_name : SoundHandle
Stream mapping:
Stream #0:0 (h264) -> setpts
Stream #0:1 (aac) -> acrossfade:crossfade0
Stream #1:0 (h264) -> format
Stream #1:1 (aac) -> acrossfade:crossfade1
Stream #2:0 (h264) -> format
Stream #2:1 (aac) -> acrossfade:crossfade1
Stream #3:0 (h264) -> format
Stream #3:1 (aac) -> acrossfade:crossfade1
Stream #4:0 (h264) -> format
Stream #4:1 (aac) -> acrossfade:crossfade1
format -> Stream #0:0 (libx264)
acrossfade -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
When I do the video only it is fine. The duration of the output.mp4 file generated for video-only is 3.4s
When I do the audio only it is also fine. The duration of the output.mp4 file generated for audio-only is 3.435s
This is the command for video only:
ffmpeg.exe -y -i "0.mp4" -i "1.mp4" -i "2.mp4" -i "3.mp4" -i "4.mp4"
-filter_complex "
[0:v]setpts=PTS-STARTPTS[v1];
[1:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(0.6/TB)[v2];
[2:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(1.2/TB)[v3];
[3:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(1.8/TB)[v4];
[4:v]format=yuva420p,fade=in:st=0:d=0.4:alpha=1,setpts=PTS-STARTPTS+(2.4/TB)[v5];
[v1][v2]overlay[u1];[u1][v3]overlay[u2];[u2][v4]overlay[u3];[u3][v5]overlay,format=yuv420p[v]
" -map [v] "output.mp4"
This is the command for audio only:
ffmpeg.exe -y -i "0.mp4" -i "1.mp4" -i "2.mp4" -i "3.mp4" -i "4.mp4"
-filter_complex "
[0][1]acrossfade=d=0.4[a0];
[a0][2]acrossfade=d=0.4[a1];
[a1][3]acrossfade=d=0.4[a2];
[a2][4]acrossfade=d=0.4[a]
" -map [a] "output.mp4"
What am I missing in order to generate one output file with both audio and video content?
Edit: Here's the full ffmpeg command + result for audio and video combined with "-loglevel debug" added. (Too big to add directly here, so I've added it to Pastebin)
https://pastebin.com/NLBc7Abb
Work Around
Not a solution, but I found a work around:
Create video only output using command above, output to video.mp4
Create audio only output using command above, output to audio.mp4
Merge both video.mp4 and audio.mp4 into output.mp4 using the following command:
ffmpeg.exe -y -i "video.mp4" -i "audio.mp4" -c:v copy -c:a aac output.mp4
If anyone has any ideas as to why the combined audio+video command does not work, please let me know. :)
I have two input videos that I am concatenating using the FFmpeg concat demuxer:
ffmpeg -f concat safe '0' -i /path/to/file.txt -c copy /path/to/output.mp4
The file.txt contains the two file paths as follows:
ffconcat version 1.0
file /path/to/input/file1.mp4
file /path/to/input/file2.mp4
Unfortunately, the concatenated video has two issues:
The duration of the first input video is 4 seconds. In the output video, the last frame freezes for several seconds before the second input video starts.
The playback speed of the second input video is slowed down so that instead of being 7 seconds long, the video plays for around 14 or 15 seconds.
I have tried specifying the duration of each video in the .txt file, as specified by the FFmpeg docs, but this doesn't seem to make a difference to the output.
I'm a bit of a newbie to FFmpeg, so any help is greatly appreciated!
Edit - The properties of each input video as given by FFprobe:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tmp/video/16382802.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Duration: 00:00:04.43, start: 0.000000, bitrate: 644 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 360x640, 640 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tmp/video/16382805.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Duration: 00:00:07.31, start: 0.023220, bitrate: 836 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 360x640, 669 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, 5.1, fltp, 158 kb/s (default)
Metadata:
handler_name : SoundHandler
Edit 2 - Stack trace when rewrapping the video (audio is lost):
ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.31)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-ffplay --enable-libfdk-aac --enable-frei0r --enable-nonfree --enable-vda
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
libavresample 3. 0. 0 / 3. 0. 0
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 'https://s3-eu-west-1.amazonaws.com/stories.snaplytics.io/fTYbaN78DBVEQI0js0ydhNw/d3ef9a13-454c-4015-8412-cbd890e70e24.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Duration: 00:00:07.31, start: 0.023220, bitrate: 746 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 360x640, 669 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 67 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, lavfi, from 'anullsrc':
Duration: N/A, start: 0.000000, bitrate: 705 kb/s
Stream #1:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
Output #0, mp4, to '/Users/barnabytaylor/Documents/fanbytes-dashboard/tmp/video/16382805.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 360x640, q=2-31, 669 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, 5.1, fltp, 341 kb/s
Metadata:
encoder : Lavc57.24.102 aac
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (pcm_u8 (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 219 fps= 57 q=-1.0 Lsize= 98706kB time=00:00:07.31 bitrate=110550.2kbits/s speed=1.91x
video:598kB audio:6kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 16257.420898%
[aac # 0x7ffbe2806e00] Qavg: 65536.000
The first video has a smaller timebase (and no audio track). Rewrap it like this and then concat:
ffmpeg -i 16382802.mp4 -f lavfi -i anullsrc -c:v copy -video_track_timescale 30k -c:a aac -ac 6 -ar 44100 -shortest new.mp4