首页 > 代码库 > 用mplayer从视频中按周期提取帧

用mplayer从视频中按周期提取帧

使用方法:extract file time step folder

time 设置时间长度

step 设置周期

均以秒(s)为单位

 

贡献:1. 从视频文件中周期性提取图片;2. Windows下批处理程序的一些技术。

依赖:mplayer

todo: 目前周期最小为1s,可以扩展使频率大于1Hz.

 

更详细的内容可以参考:

http://blog.csdn.net/xuyaqun/article/details/6077917

http://blog.csdn.net/aa846555831/article/details/53400974

http://blog.csdn.net/yjfkpyu/article/details/3694990

 1 @echo off 2  3 :: extract frames 4 rem echo filename: %1 5 rem echo time: %2 s 6 rem echo step: %3 s 7 rem echo folder: %4  8  9 if "%4" equ "" (10   echo Usage: extract file time step folder11   echo   file: mplayer can play12   echo   time unit: s13   echo   step unit: s14   echo   folder: snap saved folder 15   goto :end16 )17 18 if not exist %4 mkdir %419 20 set /A length = %2 / %321 echo length: %length%22 23 setlocal enabledelayedexpansion  24 25 set n=026 for /L %%i in (0, %3, %2) do (27   :: progress info28   set /A n += 129   set /A n = !n! %% 1030   if !n! equ 0 (31     set /A nth = %%i * 100 / %2 32     echo !nth! %%33   )34 35   :: key command36   mplayer -ss %%i -noframedrop -nosound -vo png -frames 1 %1 > nul37 38   :: save files because mplayer extracts frame in same name39   set /A name = %%i / %340   move 00000001.png %4\!name!.png  > nul41 )42 43 :end

 

用mplayer从视频中按周期提取帧