assign date and time to output file

2019-02-28 11:31发布

i am working on ffmpeg screen capture and i wan't it to start recording on start up, so i need to give the output video file a name that is different every time i start recording i did find this question very close to what i need, so i ended up with this commands in a batch file:

@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/" %%a in ('time /t') do (set mytime=%%a%%b)

cd /d E:\ffmpeg\bin

ffmpeg -f dshow -i video="screen-capture-recorder"
-c:v libx264 -r 10 -crf 37 -pix_fmt yuv420p E:\%mydate%_%mytime%.flv

now i get an error in ffmpeg cmd: [NULL @ 0270d2c01] Unable to find a suitable output format for 'E:-04-2014_02:35'

E:-04-2014_02:35 Invalid argument

i know it because the special characters in mytime : but i don't know how to change it.

1条回答
手持菜刀,她持情操
2楼-- · 2019-02-28 12:25

**edited to separate date and time with _

If you only need it for unique filenames, don't mess around with the special chars and localized format. You can use:

for /f "tokens=2 delims==" %%i in ('wmic os get localdatetime /value') do set DateTime=%%i
set DateTime=%DateTime:~0,8%_%DateTime:~8,6%
REM or:    set filename=%DateTime:~0,8%_%DateTime:~8,6%.flv
echo %DateTime%

EDIT to "the problem is the file name is like this 20140204_161529 and i wan't it to be like that 2014_02_04_16_15_29" : Use this inside the forloop:

set oldfilename=%DateTime:~0,8%_%DateTime:~8,6%.flv
set newfilename=%DateTime:~0,4%_%DateTime:~4,2%_%DateTime:~6,2%_%DateTime:~8,2%_%DateTi‌​me:~10,2%_%DateTime:~12,2%.flv
查看更多
登录 后发表回答