1

У меня есть одна команда ffmpeg, которая объединяет 3 видео mp4 вместе, а затем другая команда, которая применяет водяной знак к выходному видео первой команды. Команды:

Слияние MP4 видео с их смешением

ffmpeg -y -threads 0  -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -f lavfi -i color=black -filter_complex "[0:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS[va0];[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS+5/TB[va1];[2:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS+10/TB[va2];[3:v]scale=1280x720,trim=duration=15[over0];[over0][va0]overlay[over1];[over1][va1]overlay[over2];[over2][va2]overlay=format=yuv420[outv]" -vcodec libx264 -map [outv] -s 1280x720 -aspect 16:9 -r 30 -crf 1 -preset ultrafast output.mp4

Выход:

[jstevens@jr testing]$ ffmpeg -y -threads 0  -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -f lavfi -i color=black -filter_complex "[0:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS[va0];[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS+5/TB[va1];[2:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS+10/TB[va2];[3:v]scale=1280x720,trim=duration=15[over0];[over0][va0]overlay[over1];[over1][va1]overlay[over2];[over2][va2]overlay=format=yuv420[outv]" -vcodec libx264 -map [outv] -s 1280x720 -aspect 16:9 -r 30 -crf 1 -preset ultrafast output.mp4
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.1.1 (GCC) 20160510 (Red Hat 6.1.1-2)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  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 'vid-1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:05.00, start: 0.000000, bitrate: 1085 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1081 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:05.00, start: 0.000000, bitrate: 1018 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1014 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-3.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:05.00, start: 0.000000, bitrate: 823 kb/s
    Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 819 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #3, lavfi, from 'color=black':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #3:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x125c040] using SAR=1/1
[libx264 @ 0x125c040] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x125c040] profile Constrained Baseline, level 3.1
[libx264 @ 0x125c040] 264 - core 148 r2699 a5e06b9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - 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=1.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     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc57.24.102 libx264
    Side data:
      unknown side data type 10 (24 bytes)
Stream mapping:
  Stream #0:0 (h264) -> format
  Stream #1:0 (h264) -> format
  Stream #2:0 (h264) -> format
  Stream #3:0 (rawvideo) -> scale
  overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame=  450 fps=118 q=-1.0 Lsize=  133025kB time=00:00:15.00 bitrate=72649.6kbits/s dup=75 drop=0 speed=3.93x    
video:133021kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.003404%
[libx264 @ 0x125c040] frame I:2     Avg QP: 0.00  size:301111
[libx264 @ 0x125c040] frame P:448   Avg QP: 2.03  size:302702
[libx264 @ 0x125c040] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x125c040] mb P  I16..4:  8.1%  0.0%  0.0%  P16..4: 90.2%  0.0%  0.0%  0.0%  0.0%    skip: 1.8%
[libx264 @ 0x125c040] coded y,uvDC,uvAC intra: 97.1% 94.1% 93.7% inter: 90.5% 69.8% 68.7%
[libx264 @ 0x125c040] i16 v,h,dc,p: 35% 55%  6%  3%
[libx264 @ 0x125c040] i8c dc,h,v,p: 21% 43% 28%  7%
[libx264 @ 0x125c040] kb/s:72646.80

Применить водяной знак

ffmpeg -y -threads 0 -i output.mp4 -i watermark.png -filter_complex fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5,overlay=(main_w-overlay_w):(main_h-overlay_h) -pix_fmt yuv420p -crf 1 -preset ultrafast final.mp4

Выход:

[jstevens@jr testing]$ ffmpeg -y -threads 0 -i output.mp4 -i watermark.png -filter_complex "fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5,overlay=(main_w-overlay_w):(main_h-overlay_h)" -pix_fmt yuv420p -crf 1 -preset ultrafast final.mp4
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.1.1 (GCC) 20160510 (Red Hat 6.1.1-2)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  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 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:15.00, start: 0.000000, bitrate: 72649 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 72647 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, png_pipe, from 'watermark.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgb24(pc), 1280x720 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x1b80e00] using SAR=1/1
[libx264 @ 0x1b80e00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x1b80e00] profile Constrained Baseline, level 3.1
[libx264 @ 0x1b80e00] 264 - core 148 r2699 a5e06b9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - 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=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'final.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc57.24.102 libx264
    Side data:
      unknown side data type 10 (24 bytes)
Stream mapping:
  Stream #0:0 (h264) -> fade
  Stream #1:0 (png) -> overlay:overlay
  overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame=  450 fps=188 q=-1.0 Lsize=    1470kB time=00:00:15.00 bitrate= 802.8kbits/s speed=6.26x    
video:1467kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.175498%
[libx264 @ 0x1b80e00] frame I:2     Avg QP: 0.00  size:573234
[libx264 @ 0x1b80e00] frame P:448   Avg QP: 0.02  size:   794
[libx264 @ 0x1b80e00] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x1b80e00] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  4.3%  0.0%  0.0%  0.0%  0.0%    skip:95.7%
[libx264 @ 0x1b80e00] coded y,uvDC,uvAC intra: 100.0% 94.1% 93.9% inter: 1.2% 0.1% 0.1%
[libx264 @ 0x1b80e00] i16 v,h,dc,p: 24% 32% 22% 23%
[libx264 @ 0x1b80e00] i8c dc,h,v,p: 29% 34% 25% 13%
[libx264 @ 0x1b80e00] kb/s:801.06

Можно ли в любом случае применить водяной знак одновременно с смешиванием mp4? Я хочу быть в состоянии сделать это в одной команде.

1 ответ1

1
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i vid-4.mp4 -f lavfi -i color=black:r=ntsc-film:s=1280x720:d=18.5 -loop 1 -i watermark.png -filter_complex \
"[0:v]setpts=PTS-STARTPTS,fade=t=out:st=5:d=0.5:alpha=1[va0]; \
 [1:v]format=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS+4.5/TB[va1]; \
 [2:v]format=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,fade=t=out:st=5:d=0.5:alpha=1,setpts=PTS-STARTPTS+9/TB[va2]; \
 [3:v]format=yuva420p,fade=t=in:st=0:d=0.5:alpha=1,setpts=PTS-STARTPTS+13.5/TB[va3]; \
 [4:v][va0]overlay[over1]; \
 [over1][va1]overlay[over2]; \
 [over2][va2]overlay[over3]; \
 [over3][va3]overlay[over4]; \
 [over4][5:v]overlay=W-w:H-h:shortest=1,fade=t=in:st=0:d=0.5,fade=t=out:st=18:d=0.5,format=yuv420p[outv]" \
-c:v libx264 -map "[outv]" -crf 0 -preset ultrafast output.mp4
  • Я исключил [3:v]scale=1280x720,trim=duration=15[over0] поскольку вы можете установить размер и продолжительность (и частоту кадров) в самом фильтре источника цвета.

  • Я удалил -s 1280x720 -aspect 16:9 потому что ваши входы уже имеют формат изображения 1280x720 и 16:9. Я также удалил -r 30 потому что кажется, что нет необходимости менять значение с 25 до 30 кадров в секунду, что приведет к дублированию кадров.

  • Вам не нужно объявлять pix_fmts в фильтре формата.

  • Добавлен -loop в watermark.png .

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .