0

I'm looking to batch-convert a directory (or several) of video files from .avi to .mp4 containers, just copying the video and audio streams across. I know the ffmpeg command to do this, and have no trouble doing the files individually.

I am unfamiliar with ash (as opposed to bash) and its file-handling and looping procedures, which is making it tough to write a shell script. (It has to run in ash 'cos it's running on an underpowered Synology NAS.)

1
  • 1
    It is kind of interesting that your NAS box is underpowered and cannot run bash, but that it can run ffmeg
    – Anthon
    Commented Apr 11, 2015 at 6:01

2 Answers 2

2

You should be fine if you stick to the Bourne shell syntax, the most import of this for your application should be the for loop.

 #/bin/ash

 for filename in *.avi
 do
      ffmeg parameters "$filename"
 done
0

I use two scripts for this it uses handbreak to do the conversion, but could be modified to user ffmpeg (but remember ffmpeg is depricated).

I run process.sh and it finds then loops through, running encode.sh for each file.

process.sh

if [ "$1" != "" ]; then
    dir="$1"
else
    dir="/Data/Movies"
fi

if [ -e /tmp/process.lock ] ; then 
    echo "Process already running"
else
    echo `date` > /tmp/process.lock
    find "$dir" \( -mmin +10 -name "*.avi" -o -name "*.mkv" -o -name "*.mpg" \) -exec echo "{}" \; > /tmp/list
    cat /tmp/list | wc -l
    read -p "Pausing...."
    find "$dir" \( -mmin +10 -name "*.avi" -o -name "*.mkv" -o -name "*.mpg" \) -exec /home/coteyr/encode.sh "{}" \;
    rm /tmp/process.lock
fi

And encode.sh

#!/bin/bash
echo "$1" > /tmp/current_encode.txt
nice -n 19 HandBrakeCLI -T -Z Normal -i "$1" -o "$1.m4v" > /tmp/progress.log
mv "$1" /Data/Temp/
echo "Idle" > /tmp/current_encode.txt
echo "Idle" > /tmp/progress.log

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .