对于ffmpeg的转换bash脚本不循环 [英] bash script for ffmpeg conversion does not loop

查看:205
本文介绍了对于ffmpeg的转换bash脚本不循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些mp4文件批量转换这个bash脚本:

 #!/斌/庆典
LS博士* .MP4 | grep的-v -E\\。[^ \\。] + \\。 | SEDS / .MP4 // G|而读˚F

    TARGET =$ f.ffmpeg.mp4
    如果! [-f $ TARGET]
    然后
        回声$ TARGET
        ffmpeg的-nostdin -i $ f.mp4 -s看见320×180 -vc H264 -a codeC副本-f MP4 -y $ TARGET
    科幻    TARGET =$ f.ffmpeg.flv
    如果! [-f $ TARGET]
    然后
        回声$ TARGET
        ffmpeg的-nostdin -i $ f.mp4 -s看见320×180 -a codeC副本-y $ TARGET
    科幻    TARGET =$ f.jpg
    如果! [-f $ TARGET]
    然后
        回声$ TARGET
        ffmpeg的-nostdin -i $ f.ffmpeg.mp4 -ss 0 -vframes 1 -f IMAGE2 $ TARGET
    科幻    TARGET =$ f.ffmpeg.ogv
    如果! [-f $ TARGET]
    然后
        回声$ TARGET
        ffmpeg的-nostdin -i $ f.mp4 -s 320x176 -ar 11025 -a codeC libvorbis -y $ TARGET
    科幻
DONE

它运行一次,但不与输入的文件名转换成4个不同的格式,但循环不到下一个输入文件名。
我试图洗牌各种转换的顺序,但仍运行该脚本正好一次一个文件名。
我试图与-nostdin标志运行的ffmpeg,但它说

 无法识别选项'nostdin'

FFmpeg的版本的ffmpeg版本0.10.6-6:0.10.6-0ubuntu0jon1〜lucid2 - 我刚从的 http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu 并不能找到一个新的版本。基本系统是

 经销商ID:Ubuntu的
说明:Ubuntu的LTS 10.04.1
稿:10.04
codeNAME:明晰


解决方案

不解析的输出 LS ,您可以使用水珠兵来代替。你也应该引用您的变量在文件名来解释可能的空白:

 在医生输入* .MP4;做
    输出= $ {输入%.MP4} .ffmpeg.mp4
    [-f$ {}输出] || ffmpeg的-nostdin -i$ {}输入-s看见320×180 -vc H264 -a codeC副本-f MP4 -y$ {}输出    输出= $ {输入%.MP4} .ffmpeg.flv
    [-f$ {}输出] || ffmpeg的-nostdin -i$ {}输入-s看见320×180 -a codeC副本-y$ {}输出    [...]
DONE

至于你的错误,根据更新日志中的 -nostdin ffmpeg的1.0 ,所以你需要更新你的的ffmpeg 安装从 0.1× 1.0.x的

I have this bash script for a batch conversion of some mp4 files:

#!/bin/bash
ls dr*.mp4 | grep -v -E "\.[^\.]+\." | sed "s/.mp4//g" | while read f 
do
    TARGET="$f.ffmpeg.mp4"
    if ! [ -f $TARGET ]
    then
        echo $TARGET
        ffmpeg  -nostdin -i $f.mp4 -s 320x180 -vc h264 -acodec copy -f mp4 -y $TARGET
    fi

    TARGET="$f.ffmpeg.flv"
    if ! [ -f $TARGET ]
    then
        echo $TARGET
        ffmpeg  -nostdin -i $f.mp4 -s 320x180 -acodec copy -y $TARGET
    fi

    TARGET="$f.jpg"
    if ! [ -f $TARGET ]
    then
        echo $TARGET
        ffmpeg -nostdin -i $f.ffmpeg.mp4 -ss 0 -vframes 1 -f image2 $TARGET
    fi

    TARGET="$f.ffmpeg.ogv"
    if ! [ -f $TARGET ]
    then
        echo $TARGET
        ffmpeg  -nostdin -i $f.mp4 -s 320x176 -ar 11025 -acodec libvorbis -y $TARGET
    fi
done 

It runs once but does and converts the input file name to 4 different formats, but does not loop to the next input file name. I tried to shuffle the order of the various conversions, but still the script runs exactly once for one file name. I tried to run ffmpeg with the -nostdin flag, but it says

"Unrecognized option 'nostdin'"

The ffmpeg version is ffmpeg version 0.10.6-6:0.10.6-0ubuntu0jon1~lucid2 - I just update the ffmpeg package from http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu and cannot find an newer version. The base system is

Distributor ID: Ubuntu 
Description:    Ubuntu 10.04.1 LTS 
Release:        10.04 
Codename:       lucid

解决方案

Don't parse the Output of ls, you can use globbing instead. You should also quote your variables to account for possible whitespace in the filenames:

for input in dr*.mp4; do
    output=${input%.mp4}.ffmpeg.mp4
    [ -f "${output}" ] || ffmpeg -nostdin -i "${input}" -s 320x180 -vc h264 -acodec copy -f mp4 -y "${output}"

    output=${input%.mp4}.ffmpeg.flv
    [ -f "${output}" ] || ffmpeg -nostdin -i "${input}" -s 320x180 -acodec copy -y "${output}"

    [...]
done

As for the error you get, according to the ChangeLog the -nostdin option got added in ffmpeg 1.0, so you need update your ffmpeg installation from 0.1x to 1.0.x.

这篇关于对于ffmpeg的转换bash脚本不循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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