I have had incredible trouble building a binary of ffmpeg for Mac that works correctly for all of my needs. I have an older build that works great remuxing h264 video without problems but lacks a library I need, namely libspeex. I built a newer build based on ffmpeg’s git that includes libspeex but crashes when trying to remux h264 from .flv files with bad timecodes (live dumps from rtmpdump). So I have two ffmpeg binaries that each do half of what I need. This is what I have as my current .command file:
for f in ~/Desktop/Uploads/*.flv
do
/usr/local/bin/ffmpeg -i "$f" -vcodec copy -acodec libfaac -ab 128k -ar 48000 -async 1 "${f%.*}".mp4 && rmtrash "$f" || rmtrash "${f%.*}".mp4
done
This ffmpeg binary has libspeex included so it can decode speex audio in the .flv input files. What I’m looking to do is something like this pseudocode:
for f in ~/Desktop/Uploads/*.flv
do
ffprobe input.flv
if Stream #0:1 contains speex
ffmpeg-speex -i input.flv -acodec copy -async 1 output.m4a
fi
ffmpeg-h264 -i input.flv -vcodec copy output.mp4
MP4Box -add output.mp4 -add output.m4a finaloutput.mp4
done
Is something like this possible? Are there any alternatives?
You could run
grepon its output and test whether it found your desired string:Assuming an input file
abc.flv,ffmpeg-speexwould outputabc.m4a,ffmpeg-h264would outputabc.mp4, andMP4Boxwould outputabc-final.mp4.Edit: Fixed to
grepon stderr also; fixed problem where non-existent .m4a file might be given toMP4Boxas an input.