[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 6# thp2008
  1. setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in ('dir /b/s/a-d "%~dp0*.mp4"') do (
  3. for /f "tokens=2 delims=: " %%a in ('ffmpeg -i "%%i" 2^>^&1 ^| find "lasttimestamp"') do set /a str=%%a/10
  4. set BianLiang=!str!
  5. if 1==1 (
  6. set file=%%i
  7. set out=%%~dpni
  8. :loop
  9. set /a n+=1
  10. ffmpeg -i "!file!" -ss !BianLiang! -frames:v 1 "!out!0!n!.png"
  11. set /a BianLiang=!str!+!BianLiang!
  12. if not "!n!"=="9" goto :loop
  13. )
  14. set n=
  15. )
复制代码

TOP

H:\1>setlocal enabledelayedexpansion

H:\1>for /F "delims=" %i in ('dir /b/s/a-d "H:\1\*.mp4"') do (
for /F "tokens=2 delims=: " %a in ('ffmpeg -i "%i" 2>&1 | find "lasttimestamp"') do set /a str=%a/9
set BianLiang=!str!
if 1 == 1 (
set /a n+=1
ffmpeg.exe -i "%i" -ss !BianLiang! -frames:v 1 "%~dpni0!n!.png"
set /a BianLiang=!str!+!BianLiang!
if not "!n!" == "9" goto :loop
)
set n=
)

H:\1>(
for /F "tokens=2 delims=: " %a in ('ffmpeg -i "H:\1\232.mp4" 2>&1 | find "lasttimestamp"') do set /a str=%a/9
set BianLiang=!str!
if 1 == 1 (
set /a n+=1
ffmpeg.exe -i "H:\1\232.mp4" -ss !BianLiang! -frames:v 1 "H:\1\2320!n!.png"
set /a BianLiang=!str!+!BianLiang!
if not "!n!" == "9" goto :loop
)
set n=
)
ffmpeg version 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.3.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57.  4.101 / 57.  4.101
  libavcodec     59.  7.102 / 59.  7.102
  libavformat    59.  5.100 / 59.  5.100
  libavdevice    59.  0.101 / 59.  0.101
  libavfilter     8.  7.101 /  8.  7.101
  libswscale      6.  1.100 /  6.  1.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'H:\1\232.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.35.100
  Duration: 00:10:20.48, start: 0.000000, bitrate: 1823 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1621 kb/s, 59.97 fps, 59.97 tbr, 383839 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 188 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'H:\1\23201.png':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.5.100
  Stream #0:0(und): Video: png, rgb24, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 59.97 fps, 59.97 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.7.102 png
frame=    0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=   0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
运算符不存在。

H:\1>set /a n+=1

H:\1>ffmpeg.exe -i "%i" -ss !BianLiang! -frames:v 1 "%~dpni0!n!.png"
ffmpeg version 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.3.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57.  4.101 / 57.  4.101
  libavcodec     59.  7.102 / 59.  7.102
  libavformat    59.  5.100 / 59.  5.100
  libavdevice    59.  0.101 / 59.  0.101
  libavfilter     8.  7.101 /  8.  7.101
  libswscale      6.  1.100 /  6.  1.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
%i: No such file or directory

H:\1>set /a BianLiang=!str!+!BianLiang!
运算符不存在。

H:\1>if not "!n!" == "9" goto :loop

H:\1>set /a n+=1

H:\1>ffmpeg.exe -i "%i" -ss !BianLiang! -frames:v 1 "%~dpni0!n!.png"
ffmpeg version 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.3.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57.  4.101 / 57.  4.101
  libavcodec     59.  7.102 / 59.  7.102
  libavformat    59.  5.100 / 59.  5.100
  libavdevice    59.  0.101 / 59.  0.101
  libavfilter     8.  7.101 /  8.  7.101
  libswscale      6.  1.100 /  6.  1.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
%i: No such file or directory

H:\1>set /a BianLiang=!str!+!BianLiang!
运算符不存在。

TOP

本帖最后由 thp2008 于 2021-9-9 17:37 编辑

回复 4# idwma


    你好,感谢您的帮助,代码写的真好,这么精简。
运行出错了,1,是第8行,ffmpeg.exe后面多了个双引号,我去掉了。
2,还是报错,好像是计算的问题,另外可能,是那个时间变量,是00:50:23:28   而ffmpeg.exe 只能使用 00:50:23  。请帮我把最后的毫秒去掉。

TOP

本帖最后由 idwma 于 2021-9-9 17:13 编辑

回复 3# Batcher


    这样呀那改成用秒来算
  1. setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in ('dir /b/s/a-d "%~dp0*.mp4"') do (
  3. for /f "tokens=2 delims=: " %%a in ('ffmpeg -i "%%i" 2^>^&1 ^| find "lasttimestamp"') do set /a str=%%a/10
  4. set BianLiang=!str!
  5. if 1==1 (
  6. :loop
  7. set /a n+=1
  8. ffmpeg.exe" -i "%%i" -ss !BianLiang! -frames:v 1 "%%~dpni0!n!.png"
  9. set /a BianLiang=!str!+!BianLiang!
  10. if not "!n!"=="9" goto :loop
  11. )
  12. set n=
  13. )
复制代码

TOP

回复 2# idwma


    00:!BianLiang!:00 是不是没有考虑超过60分钟的视频?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 idwma 于 2021-9-9 16:01 编辑
  1. setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in ('dir /b/s/a-d "%~dp0*.mp4"') do (
  3. for /f "tokens=2,3 delims=,: " %%a in ('ffmpeg -i "%%i" 2^>^&1 ^| find "Duration:"') do set /a str=(%%a*60+%%b)/9
  4. set BianLiang=!str!
  5. if 1==1 (
  6. :loop
  7. set /a n+=1
  8. ffmpeg.exe" -i "%%i" -ss 00:!BianLiang!:00 -frames:v 1 "%%~dpni0!n!.png"
  9. set /a BianLiang=!str!+!BianLiang!
  10. if not "!n!"=="9" goto :loop
  11. )
  12. set n=
  13. )
复制代码

TOP

返回列表