Transcoding
This is the place to share transcoding settings and scripts.
Range from .flac file
This script is intended to be used to play tracks that are defined as a range in a flac file. The range and the file are specified as a dummy url that is parsed within the script.
Save the following lines as flacNcue2wav.sh and store it to a location in your search path, e.g., /usr/bin/ (Syntax highlighting is omitted because it transforms the code syntax to invalid.)
#!/bin/bash
# flacNcue2wav.sh transcoding script to play a range from a flac file.
INPUT="$1"
OUTPUT="$2"
# parse parameters
SKIP=`echo ${INPUT} | sed 's/http:\/\/cue2flac\/params?.*skip=\([0-9:.]*\).*/\1/'`
UNTIL=`echo ${INPUT} | sed 's/http:\/\/cue2flac\/params?.*until=\([0-9:.\-]*\).*/\1/'`
FILENAME=`echo ${INPUT} | sed 's/http:\/\/cue2flac\/params?.*filename=\"\(.*\)\".*/\1/'`
# default params
if [ "${SKIP}" == "" ]
then
SKIP="0:00.00"
fi
if [ "${UNTIL}" == "" ]
then
UNTIL="-0:00.00"
fi
# if a filename is given, try transcoding
if [ "${FILENAME}" != "" ]
then
# transcoding command from flac to raw wav with a range
exec /usr/bin/flac -f -c -d "${FILENAME}" --skip=${SKIP} --until=${UNTIL} > ${OUTPUT} 2>/dev/null
fi
Viewing RAW format pictures
You can use the program 'dcraw' (available from most good linux distributions, nslu2 ipkg etc).
For a canon CR2 file you can choose to use dcraw to transcode the image (slow, even on a top spec machine) or use dcraw to extract and offer the high res embedded jpg (> 1080p).
Presently, with libexif (the default) rather than libextractor builds, no (exif) date is provided to date the file.
Create a 'transcode' dcraw script, I called it '/opt/bin/dcraw-thumb':
#!/bin/sh exec dcraw -e -c "$1" > "$2"
don't forget to make it executable with a chmod ugo+x script-file-name and then add the following to your config.xml:
<transcoding enabled="yes"> <mimetype-profile-mappings> <transcode mimetype="image/cr2" using="cr2-jpg"/> ... </mimetype-profile-mappings> <profiles> <profile name="cr2-jpg" enabled="yes" type="external"> <mimetype>image/jpeg</mimetype> <agent command="/opt/bin/dcraw-thumb" arguments="%in %out"/> <accept-url>no</accept-url> <first-resource>yes</first-resource> <hide-original-resource>yes</hide-original-resource> <buffer size="60000" chunk-size="20000" fill-size="20000"/> </profile> ... </profiles> </transcoding>
where I have used '…' to indicate the original contents of the sections 'here'.
You will want to add mime-type mappings to the <mappings> section too:
<map from="cr2" to="image/cr2"/> <map from="CR2" to="image/cr2"/>
and there you are. Nikon NEF and Adobe DNG etc are left as an exercise.
DirecTV HR2x Transcoding
Here is the setup information to setup transcoding for the DirecTV HR2x. You MUST use a MediaTomb version later than the 0.11.0 release. The 0.11.0 release (or earlier) will NOT work with the HR2x.
After building and installing MediaTomb, start the MediaTomb server and this will create the .mediatomb directory and within it, an initial config.xml file. Here are modifications needed in config.xml:
config.xml Updated 5/27/08 Added m4a, mkv, and mov. Updated youtube profiles.
Add these to the default list in <extension-mimetype>
<map from="ts" to="video/mpeg"/> <map from="vob" to="video/mpeg"/> <map from="wav" to="audio/wav"/> <map from="mpg" to="video/mpeg"/> <map from="aac" to="audio/x-aac"/> <map from="m4a" to="audio/mp4"/> <map from="mkv" to="video/x-matroska"/> <map from="mov" to="video/x-quicktime"/>
Add these to the default list in <mimetype-contenttype>
<treat mimetype="audio/wav" as="wav"/> <treat mimetype="video/x-quicktime" as="mov"/> <treat mimetype="audio/x-ms-wma" as="wma"/> <treat mimetype="audio/x-ms-asf" as="asf"/> <treat mimetype="audio/x-aac" as="aac"/> <treat mimetype="video/x-ms-wmv" as="wmv"/> <treat mimetype="video/x-matroska" as="mkv"/>
Replace <transcoding> section with this configuration:
<transcoding enabled="yes"> <mimetype-profile-mappings> <transcode mimetype="audio/mpeg" using="vlcwav"/> <transcode mimetype="video/x-flv" using="vlcyoutube"/> <transcode mimetype="video/mp4" using="transvideo"/> <transcode mimetype="video/x-quicktime" using="transvideo"/> <transcode mimetype="application/ogg" using="vlcwav"/> <transcode mimetype="audio/x-ms-wma" using="vlcwav"/> <transcode mimetype="audio/x-ms-asf" using="vlcwav"/> <transcode mimetype="audio/x-flac" using="ffmpegwav"/> <transcode mimetype="audio/x-aac" using="vlcwav"/> <transcode mimetype="audio/mp4" using="vlcwav"/> <transcode mimetype="video/x-msvideo" using="transvideo"/> <transcode mimetype="video/x-ms-wmv" using="transvideo"/> <transcode mimetype="video/mpeg" using="mpeg2trans"/> <transcode mimetype="video/x-matroska" using="transvideo"/> <transcode mimetype="image/jpeg" using="rescalejpeg"/> </mimetype-profile-mappings> <profiles> <profile name="transvideo" enabled="yes" type="external"> <mimetype>video/mpeg</mimetype> <accept-url>no</accept-url> <first-resource>yes</first-resource> <agent command="ffmpegvideo" arguments="%in %out 5900k 256k"/> <buffer size="57600000" chunk-size="128000" fill-size="10000000"/> </profile> <profile name="mpeg2trans" enabled="yes" type="external"> <mimetype>video/mpeg</mimetype> <accept-url>no</accept-url> <first-resource>yes</first-resource> <hide-original-resource>yes</hide-original-resource> <agent command="ffmpegvideo" arguments="%in %out 6000k 256k"/> <buffer size="28800000" chunk-size="512000" fill-size="120000"/> </profile> <profile name="ffmpegwav" enabled="yes" type="external"> <use-chunked-encoding>no</use-chunked-encoding> <mimetype>audio/wav</mimetype> <accept-url>no</accept-url> <first-resource>yes</first-resource> <agent command="ffmpegaudio" arguments="%in %out"/> <buffer size="1048576" chunk-size="131072" fill-size="262144"/> </profile> <profile name="vlcwav" enabled="yes" type="external"> <use-chunked-encoding>no</use-chunked-encoding> <mimetype>audio/wav</mimetype> <accept-url>yes</accept-url> <first-resource>yes</first-resource> <agent command="vlcaudio" arguments="%in %out"/> <buffer size="300000" chunk-size="10000" fill-size="32000"/> </profile> <profile name="rescalejpeg" enabled="yes" type="external"> <mimetype>image/jpeg</mimetype> <accept-url>no</accept-url> <first-resource>yes</first-resource> <accept-ogg-theora>no</accept-ogg-theora> <agent command="transjpeg" arguments="%in %out"/> <buffer size="50000" chunk-size="100" fill-size="100"/> </profile> <!-- You must comment out the youtube profile not used --> <!-- <profile name="ffyoutube" enabled="yes" type="external"> <mimetype>video/mpeg</mimetype> <accept-url>no</accept-url> <first-resource>yes</first-resource> <accept-ogg-theora>yes</accept-ogg-theora> <agent command="ffmpegyoutube" arguments="%in %out"/> <buffer size="14400000" chunk-size="256000" fill-size="80000"/> </profile> --> <profile name="vlcyoutube" enabled="yes" type="external"> <mimetype>video/mpeg</mimetype> <accept-url>yes</accept-url> <first-resource>yes</first-resource> <accept-ogg-theora>yes</accept-ogg-theora> <agent command="vlcvideo" arguments="%in %out"/> <buffer size="14400000" chunk-size="256000" fill-size="80000"/> </profile> </profiles> </transcoding>
Here are the shell scripts called from the transcoding profiles (filepaths may differ):
vlcaudio
#!/bin/bash
INPUT="$1"
OUTPUT="$2"
AUDIO_CODEC="s16l"
AUDIO_BITRATE="192"
AUDIO_SAMPLERATE="44100"
AUDIO_CHANNELS="2"
FORMAT="wav"
exec /usr/bin/vlc -I dummy "${INPUT}" --sout "#transcode{acodec=${AUDIO_CODEC},\
ab=${AUDIO_BITRATE},channels=${AUDIO_CHANNELS}}:\
standard{access=file,mux=${FORMAT},dst=${OUTPUT}}" vlc:quit >/dev/null 2>&1
ffmpegaudio
#!/bin/bash exec /usr/bin/ffmpeg -i "$1" -f wav - > "$2"
ffmpegvideo This script will add letterboxing to the input video to output a 16:9 aspect ratio to the HR2x. note: mediainfo binary must be present
Updated 6/2/08 Script now outputs MPEG2 Transport Stream with AC3 audio. If source video already has AC3, this audio will be used unaltered. Thanks GregLee
#!/bin/bash
# This script transcodes various video formats to MPEG2 Video and
# AC3 audio in an MPEG2 Transport Stream for the DirecTV HR2x
#
# FFMpeg and Mediainfo must be installed for this script to work.
#
# Input Parameters: Input, Output, Video Bitrate, Audio Bitrate
#
# Revision 1.00 6/3/2008
VBITRATE="$3"
ABITRATE="$4"
width=`/usr/local/bin/mediainfo --Inform=Video\;%Width% "$1"`
height=`/usr/local/bin/mediainfo --Inform=Video\;%Height% "$1"`
audio=`/usr/local/bin/mediainfo --Inform=Audio\;%Codec% "$1"`
# If source audio is AC3, use it. Otherwise transcode to AC3.
if [ $audio == AC3 ]; then
audcodec="copy"
else
audcodec="ac3"
fi
aspect=$(echo "scale=2; ($width/$height)*100" | bc | awk -F '.' '{ print $1; exit; }' )
echo $aspect
comphigh=179
complow=176
if [ "$aspect" -gt "$comphigh" ]; then
# needs bars top and bottom
bars=1
pad=$(echo "scale=2; (($width/1.778)-$height)/2" | bc | awk -F '.' '{ print $1; exit; }' )
mod=$(($pad % 2))
compmod=1
if [ "$mod" -eq "$compmod" ]; then
# pad must be an even number
pad=$((pad+1))
fi
else
if [ "$aspect" -lt "$complow" ]; then
# needs bars left and right
bars=2
pad=$(echo "scale=2; (($height*1.778)-$width)/2" | bc | awk -F '.' '{ print $1; exit; }' )
mod=$(($pad % 2))
compmod=1
if [ "$mod" -eq 1 ]; then
# pad must be an even number
pad=$((pad+1))
fi
else
# no bars needed
bars=0
pad=0
fi
fi
echo $pad
# Make sure the ffmpeg path is correct
if [ "$bars" -eq 1 ]; then
# bars top and bottom
exec /usr/local/bin/ffmpeg -i "$1" -b ${VBITRATE} -maxrate ${VBITRATE} -minrate ${VBITRATE} \
-bufsize 5097k -padtop ${pad} -padbottom ${pad} -threads 2 -ab ${ABITRATE} \
-acodec ${audcodec} -async 1 -f mpegts -y - > "$2"
else
if [ "$bars" -eq 2 ]; then
# bars left and right
exec /usr/local/bin/ffmpeg -i "$1" -b ${VBITRATE} -maxrate ${VBITRATE} -minrate ${VBITRATE} \
-bufsize 5097k -padleft ${pad} -padright ${pad} -threads 2 -ab ${ABITRATE} \
-acodec ${audcodec} -async 1 -f mpegts -y - > "$2"
else
# no padding needed
exec /usr/local/bin/ffmpeg -i "$1" -b ${VBITRATE} -maxrate ${VBITRATE} \
-minrate ${VBITRATE} -bufsize 5097k -threads 2 -ab ${ABITRATE} -acodec ${audcodec} \
-async 1 -f mpegts -y - > "$2"
fi
fi
ffmpegyoutube This will add padding on the left and right to format for a 16:9 aspect ratio
#!/bin/bash
# bars left and right
exec /usr/local/bin/ffmpeg -i "$1" -r 25 -b 4000k -maxrate 4000k \
-minrate 4000k -bufsize 1000k -padleft 44 -padright 44 -threads 2 \
-ac 1 -ab 64k -ar 44100 -acodec mp2 -f dvd -y - > "$2"
vlcyoutube This will add padding on the left and right to format for a 16:9 aspect ratio
#!/bin/bash
echo $1
echo $2
exec /usr/bin/vlc -I dummy "$1" --sout\
"#transcode{vcodec=mp2v,vb=4096,canvas-width=448,canvas-height=252,\
acodec=mpga,ab=64,samplerate=44100,channels=1}:standard{access=file,mux=ts,dst="$2"}"
note: line breaks have been fixed
For information about configuring config.xml for YouTube content, please refer to the readme.lyx document in the /doc directory from the latest SVN.
DirecTV HR2x Photo Display Solution
I have found a solution for the HR2x photo display issue using MediaTomb. Since the HR2x appears to display the photo on a 640×480 canvas, it obviously has to downrez the image to 640×480. Why not do the image convert in a transcoding procedure within MediaTomb? This fixed the issue where the thumbnail was displayed instead of the regular image.
The other issue is when the HR2x refuses to display a photo (Unable to access message.) To fix this, I also strip the EXIF metadata from the photo during the transcode. It is not needed when the photo data is sent. Now, all of my photos are working :) Note: the original photo on the computer is not changed in any way. Only the photo data streamed to the HR2x. Also, the photo will be scaled to the largest value of the 640 or 480, thus maintaining the original photo aspect ratio. Any photo smaller than 640×480 will not be scaled.
Here are the details:
1) Make sure the imagemagick software is installed.
2) Add this to <mimetype-profile-mappings>
<transcode mimetype="image/jpeg" using="rescalejpeg"/>
3) Add this transcoding profile:
<profile name="rescalejpeg" enabled="yes" type="external">
<mimetype>image/jpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<agent command="transjpeg" arguments="%in %out"/>
<buffer size="50000" chunk-size="100" fill-size="100"/>
</profile>
4) Create this script called transjpeg and make it executable:
#!/bin/bash exec convert -size 640x480 "$1" -resize 640x480 +profile '*' - > "$2"
DirecTV HR2x Audio Normalization
Contributed by Master63a
Don't you love it when a commercial comes on and your speakers are almost blown? The audio is highly compressed and that is what makes it sound so loud. These scripts attempt to 'normalize' the audio using sox as the audio processor. Note that sox has extensive audio processing capability such as equalizers, replay gain, reverb, etc and the scripts can easily be modified to use some of them. These are my first real scripts so improvements are welcome. The first script is designed to process mp3 audio files and will apply compression to local files and suitable audio streams. If a local file has a sample rate that is 44Khz or higher, compression will not be applied so that the script can be used for high quality mp3 audio.
#!/bin/bash
INPUT="$1"
OUTPUT="$2"
AUDIO_CODEC="s16l"
AUDIO_BITRATE="192"
AUDIO_SAMPLERATE="44100"
AUDIO_CHANNELS="2"
FORMAT="wav"
exec &> /dev/null
# LOCAL FILES COMPAND IF SAMPLERATE < 44KHZ
if [ ${1:0:1} = \/ ]
then
mediainfo "$1" | fgrep Sampling > /tmp/samplerate.txt
exec </tmp/samplerate.txt
read LINE
SRATE=$LINE
[ ${SRATE:35:2} -ge 44 ]
COMPRESS=$?
if [ $COMPRESS = 0 ]
then
exec sox -t .mp3 "$1" -t .wav - >"$2"
else
echo 'sox companding'
exec sox -t .mp3 "$1" -t .wav - >"$2" compand 0.1,0.8 60:-40,-5 -20 -70 .2
fi
# SOX CAN HANDLE SOME OF THIS TYPE
else if [ ${1:0:5} = 'http:' ]
then
echo 'sox companding'
exec sox -t .mp3 "$1" -t .wav - >"$2" compand 0.1,0.8 60:-40,-5 -20 -70 .2
else
# BUT NOT THIS TYPE SO USE Boilerjt's VLCAUDIO SCRIPT
echo 'vlc'
exec /usr/bin/vlc -I dummy "${INPUT}" --sout "#transcode{acodec=${AUDIO_CODEC},\
ab=${AUDIO_BITRATE},channels=${AUDIO_CHANNELS}}:\
standard{access=file,mux=${FORMAT},dst=${OUTPUT}}" vlc:quit >/dev/null 2>&1
fi
fi
The second script does the same for videos such as youtube and such. If someone can find a way to end the threads more gracefully, please edit this script.
#!/bin/bash
exec &> /dev/null
# NOT ELEGANT BUT I CAN'T FIND A GOOD WAY TO STOP THE THREADS IF VIDEO IS STOPPED VIA THE HR2X
rm -f p1.wav
rm -f p2.wav
# THIS HAS NO AFFECT, PERHAPS WE NEED MEDIATOMB TO SEND A SIGNAL TO END THE SCRIPT
#trap "{ rm -f p1.wav;rm -f p2.wav }" SIGTERM SIGPIPE EXIT
mkfifo p1.wav
mkfifo p2.wav
ffmpeg -i "$1" -f wav -vn -ar 44100 -ac 2 -f wav - > p1.wav & \
sox -t raw -r 44100 -2 -s -c 2 p1.wav -t wav p2.wav compand .3,.8 -40,-5 -20 -70 .2 & \
ffmpeg -i "$1" -s hd720 -b 6000k -threads 2 -ab 192k -i p2.wav -f dvd -map 0:0 -map 1:0 - > "$2"
Play Station 3 PCM support
Mediatomb version 0.12.0 has support for PCM output for the Play Station 3. This allows streaming audio from flac, ape, ogg etc. to the playstation.
To enable PCM output support get ogg vorbis files, the following section will do the trick.
<mimetype-profile-mappings>
<transcode mimetype="application/ogg" using="2pcm"/>
</mimetype-profile-mappings>
<profiles>
<profile name="2pcm" enabled="yes" type="external" >
<mimetype>audio/L16</mimetype>
<first-resource>yes</first-resource>
<accept-url>yes</accept-url>
<sample-frequency>source</sample-frequency>
<audio-channels>2</audio-channels>
<hide-original-resource>yes</hide-original-resource>
<agent command="/usr/bin/ffmpeg" arguments="-ac 2 -y -i %in -f s16be %out"/>
<buffer size="1048576" chunk-size="4096" fill-size="1024"/>
</profile>
</profiles>
The configuration can of course me merged with existing/other mimetype-profile-mappings and profiles sections.
News Feed