替换模板视频图片的原理
理解fps
.\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i offBM-1080-720-BackAudio_320kbpsmale_5.mp4 -r 1 -f image2 ffmpeg_temp/%05d.png
视频转图片
替换结果图片集合中的指定图片
再转回视频
关键点在于fps的计算,实现无缝衔接效果
从应用角度而非视频质量角度要考虑:
本地保存的帧图片的空间消耗
菜鸟驿站视频
菜鸟驿站官网-菜鸟物流加盟_菜鸟网络 https://yz.cainiao.com/
https://videocdn.taobao.com/oss/taobao-ugc/d5400f40c3f54e53a2474f85373bccb1/1479375408/video.mp4 https://videocdn.taobao.com/oss/taobao-ugc/d5400f40c3f54e53a2474f85373bccb1/1479375408/video.mp4
ffmpeg Documentation http://ffmpeg.org/ffmpeg.html
You can extract images from a video, or create a video from many images:
For extracting images from a video:
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.
If you want to extract just a limited number of frames, you can use the above command in combination with the -frames:v
or -t
option, or in combination with -ss to start extracting from a certain point in time.
For creating a video from many images:
ffmpeg -f image2 -framerate 12 -i foo-%03d.jpeg -s WxH foo.avi
The syntax foo-%03d.jpeg
specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.
When importing an image sequence, -i also supports expanding shell-like wildcard patterns (globbing) internally, by selecting the image2-specific -pattern_type glob
option.
For example, for creating a video from filenames matching the glob pattern foo-*.jpeg
:
ffmpeg -f image2 -pattern_type glob -framerate 12 -i 'foo-*.jpeg' -s WxH foo.avi
0.1 video frame per second
.\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i offBM-1080-720-BackAudio_320kbpsmale_5.mp4 -r 0.1 -f image2 ffmpeg_temp/my-%01d.png
.\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i video-cainiao.mp4 -r 0.1 -f image2 ffmpeg_temp/
my-1-10s-%01d.png
.\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i video-cainiao.mp4 -r 0.2 -f image2 ffmpeg_temp/
my-1-15s-%01d.png
PS D:\imageVideo> .\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i video-cainiao.mp4 -r 0.1 -f image2 ffmpeg_temp/ my-1-10s-%01d.png ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-cainiao.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : www.aliyun.com - Media Transcoding Duration: 00:02:45.14, start: 0.000000, bitrate: 606 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 896x504 [SAR 1:1 DAR 16:9], 504 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, 96 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> png (native)) Press [q] to stop, [?] for help Output #0, image2, to 'ffmpeg_temp/my-1-10s-%01d.png': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Stream #0:0(und): Video: png, rgb24, 896x504 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 0.10 fps, 0.10 tbn, 0.10 tbc (default) Metadata: handler_name : VideoHandler encoder : Lavc58.16.100 png frame= 18 fps=1.0 q=-0.0 Lsize=N/A time=00:03:00.00 bitrate=N/A dup=0 drop=4108 speed=9.65x video:10098kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown PS D:\imageVideo> .\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i video-cainiao.mp4 -r 0.2 -f image2 ffmpeg_temp/ my-1-15s-%01d.png ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-cainiao.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : www.aliyun.com - Media Transcoding Duration: 00:02:45.14, start: 0.000000, bitrate: 606 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 896x504 [SAR 1:1 DAR 16:9], 504 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, 96 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> png (native)) Press [q] to stop, [?] for help Output #0, image2, to 'ffmpeg_temp/my-1-15s-%01d.png': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Stream #0:0(und): Video: png, rgb24, 896x504 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 0.20 fps, 0.20 tbn, 0.20 tbc (default) Metadata: handler_name : VideoHandler encoder : Lavc58.16.100 png frame= 14 fps=8.3 q=-0.0 Lsize=N/A time=00:01:10.00 bitrate=N/A dup=0 drop=1576 speed=41.6x video:6938kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown Exiting normally, received signal 2. PS D:\imageVideo> ^C PS D:\imageVideo> ^C PS D:\imageVideo> .\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i video-cainiao.mp4 -r 0.2 -f image2 ffmpeg_temp/ my-1-15s-%01d.png ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-cainiao.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : www.aliyun.com - Media Transcoding Duration: 00:02:45.14, start: 0.000000, bitrate: 606 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 896x504 [SAR 1:1 DAR 16:9], 504 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, 96 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> png (native)) Press [q] to stop, [?] for help Output #0, image2, to 'ffmpeg_temp/my-1-15s-%01d.png': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Stream #0:0(und): Video: png, rgb24, 896x504 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 0.20 fps, 0.20 tbn, 0.20 tbc (default) Metadata: handler_name : VideoHandler encoder : Lavc58.16.100 png frame= 35 fps=2.1 q=-0.0 Lsize=N/A time=00:02:55.00 bitrate=N/A dup=0 drop=4091 speed=10.3x video:17540kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown PS D:\imageVideo>
单个图片比特数*相应的帧数的求和 大于 视频比特数
PS D:\imageVideo> .\ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i video-cainiao.mp4 -r 0.5 -f image2 ffmpeg_temp/my-1-2s-%01d.png ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-cainiao.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : www.aliyun.com - Media Transcoding Duration: 00:02:45.14, start: 0.000000, bitrate: 606 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 896x504 [SAR 1:1 DAR 16:9], 504 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, 96 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> png (native)) Press [q] to stop, [?] for help Output #0, image2, to 'ffmpeg_temp/my-1-2s-%01d.png': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Stream #0:0(und): Video: png, rgb24, 896x504 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 0.50 fps, 0.50 tbn, 0.50 tbc (default) Metadata: handler_name : VideoHandler encoder : Lavc58.16.100 png frame= 84 fps= 12 q=-0.0 Lsize=N/A time=00:02:48.00 bitrate=N/A dup=0 drop=4042 speed=23.9x video:42688kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown PS D:\imageVideo>
采样频率
5秒--》2秒
空间随采样频率的倒数增长而线性增长
17.1MB--》41.6MB
利用ffmpeg对视频进行裁剪与拼接
利用ffmpeg对视频进行裁剪与拼接 - CSDN博客 https://blog.csdn.net/lq753799168/article/details/53915866
合并 MP4 视频
ffmpeg + ts
先将 mp4 转化为同样编码形式的 ts 流,因为 ts流是可以合并的。合并 ts 流后再把 ts 流转化为 mp4。
ffmpeg -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
ffmpeg -i 2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts
ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4
C:\Users\Public\py36\python.exe C:/Users/sas/PycharmProjects/produce_video/after_fc_distributed/mkbea.py C:\Users\sas\AppData\Roaming\Python\Python36\site-packages\requests\__init__.py:80: RequestsDependencyWarning: urllib3 (1.16) or chardet (3.0.4) doesn't match a supported version! RequestsDependencyWarning) ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i 192kbps_320kbps34175777.mp3 -af 'volume=3.0' 192kbps_320kbps34175777volume3.mp3 ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i offBM-1080-720-BackAudio_320kbpsmale34053736_51818763_5.mp4 -filter:a "volume=1.5" offBM-1080-720-BackAudio_320kbpsmale34053736_51818763_5__1_5.mp4 ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5.ts ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Duration: 00:01:55.20, start: 0.000000, bitrate: 222 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1080x720 [SAR 1:1 DAR 3:2], 141 kb/s, 20 fps, 20 tbr, 10240 tbn, 40 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 76 kb/s (default) Metadata: handler_name : SoundHandler Output #0, mpegts, to 'offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5.ts': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1080x720 [SAR 1:1 DAR 3:2], q=2-31, 141 kb/s, 20 fps, 20 tbr, 90k tbn, 10240 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 76 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= 2304 fps=0.0 q=-1.0 Lsize= 3702kB time=00:01:55.07 bitrate= 263.6kbits/s speed=3.76e+003x video:1990kB audio:1073kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 20.896620% ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i head1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb head1.ts ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'head1.mp4': Metadata: major_brand : mp42 minor_version : 1 compatible_brands: mp41mp42isom creation_time : 2016-10-25T08:23:11.000000Z Duration: 00:00:04.67, start: 0.000000, bitrate: 5079 kb/s Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default) Metadata: creation_time : 2016-10-25T08:23:11.000000Z handler_name : Core Media Audio Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720, 5070 kb/s, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 24k tbn, 50 tbc (default) Metadata: creation_time : 2016-10-25T08:23:11.000000Z handler_name : Core Media Video Output #0, mpegts, to 'head1.ts': Metadata: major_brand : mp42 minor_version : 1 compatible_brands: mp41mp42isom encoder : Lavf58.10.100 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 5070 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 24k tbc (default) Metadata: creation_time : 2016-10-25T08:23:11.000000Z handler_name : Core Media Video Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default) Metadata: creation_time : 2016-10-25T08:23:11.000000Z handler_name : Core Media Audio Stream mapping: Stream #0:1 -> #0:0 (copy) Stream #0:0 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 112 fps=0.0 q=-1.0 Lsize= 3136kB time=00:00:04.65 bitrate=5523.9kbits/s speed= 515x video:2891kB audio:1kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.407116% ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i head2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb head2.ts ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'head2.mp4': Metadata: major_brand : mp42 minor_version : 1 compatible_brands: mp42mp41 creation_time : 2016-10-25T08:36:07.000000Z Duration: 00:00:06.44, start: 0.000000, bitrate: 2371 kb/s Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 2111 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default) Metadata: creation_time : 2016-10-25T08:36:07.000000Z handler_name : Apple Video Media Handler Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default) Metadata: creation_time : 2016-10-25T08:36:07.000000Z handler_name : Apple Sound Media Handler Output #0, mpegts, to 'head2.ts': Metadata: major_brand : mp42 minor_version : 1 compatible_brands: mp42mp41 encoder : Lavf58.10.100 Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, q=2-31, 2111 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc (default) Metadata: creation_time : 2016-10-25T08:36:07.000000Z handler_name : Apple Video Media Handler Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default) Metadata: creation_time : 2016-10-25T08:36:07.000000Z handler_name : Apple Sound Media Handler Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 161 fps=0.0 q=-1.0 Lsize= 2037kB time=00:00:06.40 bitrate=2606.9kbits/s speed= 105x video:1659kB audio:200kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 9.560436% ffmpeg-20180331-be502ec-win64-static_ffmpeg.exe -i "concat:head1.ts|offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5.ts|head2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5head1head2.mp4 ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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. 12.100 / 56. 12.100 libavcodec 58. 16.100 / 58. 16.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 13.100 / 7. 13.100 libswscale 5. 0.102 / 5. 0.102 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Input #0, mpegts, from 'concat:head1.ts|offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5.ts|head2.ts': Duration: 00:00:06.40, start: 1.441711, bitrate: 11359 kb/s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720, 25 fps, 23.98 tbr, 90k tbn, 50 tbc Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 85 kb/s Output #0, mp4, to 'offBM-1080-720-BackAudio_320kbpsmale34021448_51873338_5head1head2.mp4': Metadata: encoder : Lavf58.10.100 Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720, q=2-31, 25 fps, 23.98 tbr, 90k tbn, 90k tbc Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 85 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [mpegts @ 000001dd6330a600] DTS 126000 < 10489500 out of order frame= 2577 fps=0.0 q=-1.0 Lsize= 7903kB time=00:02:06.21 bitrate= 513.0kbits/s speed=1.32e+003x video:6555kB audio:1274kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.948876% Process finished with exit code 232
FFmpeg FAQ https://ffmpeg.org/faq.html#How-can-I-concatenate-video-files_003f
3.14 How can I concatenate video files?
There are several solutions, depending on the exact circumstances.
3.14.1 Concatenating using the concat filter
FFmpeg has a concat
filter designed specifically for that, with examples in the documentation. This operation is recommended if you need to re-encode.
3.14.2 Concatenating using the concat demuxer
FFmpeg has a concat
demuxer which you can use when you want to avoid a re-encode and your format doesn’t support file level concatenation.
3.14.3 Concatenating using the concat protocol (file level)
FFmpeg has a concat
protocol designed specifically for that, with examples in the documentation.
A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow one to concatenate video by merely concatenating the files containing them.
Hence you may concatenate your multimedia files by first transcoding them to these privileged formats, then using the humble cat
command (or the equally humble copy
under Windows), and finally transcoding back to your format of choice.
ffmpeg -i input1.avi -qscale:v 1 intermediate1.mpg ffmpeg -i input2.avi -qscale:v 1 intermediate2.mpg cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg ffmpeg -i intermediate_all.mpg -qscale:v 2 output.avi
Additionally, you can use the concat
protocol instead of cat
or copy
which will avoid creation of a potentially huge intermediate file.
ffmpeg -i input1.avi -qscale:v 1 intermediate1.mpg ffmpeg -i input2.avi -qscale:v 1 intermediate2.mpg ffmpeg -i concat:"intermediate1.mpg|intermediate2.mpg" -c copy intermediate_all.mpg ffmpeg -i intermediate_all.mpg -qscale:v 2 output.avi
Note that you may need to escape the character "|" which is special for many shells.
Another option is usage of named pipes, should your platform support it:
mkfifo intermediate1.mpg mkfifo intermediate2.mpg ffmpeg -i input1.avi -qscale:v 1 -y intermediate1.mpg < /dev/null & ffmpeg -i input2.avi -qscale:v 1 -y intermediate2.mpg < /dev/null & cat intermediate1.mpg intermediate2.mpg |\ ffmpeg -f mpeg -i - -c:v mpeg4 -c:a libmp3lame output.avi
3.14.4 Concatenating using raw audio and video
Similarly, the yuv4mpegpipe format, and the raw video, raw audio codecs also allow concatenation, and the transcoding step is almost lossless. When using multiple yuv4mpegpipe(s), the first line needs to be discarded from all but the first stream. This can be accomplished by piping through tail
as seen below. Note that when piping through tail
you must use command grouping, { ;}
, to background properly.
For example, let’s say we want to concatenate two FLV files into an output.flv file:
mkfifo temp1.a mkfifo temp1.v mkfifo temp2.a mkfifo temp2.v mkfifo all.a mkfifo all.v ffmpeg -i input1.flv -vn -f u16le -c:a pcm_s16le -ac 2 -ar 44100 - > temp1.a < /dev/null & ffmpeg -i input2.flv -vn -f u16le -c:a pcm_s16le -ac 2 -ar 44100 - > temp2.a < /dev/null & ffmpeg -i input1.flv -an -f yuv4mpegpipe - > temp1.v < /dev/null & { ffmpeg -i input2.flv -an -f yuv4mpegpipe - < /dev/null | tail -n +2 > temp2.v ; } & cat temp1.a temp2.a > all.a & cat temp1.v temp2.v > all.v & ffmpeg -f u16le -c:a pcm_s16le -ac 2 -ar 44100 -i all.a \ -f yuv4mpegpipe -i all.v \ -y output.flv rm temp[12].[av] all.[av]