尝试获取目录中的每个 mp4 文件,并批量保存其第一帧的 PNG。
我在用着:
ffmpeg -i filename.mp4 -vf "select=eq(n\,0)" -vframes 1 filename.png
当我这样做时,它会正确保存每个文件的第一帧,但它们会拉伸成正方形。
输入为 607x1080 输出为 1080x1080
并非所有输入都具有相同的纵横比,因此我无法对其进行硬编码。我只想保留原始文件的纵横比和尺寸。
有任何想法吗?
编辑:这是输出:
> ffmpeg -i connecting-to-senses-explainer-1.mp4 -vf "select=eq(n\,0)" -vframes 1 output.png
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.5 (clang-1205.0.22.9)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/4.4_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --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-avresample --enable-videotoolbox
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'connecting-to-senses-explainer-1.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: mp42iso2avc1mp41
creation_time : 2021-10-13T22:25:00.000000Z
encoder : HandBrake 1.4.2 2021100300
Duration: 00:00:10.00, start: 0.000000, bitrate: 131 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1080x1080 [SAR 9:16 DAR 9:16], 128 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2021-10-13T22:25:00.000000Z
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> png (native))
Press [q] to stop, [?] for help
[swscaler @ 0x1308c0000] No accelerated colorspace conversion found from yuv420p to rgb24.
Output #0, image2, to 'output.png':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: mp42iso2avc1mp41
encoder : Lavf58.76.100
Stream #0:0(und): Video: png, rgb24(pc, bt709, progressive), 1080x1080 [SAR 9:16 DAR 9:16], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
Metadata:
creation_time : 2021-10-13T22:25:00.000000Z
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc58.134.100 png
frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed= 1.3x
video:110kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown