E
E
Evgeny Elizarov2012-03-26 22:02:09
bash
Evgeny Elizarov, 2012-03-26 22:02:09

Help debug video autoconverter on bash pliz

Gentlemen, I'm trying to write a script that would check for the presence of an already converted file in a given folder and, if not, encode it. It will probably be easier to understand what I mean by the code.
pastebin.com/C7aG2LEQ

The problem is in line 12, for some reason the check of an existing file skips, as a result it tries to encode it again, which in general I don’t need to do at all, because there are a lot of files there. Plz tell me what is wrong

Answer the question

In order to leave comments, you need to log in

4 answer(s)
@
@sledopit, 2012-03-26
@KorP

M, how do you have some other commands between the if and then lines?

if 
then  
echo "$i.mp4 not exist" 
echo "Converting "$i"." 
/usr/local/bin/ffmpeg -i ${video_folder}$i.mkv -acodec aac -strict experimental -ab 128k -ac 2 -vcodec libx264 -b 1200k -s 1280x720 -r 30 -threads 0                 ${films_folder}$i.mp4 ; echo "Convert "$i" to mp4 is done!"
fi

So everything is ok.
Well, I'll tinker a bit more:
for i in `ls -a $video_folder/*$file_mask*.mkv`

Never do that, you hear? Never! Suddenly you have spaces in your name and all sorts of non-printable characters?
for i in $video_folder/*$file_mask*.mkv

That's right.
i=$(echo $i | sed 's/.mkv//' | sed 's%^.*/%%')

omg. what the hell is sed here?
echo ${i/.mkv}

handle everything just fine.
Well, else with shift is completely unnecessary here.

P
Petr0vich, 2012-03-26
@Petr0vich

Why double square brackets?

E
egorinsk, 2012-03-27
@egorinsk

A Bash script in 99% of cases should start with set -e. It is strange that no one notices such egregious errors.

B
BrainHacker, 2012-03-26
@BrainHacker

If you have the message "${films_folder}$i.mp4 not exist" displays the correct file name, then try to move lines 13 and 14 under "then":

if 
then
    echo "${films_folder}$i.mp4 not exist"
    echo "Converting "$i"."

    /usr/local/bin/ffmpeg -i ${video_folder}$i.mkv -acodec aac -strict experimental -ab 128k -ac 2 -vcodec libx264 -b 1200k -s 1280x720 -r 30 -threads 0 ${films_folder}$i.mp4

    echo "Convert "$i" to mp4 is done!"
else
    shift
fi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question