ffmpeg concat上次图像持续时间不正确

ffmpeg concat上次图像持续时间不正确,ffmpeg,Ffmpeg,这是我的png.txt文件: file '01.png' duration 92 file '02.png' duration 46 file '03.png' duration 67 file '04.png' duration 62 file '05.png' duration 57 file '06.png' duration 3 file '06.png' mp3播放时间=00:05:28(以上总计) 这是一句话: ffmpeg -f concat -i png.txt -vsync

这是我的png.txt文件:

file '01.png'
duration 92
file '02.png'
duration 46
file '03.png'
duration 67
file '04.png'
duration 62
file '05.png'
duration 57
file '06.png'
duration 3
file '06.png'
mp3播放时间=00:05:28(以上总计)

这是一句话:

ffmpeg -f concat -i png.txt -vsync vfr -i 20170817.mp3 -c:a aac -s 1280x720 -c:v libx264 -pix_fmt yuv420p -shortest 20170817.mp4
以下是输出:

ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, concat, from 'png.txt':
  Duration: 00:05:27.00, start: 0.000000, bitrate: 0 kb/s
    Stream #0:0: Video: png, rgba(pc), 1280x720 [SAR 2835:2835 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Input #1, mp3, from '20170817.mp3':
  Metadata:
    encoder         : Lavf57.71.100
  Duration: 00:05:28.10, start: 0.069063, bitrate: 24 kb/s
    Stream #1:0: Audio: mp3, 16000 Hz, mono, s16p, 24 kb/s
File '20170817.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
  Stream #1:0 -> #0:1 (mp3 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fbe83003000] using SAR=1/1
[libx264 @ 0x7fbe83003000] using cpu capabilities: MMX2 SSE2Fast SSSE3     SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fbe83003000] profile High, level 3.1
[libx264 @ 0x7fbe83003000] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4    AVC codec - Copyleft 2003-2016 - 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=6 lookahead_threads=1 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 '20170817.mp4':
  Metadata:
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 16000 Hz, mono, fltp, 69 kb/s
    Metadata:
      encoder         : Lavc57.89.100 aac
frame=    7 fps=4.2 q=-1.0 Lsize=    3349kB time=00:05:27.04 bitrate=  83.9kbits/s speed= 196x    
video:465kB audio:2863kB subtitle:0kB other streams:0kB global    headers:0kB muxing overhead: 0.644585%
[libx264 @ 0x7fbe83003000] frame I:1     Avg QP: 7.93  size:159157
[libx264 @ 0x7fbe83003000] frame P:2     Avg QP:17.16  size: 61998
[libx264 @ 0x7fbe83003000] frame B:4     Avg QP:18.34  size: 48049
[libx264 @ 0x7fbe83003000] consecutive B-frames: 14.3% 28.6%  0.0% 57.1%
[libx264 @ 0x7fbe83003000] mb I  I16..4: 48.6% 21.6% 29.8%
[libx264 @ 0x7fbe83003000] mb P  I16..4:  4.4%  9.8% 19.7%  P16..4: 11.6%  3.0%  2.6%  0.0%  0.0%    skip:48.9%
[libx264 @ 0x7fbe83003000] mb B  I16..4:  0.4%  0.5% 13.2%  B16..8: 14.9%  3.9%  2.6%  direct: 1.1%  skip:63.4%  L0:45.0% L1:52.1% BI: 3.0%
[libx264 @ 0x7fbe83003000] 8x8 transform intra:19.2% inter:38.3%
[libx264 @ 0x7fbe83003000] coded y,uvDC,uvAC intra: 52.3% 63.3% 62.4% inter: 8.6% 7.7% 6.9%
[libx264 @ 0x7fbe83003000] i16 v,h,dc,p: 88%  9%  3%  0%
[libx264 @ 0x7fbe83003000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 12% 45%  2%  2%  3%  2%  3%  4%
[libx264 @ 0x7fbe83003000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 26% 18%  5%  5%  5%  5%  6%  6%
[libx264 @ 0x7fbe83003000] i8c dc,h,v,p: 55% 18% 20%  8%
[libx264 @ 0x7fbe83003000] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fbe83003000] ref P L0: 93.3%  0.3%  3.7%  2.8%
[libx264 @ 0x7fbe83003000] ref B L0: 85.2% 14.8%
[libx264 @ 0x7fbe83003000] ref B L1: 87.8% 12.2%
[libx264 @ 0x7fbe83003000] kb/s:11.52
[aac @ 0x7fbe83004800] Qavg: 1971.172
问题是mp4的持续时间是00:06:45,音乐在00:05:28结束

我该如何切掉最后一点沉默

我尝试了以下方法:

ffmpeg -ss 0 -i 20170817.mp4 -to 00:05:28 -c copy cut.mp4
哪个更糟。在前面添加空白无声视频,并在中间剪切尚未完成的视频


请注意,前5张图像在正确的音乐位置是正确的,只有最后一张图像持续时间错误

在最后运行到相同的额外静音后,似乎使用输出选项明确限制视频长度(
-to
-t
)可以完成此任务。()

我对你的问题有一个类似的设置,尽管我对一个音频文件进行了10秒的切片,并使用
concat
过滤器将其覆盖4幅图像

# files.ffconcat
file 'image1.png'
duration 1
file 'image2.png'
duration 4
file 'image3.png'
duration 3
file 'image4.png'
duration 2
虽然1+4+3+2=10秒,但最终视频的长度为10.84秒,结尾为静音,正如您所观察到的:

frame=  274 fps= 17 q=-1.0 Lsize=    1013kB time=00:00:10.84 bitrate= 765.2kbits/s dup=343 drop=0 speed=0.683x
但是,添加
-t10
作为输出选项

ffmpeg \
    -t 10 \
    -i song.mp3 \
    -i files.ffconcat \
    -pix_fmt yuv420p \
    -t 10 \
    video.mp4
ffmpeg \
    -t 10 \
    -i song.mp3 \
    -i files.ffconcat \
    -pix_fmt yuv420p \
    -t 10 \
    video.mp4
结果显示的视频正好是10秒:

frame=  250 fps= 31 q=-1.0 Lsize=    1002kB time=00:00:10.00 bitrate= 820.0kbits/s dup=343 drop=0 speed=1.25x
# files.ffconcat
file 'image1.png'
duration 2.5
file 'image2.png'
duration 2.5
file 'image3.png'
duration 2.5
file 'image4.png'
duration 2.5
旁白 有趣的是,如果每个图像的持续时间为2.5秒,则最终视频不需要精确到10秒:

frame=  250 fps= 31 q=-1.0 Lsize=    1002kB time=00:00:10.00 bitrate= 820.0kbits/s dup=343 drop=0 speed=1.25x
# files.ffconcat
file 'image1.png'
duration 2.5
file 'image2.png'
duration 2.5
file 'image3.png'
duration 2.5
file 'image4.png'
duration 2.5
这是我无法理解的。但对于任何好奇的人来说,这里是
ffmpeg-version

ffmpeg version 4.0.1-tessus Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
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

你试过使用不同的音频编解码器吗?aac具有
启动
剩余
slient尝试用
-acodec副本
替换
-c:aac
,结果相同,结尾无提示。另外-acodec copy-只有浏览器可以播放mp4,quicktime无法播放您可以对输出执行
ffprobe
吗?上传到youtube并自动截断静音端:D