bash变量与ffmpeg循环变化 [英] bash variable changes in loop with ffmpeg
问题描述
我写了一个skript,以便根据我在时间戳上记录的视频快速创建简短的预览剪辑,我发现以后值得进行剪辑. 我的带有时间戳的文件是这样写的
I wrote a skript to quickly create short preview clips from vides I recorded on timestamps that I found worth checking out later for cutting. My file with the timestamps is written like this
FILE_NAME1#MM:SS MM:SS
FILE_NAME2#MM:SS MM:SS MM:SS MM:SS
示例:
MAH01728#02:47 03:34 03:44 05:00 06:08 06:55
脚本如下:
#!/bin/bash
while read f
do
file=$(echo $f | cut -d"#" -f1)
filename=${file}".MP4"
timestamps=$(echo $f | cut -d"#" -f2)
for time in $timestamps
do
ffmpeg -ss 00:${time}.0 -i "orig/${filename}" -c copy -t 10 "preview/${file}_${time}.MP4"
done
done < $1
脚本获得了我想要的预览的一半,另一方面,文件名被弄乱了,ffmpeg抱怨找不到文件:
The script gets half of the previews that I want and on the other the filename is messed up and ffmpeg complains that the file is not found:
orig/714.MP4: No such file or directory
orig/00:58 01:25.MP4: No such file or directory
因此,我修改了脚本以进行故障排除,只是在ffmpeg命令前添加了回显-现在所有文件名都是正确的.我想念什么?
So I modified the script for trouble shooting and just put an echo in front of the ffmpeg command - now all file names are correct. What am I missing?
ffmpeg -ss 00:01:47.0 -i orig/MAH01714.MP4 -c copy -t 10 preview/MAH01714_01:47.MP4
ffmpeg -ss 00:02:00.0 -i orig/MAH01713.MP4 -c copy -t 10 preview/MAH01713_02:00.MP4
ffmpeg -ss 00:00:58.0 -i orig/MAH01712.MP4 -c copy -t 10 preview/MAH01712_00:58.MP4
ffmpeg -ss 00:01:25.0 -i orig/MAH01712.MP4 -c copy -t 10 preview/MAH01712_01:25.MP4
推荐答案
ffmpeg
从标准输入中读取,使用来自$1
的数据,该数据是为循环顶部的read
命令使用的.从/dev/null
重定向其标准输入:
ffmpeg
reads from standard input, consuming data from $1
that was intended for the read
command at the top of the loop. Redirect its standard input from /dev/null
:
while IFS="#" read file timestamps; do
filename="$file.MP4"
for time in $timestamps; do
ffmpeg -ss 00:${time}.0 -i "orig/${filename}" \
-c copy -t 10 "preview/${file}_${time}.MP4" < /dev/null
done
done < "$1"
echo
不会从标准输入中读取 ,这就是为什么您所做的修改使它看起来可以正常工作的原因.
echo
does not read from standard input, which is why your modification made it appear to be working correctly.
这篇关于bash变量与ffmpeg循环变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!