FFmpeg脚本跳过文件 [英] FFmpeg script skips files

查看:295
本文介绍了FFmpeg脚本跳过文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Shell脚本来转换许多视频文件,并在文件名后附加一些内容来保存它们.该脚本有效,但似乎会随机跳过文件,并且其中很多.

I wrote a shell script to convert many video files and save them with something appended to the file name. The script works, but it seems to randomly skip files, and a lot of them.

当我重新运行脚本时,它将转换之前跳过的文件.我如何才能停止跳过文件?

When I re-run the script, it will convert files it skipped before. How can I get it to stop skipping files?

workingDir=/home/user/Videos

# get list of files to convert
find /video/folder -iname "*.mp4" > $workingDir/file_list

# convert files
cat $workingDir/file_list | while read LINE; do
    # FFmpeg often cuts off the beginning of this line
    echo "$(dirname "$LINE")/$(basename "$LINE")"
    if /usr/bin/ffmpeg -n -loglevel panic -v quiet -stats -i "$LINE" \
        -c:v libx264 -vf scale="trunc(oh*a/2)*2:320" \
        -pix_fmt yuv420p -preset:v slow -profile:v main -tune:v animation -crf 23 \
        "$(dirname "$LINE")/$(basename "$LINE" \.mp4)"_reencoded.mp4 2>/dev/null; then
            echo "Success: $(dirname "$LINE")/$(basename "$LINE")" >> $workingDir/results
    else
        echo "Failed:  $(dirname "$LINE")/$(basename "$LINE")" >> $workingDir/results
    fi
done

一个问题似乎是FFmpeg干扰了脚本. FFmpeg输出通常会切断下一个命令的开头,即使未显示输出也是如此.通过if语句之前的回显线可以证明这一点,该语句通常被切断.但是,即使对于没有中断的行,大多数情况也会被无缘无故地跳过.

One problem seems to be that FFmpeg interferes with the script. The FFmpeg output often cuts off the beginning of the next command, even if the output is not shown. This is demonstrated by the echo line before the if statement, which is often cut off. But even for lines that aren't cut off, most of them will be skipped for no apparent reason.

推荐答案

ffmpeg从stdin读取,从而消耗了while read的输入.只需通过添加< /dev/null

ffmpeg reads from stdin, thereby consuming input meant for while read. Just redirect stdin for ffmpeg by adding < /dev/null

这篇关于FFmpeg脚本跳过文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆