3 回答

TA贡献1895条经验 获得超3个赞
警告:我从来没有用过ffmpeg,但与有关程序的其他问题的工作,看起来像ssh,ffmpeg从标准输入读取实际上并没有使用它,所以在第一次调用Convert时消耗的文件列表的其余部分后read获得的第一个线。尝试这个
Convert() {
ffmpeg -i "$1" -vcodec mpe4 -sameq -acodec aac \
-strict experimental "$1.mp4" < /dev/null
}
这样,ffmpeg就不会从用于read命令的标准输入中“劫持”数据。

TA贡献1797条经验 获得超6个赞
[...]
for i in `cat list.txt`
切勿使用以下语法:
for i in $(command); do ...; done # or
for i in `command`; do ...; done
此语法逐字读取命令的输出,而不是逐行读取命令的输出,这经常会导致意外的问题(例如,当行包含一些空格时,以及当您想读取诸如项之类的行时)。
总会有一个更聪明的解决方案:
command|while read -r; do ...; done # better general case to read command output in a loop
while read -r; do ...; done <<< "$(command)" # alternative to the previous solution
while read -r; do ...; done < <(command) # another alternative to the previous solution
for i in $DIR/*; do ...; done # instead of "for i in $(ls $DIR); do ...; done
for i in {1..10}; do ...; done # instead of "for i in $(seq 1 10); do ...; done
for (( i=1 ; i<=10 ; i++ )); do ...; done # such that the previous command
while read -r; do ...; done < file # instead of "cat file|while read -r; do ...; done"
# dealing with xargs or find -exec sometimes...
# ...
我编写了一门课程,其中包含有关此主题的更多详细信息和重复出现的错误,但不幸的是,使用法语:)
要回答原始问题,您可以使用类似以下内容的内容:
Convert() {
ffmpeg -i “$1” -vcodec mpe4 -sameq -acodec aac -strict experimental “$1.mp4”
}
Convert_loop(){
while read -r; do
Convert $REPLY
done < $1
}
Convert_loop list.txt

TA贡献1911条经验 获得超7个赞
吻!=)
convert() {
ffmpeg -i "$1" \
-vcodec mpe4 \
-sameq -acodec aac \
-strict experimental "${1%.*}.mp4"
}
while read line; do
convert "$line"
done < list.txt
添加回答
举报