User:Outlyer/neroaacenc k3b plugin

From Hydrogenaudio Knowledgebase
Jump to: navigation, search

This is a slightly more complete version of the "neroaacenc" script for use with K3B as found in K3b and Nero AAC.

Important: The code here doesn't take the input parameter, so when configuring k3b you must set the command to neroaac %f %t %a %c %n %m %y instead of neroaac - %f %t %a %c %n %m %y (note the dash is missing).

Differences:

  • set -e: Fail quickly (abort on fail)
  • Logfiles, for debugging purposes all output can be easily redirected
  • Doesn't set empty tags
#!/bin/bash
#
# Based on <http://wiki.hydrogenaudio.org/index.php?title=K3b_and_Nero_AAC_Guide>
#

set -e

TEMPFILE=/dev/shm/neroaac-$RANDOM

nerodir=/usr/share/neroaacenc

LOGFILE_OUT=/dev/null # redirect std output to... for debugging e.g. $TEMPFILE.out
LOGFILE_ERR=/dev/null # redirect std error to... for debugging e.g. $TEMPFILE.err

( # used to redirect output easily

# output a WAV to stdin and encode it to $TEMPFILE.mp4
sox -V -x -s -w -t raw -r 44100 -c 2 - -t wav - | wine $nerodir/neroAacEnc.exe -ignorelength -if - -of $TEMPFILE.mp4

# tag it
# avoid setting empty tags:
# 
tags=
if [ "$2" ]; then tags+=" -meta:title=\"$2\""; fi
if [ "$3" ]; then tags+=" -meta:artist=\"$3\""; fi
if [ "$4" ]; then tags+=" -meta:comment=\"$4\""; fi
if [ "$5" ]; then tags+=" -meta:track=\"$5\""; fi
if [ "$6" ]; then tags+=" -meta:album=\"$6\""; fi
if [ "$7" ]; then tags+=" -meta:year=\"$7\""; fi

if [ "$tags" ]; then
    eval wine $nerodir/neroAacTag.exe $TEMPFILE.mp4 $tags
fi

# rename to its final name
mv $TEMPFILE.mp4 "$1"

) >>$LOGFILE_OUT 2>>$LOGFILE_ERR