JakeWharton/mkvdts2ac3 — Issue #62: find a way to clean up ffmpeg output and provide progress bar
Author: choekstr
Created: 2011-12-22 22:31:11+00:00
State: open
Labels: Feature Request

Ok, I think I have it! After lots of hours of testing and tweaking and an idea from Rupert Plumridge I have come up with a pretty slick solution. I run ffmpeg in the background outputing to a tmp file and parse the tmp file pulling out just what i want and massaging the data to give a rough sense of progress. A TODO could be to calculate percentage and display that as well.

Here is the whole conversion section for review. It should be a direct cut from the first line and replace up to the last line:

# ------ CONVERSION ------
# Convert DTS to AC3
doprint $"Converting DTS to AC3."
doprint "> ffmpeg -i \"$DTSFILE\" -acodec ac3 -ac 6 -ab 448k \"$AC3FILE\""

dopause
if [ $EXECUTE = 1 ]; then
color YELLOW; echo $"Converting DTS to AC3:"; color OFF
nice -n $PRIORITY ffmpeg -i "$DTSFILE" -acodec ac3 -ac 6 -ab 448k "$AC3FILE" 2>/tmp/ffmpeg_output &
PID=$!
DTSFILESIZE=$($DUCMD "$DTSFILE" | cut -f1) # Capture DTS filesize for end summary
let AC3FILESIZE=$DTSFILESIZE/5 #Estimate on AC3 ending filesize based on typical use
while [ -e /proc/$PID ];do
LINE=$(tail -1 /tmp/ffmpeg_output|sed "s/kB/kB\/${AC3FILESIZE}kB/g") #Inject size in output
echo -ne "\r$LINE" # Provide updates from ffmpeg_output every second
sleep 1
done
checkerror $? $"Converting the DTS file to AC3 failed" 1
cleanup /tmp/ffmpeg_output

# If we are keeping the DTS track external copy it back to original folder before deleting
if [ ! -z $KEEPDTS ]; then
color YELLOW; echo $"Moving DTS track to MKV directory."; color OFF
rsync --progress -a "$DTSFILE" "$DEST"
checkerror $? $"There was an error copying the DTS track to the MKV directory. You can perform
this manually from \"$DTSFILE\"." 1
fi
cleanup $DTSFILE

timestamp $"DTS track conversion took: "
fi

I might be able to use this same concept to provide a progress bar for Extracting DTS. Need to revisit this again.