4

我想使用 ffmpeg 将视频的前几秒(比如 5 秒)转换为多种输出格式。

当我使用此语法转换整个视频时,一切正常:(
为简单起见,我将所有选项保留为默认值)

ffmpeg -i input.flv output1.mp4 output2.avi

但是当使用这种语法尝试前 5 秒时:

ffmpeg -t 5 -i input.flv output1.mp4 output2.avi

第一个输出文件(即 ouptput1.mp4)没问题,长度为 5 秒,但第二个(以及下一个输出,如果存在)具有原始文件的大小。

这就是 ffmpeg 在屏幕上打印的内容。

D:\ffmpeg\bin>ffmpeg -t 5 -i input.flv output1.mp4 output2.avi
ffmpeg version N-40301-gc1fe2db Copyright (c) 2000-2012 the FFmpeg developers
  built on May  3 2012 11:40:38 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --e
nable-zlib
  libavutil      51. 49.100 / 51. 49.100
  libavcodec     54. 17.101 / 54. 17.101
  libavformat    54.  3.100 / 54.  3.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 72.104 /  2. 72.104
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 11.100 /  0. 11.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, flv, from 'input.flv':
  Duration: 00:00:37.00, start: 0.000000, bitrate: 366 kb/s
    Stream #0:0: Video: flv1, yuv420p, 320x240, 300 kb/s, 29.97 tbr, 1k tbn, 1k
tbc
    Stream #0:1: Audio: mp3, 22050 Hz, mono, s16, 56 kb/s
[buffer @ 01de98c0] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:fl
ags=2
[buffer @ 01dea4e0] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:fl
ags=2
[libx264 @ 02b067a0] using cpu capabilities: MMX2 Cache64
[libx264 @ 02b067a0] profile High, level 1.3
[libx264 @ 02b067a0] 264 - core 120 r2164 da19765 - H.264/MPEG-4 AVC codec - Cop
yleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
ma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_c
ompat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 we
ightb=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 'output1.mp4':
  Metadata:
    encoder         : Lavf54.3.100
    Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 320x240, q=-1--1, 3
0k tbn, 29.97 tbc
    Stream #0:1: Audio: aac (@[0][0][0] / 0x0040), 22050 Hz, mono, s16, 128 kb/s

Output #1, avi, to 'output2.avi':
  Metadata:
    ISFT            : Lavf54.3.100
    Stream #1:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 320x240, q=2-31, 200
 kb/s, 29.97 tbn, 29.97 tbc
    Stream #1:1: Audio: mp3 (U[0][0][0] / 0x0055), 22050 Hz, mono, s16
Stream mapping:
  Stream #0:0 -> #0:0 (flv -> libx264)
  Stream #0:1 -> #0:1 (mp3 -> libvo_aacenc)
  Stream #0:0 -> #1:0 (flv -> mpeg4)
  Stream #0:1 -> #1:1 (mp3 -> libmp3lame)
Press [q] to stop, [?] for help
frame=   48 fps=0.0 q=29.0 q=2.4 size=       8kB time=00:00:00.16 bitrate= 399.6
frame=   62 fps= 59 q=29.0 q=2.4 size=      32kB time=00:00:00.63 bitrate= 408.8
frame=   73 fps= 46 q=29.0 q=3.5 size=      57kB time=00:00:01.00 bitrate= 466.1
frame=  104 fps= 50 q=29.0 q=3.5 size=      87kB time=00:00:02.03 bitrate= 349.7
frame=  134 fps= 52 q=29.0 q=3.6 size=     113kB time=00:00:03.03 bitrate= 303.9
***frame=  150 fps= 49 q=29.0 q=2.4 size=     126kB time=00:00:03.57 bitrate= 289.3
frame=  150 fps= 42 q=29.0 q=8.8 size=     126kB time=00:00:03.57 bitrate= 289.3
frame=  150 fps= 37 q=29.0 q=6.9 size=     126kB time=00:00:03.57 bitrate= 289.3
frame=  150 fps= 33 q=29.0 q=9.7 size=     126kB time=00:00:03.57 bitrate= 289.3
frame=  150 fps= 29 q=29.0 q=6.0 size=     126kB time=00:00:03.57 bitrate= 289.3
frame=  150 fps= 27 q=29.0 q=11.2 size=     126kB time=00:00:03.57 bitrate= 289.***
frame=  150 fps= 24 q=29.0 Lq=11.0 size=     171kB time=00:00:04.93 bitrate= 283
.7kbits/s
video:1282kB audio:225kB global headers:0kB muxing overhead -88.650217%
[libx264 @ 02b067a0] frame I:1     Avg QP:10.27  size:    74
[libx264 @ 02b067a0] frame P:114   Avg QP:23.49  size:   727
[libx264 @ 02b067a0] frame B:35    Avg QP:29.30  size:   124
[libx264 @ 02b067a0] consecutive B-frames: 68.0%  2.7%  0.0% 29.3%
[libx264 @ 02b067a0] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 02b067a0] mb P  I16..4:  2.1%  3.2%  0.1%  P16..4: 19.2%  5.1%  3.6%
 0.0%  0.0%    skip:66.6%
[libx264 @ 02b067a0] mb B  I16..4:  0.2%  0.5%  0.0%  B16..8:  9.6%  1.2%  0.4%
 direct: 0.6%  skip:87.4%  L0:46.1% L1:42.5% BI:11.4%
[libx264 @ 02b067a0] 8x8 transform intra:51.7% inter:78.4%
[libx264 @ 02b067a0] coded y,uvDC,uvAC intra: 29.8% 44.5% 10.3% inter: 8.9% 10.3
% 2.2%
[libx264 @ 02b067a0] i16 v,h,dc,p: 52% 31% 16%  1%
[libx264 @ 02b067a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 25% 45%  1%  0%  1%  0%
 1%  3%
[libx264 @ 02b067a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 48% 23%  2%  1%  2%  3%
 2%  1%
[libx264 @ 02b067a0] i8c dc,h,v,p: 54% 26% 16%  3%
[libx264 @ 02b067a0] Weighted P-Frames: Y:2.6% UV:0.9%
[libx264 @ 02b067a0] ref P L0: 79.8%  7.0%  9.6%  3.6%  0.0%
[libx264 @ 02b067a0] ref B L0: 92.5%  6.7%  0.8%
[libx264 @ 02b067a0] ref B L1: 96.8%  3.2%
[libx264 @ 02b067a0] kb/s:139.51

D:\ffmpeg\bin>

使所有输出文件大小相同的正确语法如何?

这不是ffmpeg的错误吗?(注意转换进度的最后几行,所有时间戳看起来都一样)

提前致谢。

4

2 回答 2

4

您需要为每个输出添加输出选项:

ffmpeg -i input.flv -t 5 output1.mp4 -t 5 output2.avi

考虑为输出质量添加一个附加选项——特别是对于 avi,因为 libx264(如果可用)是 mp4 的默认值,而 libx264 的默认选项是正常的。

ffmpeg -i input.flv -t 5 output1.mp4 -t 5 -qscale 3 output2.avi

有关(也称为)的更多信息,请参阅FFmpeg:终极视频和音频操作工具。-qscale-q:v

于 2012-06-05T18:29:35.033 回答
0

为了省去指定每个文件名的麻烦,您可以使用 FOR 循环。这会将所有 flv 和 mp4 文件保存为 avi 文件,并将其原始文件名保存到“NEW”文件夹中。在 bat/cmd 文件中使用:

md NEW
FOR /F "tokens=*" %%G IN ('dir /b *.flv') DO ffmpeg -y -i "%%G" -t 5 "NEW\%%~nG.avi"
FOR /F "tokens=*" %%G IN ('dir /b *.mp4') DO ffmpeg -y -i "%%G" -t 5 "NEW\%%~nG.avi"
于 2022-01-21T11:55:25.297 回答