【问题标题】:Windows Batch File: for /F read only first line of mylist.txt and delete first line afterwardsWindows 批处理文件:for /F 只读 mylist.txt 的第一行,然后删除第一行
【发布时间】:2018-05-20 02:54:01
【问题描述】:

我运行一个批处理脚本:

FOR /F "tokens=1" %%F IN (mylist.txt) do C:\VideoConverter\Applications\ffmpeg.exe ^
-f image2 -loop 1 -framerate 0.1 -i "%%~F" -i "%~dpn1.mp3" -codec:v libx264 ^
-s 1920x1080 -acodec copy -strict experimental -movflags faststart -t 00:10:10.00 ^
-f mp4 "%~dpn1.mp4"

在我的文件夹中有以下文件:

file001.mp3
file002.mp3
file003.mp3

mylist.txt 包含:

pic001.jpg 
pic002.jpg 
pic003.jpg

目前,该脚本为文件夹中的每个 mp3 创建了 3 个具有 3 个不同背景图像的视频。这是错误的。

我只想制作这三个视频。

video 1 = file001.mp3 + pic001.jpg (line1) 
video 2 = file002.mp3 + pic002.jpg (line2)
video 3 = file003.mp3 + pic003.jpg (line3)

有人可以帮助我使用 for /f 命令吗?感谢您的帮助。

【问题讨论】:

  • 请按照与上一个代码块的格式相同的方式格式化多行代码和数据。

标签: windows batch-file ffmpeg command


【解决方案1】:

我会使用 for 循环播放视频,通过标准输入将 mylist.txt 推入 for 循环(使用 <),然后让 set /p 逐行捕获它(每个循环一次迭代)。像这样的:

@echo off & setlocal

(
    for %%I in (*.mp3) do (

        rem // set /P grabs one line of input from stdin
        set /P "imagefile="

        setlocal enabledelayedexpansion
        if defined imagefile call :build "%%~I" "!imagefile!" "%%~dpnI.mp4"
        endlocal

        set "imagefile="
    )
) < mylist.txt
rem // The line above dumps mylist.txt into stdin, letting set /P grab one line at a time.

goto :EOF

:build <in_mp3> <in_image> <outfile>
C:\VideoConverter\Applications\ffmpeg.exe -f image2 -loop 1 -framerate 0.1 ^
-i "%~1" -i "%~2" -codec:v libx264 -s 1920x1080 -acodec copy -strict experimental ^
-movflags faststart -t 00:10:10.00 -f mp4 "%~3"

【讨论】:

  • 考虑到mylist.txt 也已排序,那么for /F "delims= eol=|" %%I in ('dir /B /A:-D /O:N *.mp3) 如何保证正确的排序顺序?
  • 我更改了-i "%~1" -i "%~2" with -i "%~2" -i "%~1",它成功了。非常感谢您的帮助:)
  • @aschipfl 我必须做一些测试,看看是否需要进一步修改代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-12
  • 1970-01-01
  • 1970-01-01
  • 2016-09-13
  • 2010-12-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多