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命令的標準輸入中“劫持”數(shù)據。

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...
# ...
我編寫了一門課程,其中包含有關此主題的更多詳細信息和重復出現(xiàn)的錯誤,但不幸的是,使用法語:)
要回答原始問題,您可以使用類似以下內容的內容:
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
添加回答
舉報