在 FFMPEG 中使用 -itsoffset 和 enable=gt() 时出错

在 FFMPEG 中使用 -itsoffset 和 enable=gt() 时出错

我正在尝试在视频剪辑的末尾添加一个简短的结尾,该结尾从该剪辑的最后一帧开始叠加。

到目前为止我可以

  • 填充剪辑显示最后一帧 10 秒(动画播放的时间)
  • 将视频缩放到正确的匹配尺寸
  • 将动画叠加到剪辑中

但我无法在正确的位置开始播放动画。

目前它适用于任意值,小于剪辑的初始持续时间,例如 5.6...

video="test-video.mp4"
output="test-video-outro.mp4"
duration='5.6'
ffmpeg -y -i $video -itsoffset $duration -i outro-frames/Outro.%05d.png \
-filter_complex "[0]tpad=stop_mode=clone:stop_duration=10[extended];[1][extended]scale2ref[scaled][ref];[ref][scaled]overlay=x=0:y=0:enable=gt(t\,$duration\)" \
$output

但是当我使用ffprobe它来获取剪辑的实际持续时间,并将其用作持续时间偏移量时......

duration=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 $video)

45.492133例如,我知道该值是正确的——但我收到一个错误......

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7febc9853e00] moov atom not found
test-video-outro.mp4: Invalid data found when processing input

我也尝试过使用setpts-itsoffset但得到同样的错误

ffmpeg -y -i $video -i outro-frames/Outro.%05d.png \
-filter_complex "[0]tpad=stop_mode=clone:stop_duration=10,setpts=PTS[extended];[1]setpts=PTS+$duration/TB[offset];[offset][extended]scale2ref[scaled][ref];[ref][scaled]overlay=x=0:y=0:enable=gt(t\,$duration\)" \
$output

似乎输入视频的持续时间越接近,问题就越多。将持续时间设置为结束前几秒,结尾动画可以正常工作,但行为有些奇怪,会出现闪烁。

我觉得我已经接近成功了,但现在却陷入困境,任何建议都值得感激。

完整输出日志

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.16)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include/darwin -fno-stack-check' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --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. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test-video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41iso4
    creation_time   : 2020-04-26T13:32:15.000000Z
  Duration: 00:00:15.50, start: 0.000000, bitrate: 587 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, Closed Captions, 453 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2020-04-26T13:32:15.000000Z
      handler_name    : Vireo Eyes v2.5.3
      encoder         : AVC Coding
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2020-04-26T13:32:15.000000Z
      handler_name    : Vireo Ears v2.5.3
Input #1, image2, from 'outro-frames/Outro.%05d.png':
  Duration: 00:00:01.64, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: png, pal8(pc), 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 (h264) -> tpad (graph 0)
  Stream #1:0 (png) -> setpts (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
-async is forwarded to lavfi similarly to -af aresample=async=1:min_hard_comp=0.100000:first_pts=0.
[image2 @ 0x7f909303da00] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[libx264 @ 0x7f909301e200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f909301e200] profile High, level 3.1
[libx264 @ 0x7f909301e200] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=22 lookahead_threads=3 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 'test-video-outro.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41iso4
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720, q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2020-04-26T13:32:15.000000Z
      handler_name    : Vireo Ears v2.5.3
      encoder         : Lavc58.54.100 aac
./generate-youtube-video.sh: line 13: 28518 Segmentation fault: 11  ffmpeg -y -i $video -i outro-frames/Outro.%05d.png -filter_complex "[0]tpad=stop_mode=clone:stop_duration=10,setpts=PTS[extended];[1]setpts=PTS+$duration/TB[offset];[offset][extended]scale2ref[scaled][ref];[ref][scaled]overlay=x=0:y=0:enable=gt(t\,$duration\)" -async 1 $output
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb1bb014800] moov atom not found
test-video-outro.mp4: Invalid data found when processing input

答案1

您不需要为此填充视频。覆盖将延长主输入的最后一帧,并在较长的输入结束时终止。

ffmpeg -y -i $video -itsoffset $duration -i outro-frames/Outro.%05d.png \ -filter_complex "[1][0]scale2ref[scaled][ref];[ref][scaled]overlay=x=0:y=0:enable=gt(t\,$duration\)" \ $output

(缺少 moov atom 错误是指 MP4/MOV 文件损坏,与实际的 ffmpeg 命令或应用的过滤器无关)

相关内容