Scripted fade in/out of audio

dgmm freebsd01 at dgmm.net
Sat Feb 3 13:51:06 UTC 2007


On Tuesday 30 January 2007 01:14, dgmm wrote:
> All,
>
> Are there any programs out there which can do fade in and out of audio
> during a copy or encode, under control of a shell script or similar?
>
> I have a large number of short video clips which need to be re-encoded into
> one long stream with a one second fade-in at the start of each clip and a
> one second fade out at the end of each clip.
>
> So far, I've got a script which separates audio and video and creates the
> fade-in/out for the video, re-encodes it and muxes the audio back in.
> (I'm sure the script as is could be improved, advice welcome :-)
>
> Would this be better on another list?  If so, which?

Never mind.  A face to face discussion pointed me at sox which does what I 
want.

(code fragment)

echo "-------------------------------------"
echo " Calculating audio fade positions"
echo "-------------------------------------"
aud_time=`sox $tmpdir/zaudio.mp3 2>&1 -e stat | grep Length | \
   cut -d : -f 2 | cut -f 1 | sed 's/^[ \t]*//'`
echo Audio size in seconds: $aud_time
aud_frames=`sox $tmpdir/zaudio.mp3 2>&1 -e stat | grep Samples | \
   cut -d : -f 2 | cut -f 1 | sed 's/^[ \t]*//'`
echo Audio size in frames:  $aud_frames
frames_per_second=`perl -e "print ($aud_frames / $aud_time)"`
int_time=`perl -e "print int($aud_time)"`
frac_time=`perl -e "print int(($aud_time - int($aud_time)) * 
$frames_per_second)"`
stop_time=${int_time}.${frac_time}
echo "-------------------------------------"
echo " Processing audio fades"
echo "-------------------------------------"
sox $tmpdir/zaudio.mp3 $tmpdir/zaudio1.mp3 fade q 2 $stop_time 1

-- 
Dave


More information about the freebsd-multimedia mailing list