I'm trying to speed up the rendering of a video by using the GPU instead of the CPU. This code works, but I don't know if I'm doing it correctly.
ffmpeg -hwaccel cuvid -c:v hevc_cuvid \
-i video.mp4 \
-i logo.png \
-i text.mov \
-c:v h264_nvenc \
-filter_complex " \
[0]scale_npp=1920:1080,hwdownload,format=nv12[bg0]; \
[bg0]trim=0.00:59.460,setpts=PTS-STARTPTS[bg0]; \
[1]scale=150:-1[logo1];[bg0][logo1]overlay=(W-w)-10:(H-h)-10[bg0]; \
[2]scale=500:-1[logo2];[logo2]setpts=PTS-STARTPTS[logo2]; \
[bg0][logo2]overlay=-150:-100[bg0]; \
[bg0]fade=in:00:30,fade=out:1750:30[bg0]" \
-map "[bg0]" -preset fast -y output.mp4
I feel like I need to be using hwuplaod somewhere in there, but I'm not totally sure. Any help would be appreciated.
Log from run:
ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
configuration: --enable-gpl --enable-libx264 --enable-cuda --enable-nvenc --enable-cuvid --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include/ --extra-ldflags=-L/usr/local/cuda/lib64/
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
[hevc # 0x3eb04c0] vps_num_hrd_parameters -1 is invalid
[hevc # 0x3eb04c0] VPS 0 does not exist
[hevc # 0x3eb04c0] SPS 0 does not exist.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.7.100
Duration: 00:00:59.46, start: 0.000000, bitrate: 5894 kb/s
Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 5891 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
Metadata:
handler_name : VideoHandler
Input #1, png_pipe, from 'logo.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 528x128 [SAR 11339:11339 DAR 33:8], 25 tbr, 25 tbn, 25 tbc
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'text.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf57.56.100
Duration: 00:00:06.00, start: 0.000000, bitrate: 1276 kb/s
Stream #2:0(eng): Video: qtrle (rle / 0x20656C72), bgra, 1920x1080, 1274 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
Metadata:
handler_name : DataHandler
Stream mapping:
Stream #0:0 (hevc_cuvid) -> scale_npp
Stream #1:0 (png) -> scale
Stream #2:0 (qtrle) -> scale
fade -> Stream #0:0 (h264_nvenc)
Press [q] to stop, [?] for help
Output #0, mp4, to 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.12.100
Stream #0:0: Video: h264 (h264_nvenc) (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 2000 kb/s, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
encoder : Lavc58.18.100 h264_nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: -1
frame= 1783 fps=151 q=30.0 Lsize= 15985kB time=00:00:59.45 bitrate=2202.4kbits/s dup=4 drop=0 speed=5.04x
video:15977kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.050389%
Not sure what to make of this, pretty new to ffmpeg.
See this portion,
Stream #0:0 (hevc_cuvid) -> scale_npp
Stream #1:0 (png) -> scale
Stream #2:0 (qtrle) -> scale
fade -> Stream #0:0 (h264_nvenc)
hevc_cuvid is the decoder for the input stream 0:0 and h264_nvenc is the encoder for the output stream 0:0. Both are hardware accelerated.
The other two input video streams have codecs PNG and QTRLE, for which, no hardware acceleration is available.
Related
I want to convert mp4 video resolution using FFmPEG, I use the following command:
ffmpeg.exe -i '.\(G)I-DLE - Uh-Oh.mp4' -vf scale=1920:1080 1080p.mp4
The video stream of the input file is H264 bit stream, while the output file is mPEG4 bit stream.How to solve this problem? Here is the command line output:
ffmpeg version N-104710-g12f8293c02 Copyright (c) 2000-2021 the FFmpeg developers
built with Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24245 for x86
configuration: --prefix=./out --extra-cflags=-I../common --toolchain=msvc --target-os=win32 --arch=x86 --enable-asm --enable-yasm --enable-gpl --disable-shared --disable-doc --disable-podpages --disable-txtpages --enable-static
libavutil 57. 9.101 / 57. 9.101
libavcodec 59. 14.100 / 59. 14.100
libavformat 59. 9.102 / 59. 9.102
libavdevice 59. 0.101 / 59. 0.101
libavfilter 8. 17.100 / 8. 17.100
libswscale 6. 1.101 / 6. 1.101
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\(G)I-DLE - Uh-Oh.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
artist : (G)I-DLE
comment : 163 key(Don't modify):reZGxbjnM7jVHKNhHTowoqD/KBkrenVYXoIu24rU95dHecNWoUdka1gVaCz12onEbysjwXZQbsMRKCBZBOHaVoB9rPs/bExUC78XiecFLTSw20rpKAp6mock+Or4r3oiKYA6eT4wmbRNV/aJZNGiPLhQje+VCg4t7ASt57Pjmm4yJ1Ug0M2wvjkKx+IvqEFRP2FUmmGdOavdm/pFzXbqql/xKDgTnVSeG44a26U1z
title : Uh-Oh
encoder : Lavf57.71.100
Duration: 00:03:30.84, start: 0.000000, bitrate: 6224 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 6087 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
File '1080p.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[mpeg4 # 04466E40] Invalid pixel aspect ratio 256/81, limit is 255/255 reducing
Output #0, mp4, to '1080p.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
artist : (G)I-DLE
comment : 163 key(Don't modify):reZGxbjnM7jVHKNhHTowoqD/KBkrenVYXoIu24rU95dHecNWoUdka1gVaCz12onEbysjwXZQbsMRKCBZBOHaVoB9rPs/bExUC78XiecFLTSw20rpKAp6mock+Or4r3oiKYA6eT4wmbRNV/aJZNGiPLhQje+VCg4t7ASt57Pjmm4yJ1Ug0M2wvjkKx+IvqEFRP2FUmmGdOavdm/pFzXbqql/xKDgTnVSeG44a26U1z
title : Uh-Oh
encoder : Lavf59.9.102
Stream #0:0(eng): Video: mpeg4 (mp4v / 0x7634706D), yuv420p(tv, progressive), 1080x1920 [SAR 177:56 DAR 1593:896], q=2-31, 200 kb/s, SAR 256:81 DAR 16:9, 25 fps, 12800 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc59.14.100 mpeg4
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
encoder : Lavc59.14.100 aac
frame= 5271 fps=237 q=31.0 Lsize= 76329kB time=00:03:30.80 bitrate=2966.2kbits/s speed=9.48x
video:72842kB audio:3352kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.177660%
[aac # 04770BC0] Qavg: 969.899**strong text**
As you can see above, the input format is H264 and the output format is MPEG4. How can change the video resolution without changing the video stream format?
If I define some dummy filter_complex say:
[3:v]split=2[3_1][3_2]
[3_1]format=yuv420p,scale='640:360',setsar='1/1'[1]
[3_2]format=yuv420p,scale='640:360',setsar='1/1'[2]
[4:v]split=2[4_1][4_2]
[4_1]format=yuv420p,scale='640:360',setsar='1/1'[3]
[4_2]format=yuv420p,scale='640:360',setsar='1/1'[4]
[1][2][3][4]concat=n=4:v=1:a=0[video_out]
FFmpeg uses all the memory and crashes. What might be the reason?
The same happens for:
[3:v]format=yuv420p,scale='640:360',setsar='1/1'[1]
[3:v]format=yuv420p,scale='640:360',setsar='1/1'[2]
[4:v]format=yuv420p,scale='640:360',setsar='1/1'[3]
[4:v]format=yuv420p,scale='640:360',setsar='1/1'[4]
[1][2][3][4]concat=n=4:v=1:a=0[video_out]
I know the examples are silly but I am here asking about why this uses all my RAM? (and how to work around this)
This works great by the way (inputs used once):
[3:v]format=yuv420p,scale='640:360',setsar='1/1'[1]
[4:v]format=yuv420p,scale='640:360',setsar='1/1'[2]
[1][2]concat=n=2:v=1:a=0[video_out]
UPDATE:
The full log. While it runs it reaches 2GB memory usage in about 5s and continues to grow.
ffmpeg.exe -y -f lavfi -i nullsrc=s=640x360 -i 1000211803.mp4 -i 220710.mp4 -i 223157.mp4 -i 232365.mp4 -i 1000000046.mp4 -i 1000238585.mp4 -filter_complex_script "c:\Users\wojtek\Desktop\Development\video_grid_ffmpeg_nodejs\filter_complex_param.txt" -vsync 2 -map "[video_out]" out.mp4
ffmpeg version n4.3.1-20-g8a2acdc6da Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3-win32 (GCC) 20200320
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-opencl --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --disable-avisynth --enable-libdav1d --disable-libdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --disable-libvidstab --disable-libx264 --disable-libx265 --disable-libxavs2 --disable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
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
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
Input #0, lavfi, from 'nullsrc=s=640x360':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '1000211803.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.33.100
Duration: 00:55:35.33, start: 0.000000, bitrate: 136 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 376x210 [SAR 1:1 DAR 188:105], 134 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '220710.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.33.100
Duration: 00:57:21.43, start: 0.000000, bitrate: 102 kb/s
Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 376x210 [SAR 1:1 DAR 188:105], 99 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '223157.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.33.100
Duration: 01:01:11.27, start: 0.000000, bitrate: 156 kb/s
Stream #3:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 376x210 [SAR 1:1 DAR 188:105], 153 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from '232365.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.33.100
Duration: 01:01:07.20, start: 0.000000, bitrate: 127 kb/s
Stream #4:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 376x210 [SAR 1:1 DAR 188:105], 124 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #5, mov,mp4,m4a,3gp,3g2,mj2, from '1000000046.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.33.100
Duration: 00:52:17.23, start: 0.000000, bitrate: 190 kb/s
Stream #5:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 376x210 [SAR 1:1 DAR 188:105], 188 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #6, mov,mp4,m4a,3gp,3g2,mj2, from '1000238585.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.33.100
Duration: 00:50:58.77, start: 0.000000, bitrate: 106 kb/s
Stream #6:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 376x210 [SAR 1:1 DAR 188:105], 103 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream mapping:
Stream #3:0 (h264) -> format
Stream #3:0 (h264) -> format
Stream #4:0 (h264) -> format
Stream #4:0 (h264) -> format
concat -> Stream #0:0 (mpeg4)
Press [q] to stop, [?] for help
Output #0, mp4, to 'out.mp4':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
encoder : Lavc58.91.100 mpeg4
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame= 6130 fps=610 q=20.6 Lsize= 5334kB time=00:03:24.30 bitrate= 213.9kbits/s speed=20.3x
video:5307kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.507003%
The above has been produced using this filter_complex parameter value:
[3:v]format=yuv420p,scale='-1:360',crop='640:in_h',setsar='1/1'[i2_640_360]
[3:v]format=yuv420p,scale='-1:360',crop='640:in_h',setsar='1/1'[i2_320_360]
[4:v]format=yuv420p,scale='-1:360',crop='640:in_h',setsar='1/1'[i3_320_360]
[4:v]format=yuv420p,scale='-1:360',crop='640:in_h',setsar='1/1'[i3_640_360]
[i2_640_360][i2_320_360][i3_320_360][i3_640_360]concat=n=4:v=1:a=0[video_out]
I did not wait for it to give the out of memory error.
It seems that all the outputs of the split/asplit filters need to be put through fifo/afifo filters respectively before further processing. Don't know why exactly.
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 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
ffmpeg newbie here struggling to do something that apparently should be easy.
I want to concatenate three videos, being one of them just a blank video two seconds transition.
First I generate the blank video with:
ffmpeg -f lavfi -i color=c=black:s=320x240:d=0.5 silent.mp4
After I try to concat it with two other videos I have:
ffmpeg -i video-a.mp4 -i 2-seconds-silent-video.mp4 -i video-b.mp4 -y -filter_complex concat=n=3:v=1:a=1 result.mp4
What I'm getting:
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_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-libvo-aacenc --enable-libxvid --enable-libvpx --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-a.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.40.101
Duration: 00:00:03.03, start: 0.033333, bitrate: 822 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 691 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2-seconds-silent-video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.40.101
Duration: 00:00:02.00, start: 0.000000, bitrate: 17 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 11 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'video-b.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.40.101
Duration: 00:00:03.03, start: 0.033333, bitrate: 745 kb/s
Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 613 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Cannot find a matching stream for unlabeled input pad 5 on filter Parsed_concat_0
What I also tried without success:
ffmpeg -y -i "concat:video-a.mp4|2-seconds-silent-video.mp4|video-b.mp4" -c copy result.mp4
Result:
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_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-libvo-aacenc --enable-libxvid --enable-libvpx --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fd12a812800] Found duplicated MOOV Atom. Skipped it
Last message repeated 1 times
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:video-a.mp4|2-seconds-silent-video.mp4|video-b.mp4':
Metadata:
encoder : Lavf56.40.101
minor_version : 512
major_brand : isom
compatible_brands: isomiso2avc1mp41
Duration: 00:00:03.03, start: 0.033333, bitrate: 1579 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 691 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
[mp4 # 0x7fd12a033a00] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x7fd12a033a00] Codec for stream 1 does not use global headers but container format requires global headers
Output #0, mp4, to 'result.mp4':
Metadata:
compatible_brands: isomiso2avc1mp41
minor_version : 512
major_brand : isom
encoder : Lavf56.36.100
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 691 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 75 fps=0.0 q=-1.0 Lsize= 305kB time=00:00:03.05 bitrate= 818.1kbits/s
video:253kB audio:48kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.179313%
There's no audio stream when I generate my blank video. The solution is add a silent audio stream to the video:
ffmpeg -y -f lavfi -i anullsrc -i 2-seconds-silent-video.mp4 -shortest -c:v copy -c:a aac -strict experimental silent-video.mp4
answered here by #miindlek, thank you.
where I found the line above: adding silent audio in ffmpeg