原视频:a.mp4 帧率:60 时长:17''
使用命令 ffmpeg -i a.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 /tmp_frames/frame%08d.jpg 将视频的所有帧都提取出来,得到: 1044 张图片;
然后用 python 脚本优化处理这1044张图片,并存在 out_frames 中,得到 1044 张图片;
使用命令:ffmpeg -i out_frames/out_frame%08d.jpg -i a.mp4 -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r 60 -pix_fmt yuv420p output_a.mp4
得到: 新视频:output_a.mp4 帧率:60 时长:17''
得到: 新视频:output_a.mp4 帧率:60 时长:44''
为什么指定了帧率,时长不能跟原视频一样(视频时长不对,但音频时长是对的),要如何处理才能与期望值相符;搜索也问了 gpt ,它要求加上 -t 参数,但 -t 参数只是截取前 17'',会导致视频不完整
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 15.0.0 (clang-1500.0.40.1)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Input #0, image2, from '/Users/XXXX/Documents/out_frames/out_frame%08d.jpg':
Duration: 00:00:41.76, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1000x1770 [SAR 1:1 DAR 100:177], 25 fps, 25 tbr, 25 tbn
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'test.MP4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
comment : vid:v0300fg10000cn42qhrc77u6heiifl6g
encoder : Lavf58.76.100
Duration: 00:00:17.44, start: 0.000000, bitrate: 1571 kb/s
Stream #1:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 720x1280 [SAR 1:1 DAR 9:16], 1431 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #1:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Stream #1:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[image2 @ 0x144104080] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[swscaler @ 0x130658000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x148320000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x1381c8000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x148320000] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x144011220] using SAR=1/1
[libx264 @ 0x144011220] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x144011220] profile High, level 4.2, 4:2:0, 8-bit
[libx264 @ 0x144011220] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - 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=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=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output_test.MP4':
Metadata:
encoder : Lavf60.3.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown, progressive), 1000x1770 [SAR 1:1 DAR 100:177], q=2-31, 60 fps, 15360 tbn
Metadata:
encoder : Lavc60.3.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
[vost#0:0/libx264 @ 0x144010f50] More than 1000 frames duplicated
frame= 2505 fps=130 q=-1.0 Lsize= 90004kB time=00:00:41.70 bitrate=17681.4kbits/s dup=1461 drop=0 speed=2.17x
video:89684kB audio:273kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.052407%
[libx264 @ 0x144011220] frame I:11 Avg QP:27.17 size:669305
[libx264 @ 0x144011220] frame P:631 Avg QP:30.57 size:107758
[libx264 @ 0x144011220] frame B:1863 Avg QP:36.59 size: 8845
[libx264 @ 0x144011220] consecutive B-frames: 0.8% 0.1% 0.1% 99.0%
[libx264 @ 0x144011220] mb I I16..4: 7.3% 20.1% 72.5%
[libx264 @ 0x144011220] mb P I16..4: 0.2% 0.2% 3.9% P16..4: 20.9% 12.1% 17.0% 0.0% 0.0% skip:45.7%
[libx264 @ 0x144011220] mb B I16..4: 0.0% 0.0% 0.1% B16..8: 11.7% 2.5% 2.3% direct: 0.7% skip:82.6% L0:55.3% L1:41.7% BI: 3.0%
[libx264 @ 0x144011220] 8x8 transform intra:10.0% inter:9.4%
[libx264 @ 0x144011220] coded y,uvDC,uvAC intra: 91.4% 0.0% 0.0% inter: 7.6% 0.0% 0.0%
[libx264 @ 0x144011220] i16 v,h,dc,p: 72% 3% 21% 4%
[libx264 @ 0x144011220] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 4% 54% 3% 2% 4% 1% 6% 1%
[libx264 @ 0x144011220] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 9% 23% 5% 4% 7% 3% 8% 5%
[libx264 @ 0x144011220] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 0x144011220] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x144011220] ref P L0: 57.5% 7.5% 20.6% 14.5%
[libx264 @ 0x144011220] ref B L0: 81.5% 11.8% 6.7%
[libx264 @ 0x144011220] ref B L1: 98.3% 1.7%
[libx264 @ 0x144011220] kb/s:17597.24
1
xtreme1 288 天前
试试不用 -r
-vf "fps=60,format=yuv420p" |
2
misdake 288 天前
-r 写在-i 前面试试
|
4
jifengg 288 天前
@craiiz 不是“居然会有影响”,而是意义不一样。
你看你贴的日志,Input #0 那里,是不是显示的 “mjpeg **** 25fps”,因为你这个输入是一个“图片序列”,本身没有帧率信息,你不指定,ffmpeg 用了默认 25 ,要在 -i 前面指定它的帧率; 而输出文件前面的 -r ,是指要把输入帧率转成这个帧率,不管输入是 1fps 、25fps 、60fps 、120fps ; ffmpeg 的参数顺序是很重要的,特别是在 -i 前后,意义完全不一样。 比如你要从一个 60 分钟的视频中,第 30 分钟的地方,截取 10 秒 视频 ffmpeg -i 60min.mp4 -ss 600 -t 10 -c copy out.mp4 ffmpeg -ss 600 -t 10 -i 60min.mp4 -c copy out.mp4 你会发现 -ss 和 -t 写在 -i 前面的会快很多。 -i 前面的和源相关的参数,是用来“描述”这个源的,所有的 -i 后面的参数,才是用来指定输出参数的。 ffmpeg 是支持一个命令里多个输入多个输出的,所以参数的位置很重要。 |