2

I'm a newbie to linux scripting and am having an issue with a script that I got from the web and am trying to modify.

Here is the script

#!/bin/bash
if (($# ==0))
then
    echo "Usage: flvto3gp [flv files] ..."
    exit
fi

while (($# !=0 ))
do 
    ffmpeg -ss 00:00:10 -t 1 -s 400x300 -i $1 -f mjpeg   /home/zavids/rawvids/thumbs/$1.jpg
    shift
done
echo "Finished"
echo "\"fakap all those nonsense!\""
echo ""

So I'm grabbing a screenshot from a video and saving it as a jpeg. The problem is the extension of the video file is retained so finished file is video.flv.jpg (for example). How can I get rid of that video extension?

4

2 回答 2

2

更改此行

ffmpeg -ss 00:00:10 -t 1 -s 400x300 -i $1 -f mjpeg   /home/zavids/rawvids/thumbs/$1.jpg

对此

ffmpeg -ss 00:00:10 -t 1 -s 400x300 -i $1 -f mjpeg /home/zavids/rawvids/thumbs/${1%.*}.jpg

这会在使用bash参数扩展创建输出文件的名称之前从输入文件中删除扩展名。

于 2012-06-22T13:38:20.163 回答
0

你可以尝试使用这个:

${string%substring}

它从 $string 后面删除 $substring 的最短匹配。

对于您的情况:

${1%.flv}

此代码将从您的第一个参数的末尾替换 .flv。

您也可以在这里获得很多详细信息:http: //tldp.org/LDP/abs/html/string-manipulation.html

于 2012-06-22T13:39:10.270 回答