ffmpeg 生成开始时间大于 0 的视频

ffmpeg 生成开始时间大于 0 的视频

我正在尝试使用 ffmpeg 剪切视频。我知道如何以“正常方式”进行操作:

ffmpeg -i test.mp4 -ss 0 -t 6 -c:v libx264 -profile:v main -level 3.1 -preset medium -crf 20 -r 25 -b:v 1200k -minrate 1200k -maxrate 1200k -bufsize 1835k -c:a libfdk_aac -ar 48000 -ac 2 -ab 128k trimmed.mp4 

这是我的问题。当我剪切时,但我也注意到其他命令,当我使用

ffmpeg -i trimmed.mp4

输出显示了这条奇怪的行:

Duration: 00:00:06.04, start: 0.042667

为什么我的视频时长是 00:00:06.04?为什么它从 0.042667 开始?在我的应用程序中,我需要每个视频正好是 6 秒,因为在我连接 6 个视频后,我在上面放了一个覆盖层,每 6 秒显示一个不同的文本。实际上,结果视频并不正确,因为覆盖层与视频不同步。

我尝试了一个视频,视频的持续时间为 00:00:06.00,开始时间为 0.0000,结果没问题。有没有办法精确设置持续时间和开始时间?我发现了一个类似的问题这里

任何帮助,将不胜感激。


对每个视频重复第一个命令:

ffmpeg -i sample.mov -ss 1 -t 6 -c:v libx264 -profile:v main -level 3.1 -preset medium -crf 20 -r 25 -b:v 1200k -minrate 1200k -maxrate 1200k -bufsize 1835k -c:a libfdk_aac -ar 48000 -ac 2 -ab 128k  -y testTrim.mp4
ffmpeg version 2.3.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug  7 2014 18:14:20 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/home/stuzzo/ffmpeg_build --extra-cflags=-I/home/stuzzo/ffmpeg_build/include --extra-ldflags=-L/home/stuzzo/ffmpeg_build/lib --bindir=/home/stuzzo/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-nonfree
  libavutil      52. 98.100 / 52. 98.100
  libavcodec     55. 72.102 / 55. 72.102
  libavformat    55. 51.101 / 55. 51.101
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2005-10-17 22:54:32
  Duration: 00:01:25.50, start: 0.000000, bitrate: 307 kb/s
    Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 261 kb/s, 10 fps, 10 tbr, 3k tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2005-10-17 22:54:33
      handler_name    : Apple Video Media Handler
      encoder         : 3ivx D4 4.5.1
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 43 kb/s (default)
    Metadata:
      creation_time   : 2005-10-17 22:54:34
      handler_name    : Apple Sound Media Handler
[libx264 @ 0x2ad0620] using SAR=1/1
[libx264 @ 0x2ad0620] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x2ad0620] profile Main, level 3.1
[libx264 @ 0x2ad0620] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 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=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=1200 vbv_bufsize=1835 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'testTrim.mp4':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    encoder         : Lavf55.51.101
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 1200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2005-10-17 22:54:33
      handler_name    : Apple Video Media Handler
      encoder         : Lavc55.72.102 libx264
    Stream #0:1(eng): Audio: aac (libfdk_aac) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 128 kb/s (default)
    Metadata:
      creation_time   : 2005-10-17 22:54:34
      handler_name    : Apple Sound Media Handler
      encoder         : Lavc55.72.102 libfdk_aac
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
frame=  149 fps=0.0 q=-1.0 Lsize=     122kB time=00:00:06.01 bitrate= 165.5kbits/s dup=89 drop=0    
video:21kB audio:95kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.938407%
[libx264 @ 0x2ad0620] frame I:1     Avg QP: 8.65  size:   425
[libx264 @ 0x2ad0620] frame P:42    Avg QP: 9.92  size:   347
[libx264 @ 0x2ad0620] frame B:106   Avg QP: 9.92  size:    56
[libx264 @ 0x2ad0620] consecutive B-frames:  4.7%  1.3%  0.0% 94.0%
[libx264 @ 0x2ad0620] mb I  I16..4: 98.8%  0.0%  1.2%
[libx264 @ 0x2ad0620] mb P  I16..4:  1.3%  0.0%  0.5%  P16..4:  1.2%  0.4%  0.3%  0.0%  0.0%    skip:96.3%
[libx264 @ 0x2ad0620] mb B  I16..4:  0.1%  0.0%  0.0%  B16..8:  2.1%  0.0%  0.0%  direct: 0.0%  skip:97.8%  L0:26.8% L1:73.2% BI: 0.1%
[libx264 @ 0x2ad0620] coded y,uvDC,uvAC intra: 11.0% 2.5% 0.6% inter: 0.1% 0.1% 0.0%
[libx264 @ 0x2ad0620] i16 v,h,dc,p: 60% 39%  0%  0%
[libx264 @ 0x2ad0620] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 42% 17%  2%  2%  3%  3%  3%  2%
[libx264 @ 0x2ad0620] i8c dc,h,v,p: 83% 15%  2%  0%
[libx264 @ 0x2ad0620] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x2ad0620] ref P L0: 82.2%  5.1% 10.5%  2.2%
[libx264 @ 0x2ad0620] ref B L0: 56.4% 43.6%
[libx264 @ 0x2ad0620] ref B L1: 99.4%  0.6%
[libx264 @ 0x2ad0620] kb/s:28.08

连接之前:

ffmpeg -i testTrim.mp4 -q:v 0 testTrim.mpeg

ffmpeg version 2.3.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug  7 2014 18:14:20 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/home/stuzzo/ffmpeg_build --extra-cflags=-I/home/stuzzo/ffmpeg_build/include --extra-ldflags=-L/home/stuzzo/ffmpeg_build/lib --bindir=/home/stuzzo/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-nonfree
  libavutil      52. 98.100 / 52. 98.100
  libavcodec     55. 72.102 / 55. 72.102
  libavformat    55. 51.101 / 55. 51.101
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'testTrim.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.51.101
  Duration: 00:00:06.04, start: 0.042667, bitrate: 231 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 96 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[mpeg1video @ 0x2eda3c0] Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!
Output #0, mpeg, to 'testTrim.mpeg':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.51.101
    Stream #0:0(eng): Video: mpeg1video, yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 1200 kb/s, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc55.72.102 mpeg1video
    Stream #0:1(eng): Audio: mp2, 48000 Hz, stereo, s16, 384 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc55.72.102 mp2
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg1video (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp2 (native))
Press [q] to stop, [?] for help
frame=  150 fps=0.0 q=0.0 Lsize=    1116kB time=00:00:06.06 bitrate=1508.1kbits/s dup=1 drop=0    
video:823kB audio:285kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.764562%

连接:

ffmpeg -i "concat:testTrim1.mpeg|testTrim2.mpeg|testTrim3.mpeg|testTrim4.mpeg|testTrim5.mpeg|testTrim6.mpeg" -q:v 0 -s 640x360 -maxrate 5000k -bufsize 5000k -y concat.mpeg

ffmpeg version 2.3.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug  7 2014 18:14:20 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/home/stuzzo/ffmpeg_build --extra-cflags=-I/home/stuzzo/ffmpeg_build/include --extra-ldflags=-L/home/stuzzo/ffmpeg_build/lib --bindir=/home/stuzzo/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-nonfree
  libavutil      52. 98.100 / 52. 98.100
  libavcodec     55. 72.102 / 55. 72.102
  libavformat    55. 51.101 / 55. 51.101
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpeg, from 'concat:testTrim.mpeg|testTrim.mpeg|testTrim.mpeg|testTrim.mpeg|testTrim.mpeg|testTrim.mpeg':
  Duration: 00:00:06.07, start: 0.529978, bitrate: 9033 kb/s
    Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 640x480 [SAR 1:1 DAR 4:3], 1200 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Stream #0:1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 384 kb/s
Output #0, mpeg, to 'concat.mpeg':
  Metadata:
    encoder         : Lavf55.51.101
    Stream #0:0: Video: mpeg1video, yuv420p, 640x360 [SAR 3:4 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc55.72.102 mpeg1video
    Stream #0:1: Audio: mp2, 48000 Hz, stereo, s16, 384 kb/s
    Metadata:
      encoder         : Lavc55.72.102 mp2
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg1video (native) -> mpeg1video (native))
  Stream #0:1 -> #0:1 (mp2 (native) -> mp2 (native))
Press [q] to stop, [?] for help
frame=  909 fps=287 q=0.0 Lsize=    3172kB time=00:00:36.42 bitrate= 713.4kbits/s dup=9 drop=0    
video:1433kB audio:1708kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.982865%

最后:

ffmpeg -i concat.mpeg -i overlay.mov -filter_complex “[0:v][1:v] overlay [v]” -map “[v]” -map 0:a -q:v 0 -s 640x360 -shortest -y moment_overlay.mpeg

ffmpeg -i concat.mpeg -i 2scrittenew.mov -filter_complex "[0:v][1:v] overlay [v]" -map "[v]" -map 0:a -q:v 0 -s 640x360 -b:v 1200k -minrate 1200k -maxrate 1200k -bufsize 1835k -shortest -y concat_overlay.mpeg
ffmpeg version 2.3.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug  7 2014 18:14:20 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/home/stuzzo/ffmpeg_build --extra-cflags=-I/home/stuzzo/ffmpeg_build/include --extra-ldflags=-L/home/stuzzo/ffmpeg_build/lib --bindir=/home/stuzzo/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-nonfree
  libavutil      52. 98.100 / 52. 98.100
  libavcodec     55. 72.102 / 55. 72.102
  libavformat    55. 51.101 / 55. 51.101
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpeg, from 'concat.mpeg':
  Duration: 00:00:36.43, start: 0.529978, bitrate: 713 kb/s
    Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 640x360 [SAR 134:161 DAR 2144:1449], 5000 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Stream #0:1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 384 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2scrittenew.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2015-03-09 10:05:48
  Duration: 00:00:36.00, start: 0.000000, bitrate: 4384 kb/s
    Stream #1:0(eng): Video: qtrle (rle  / 0x20656C72), bgra, 640x360, 4381 kb/s, SAR 640:640 DAR 16:9, 25 fps, 25 tbr, 25 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2015-03-09 10:05:48
      handler_name    : Apple Alias Data Handler
      encoder         : Animation
      timecode        : 00:00:00:00
    Stream #1:1(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2015-03-09 10:06:41
      handler_name    : Apple Alias Data Handler
      timecode        : 00:00:00:00
[mpeg1video @ 0x2998960] Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!
Output #0, mpeg, to 'concat_overlay.mpeg':
  Metadata:
    encoder         : Lavf55.51.101
    Stream #0:0: Video: mpeg1video, yuv420p, 640x360 [SAR 134:161 DAR 2144:1449], q=2-31, 1200 kb/s, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc55.72.102 mpeg1video
    Stream #0:1: Audio: mp2, 48000 Hz, stereo, s16, 384 kb/s
    Metadata:
      encoder         : Lavc55.72.102 mp2
Stream mapping:
  Stream #0:0 (mpeg1video) -> overlay:main (graph 0)
  Stream #1:0 (qtrle) -> overlay:overlay (graph 0)
  overlay (graph 0) -> Stream #0:0 (mpeg1video)
  Stream #0:1 -> #0:1 (mp2 (native) -> mp2 (native))
Press [q] to stop, [?] for help
frame=  909 fps=184 q=0.0 Lsize=    7034kB time=00:00:36.42 bitrate=1582.1kbits/s    
video:5278kB audio:1708kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.687947%

相关内容