MediaTomb and PS3: The Lazy Man's solution (Part II)
A while back I did an article on a catch-all solution for streaming content to the Playstation 3 using MediaTomb and a big transcoding script. It served me well: every movie I had - be it avi, mkv, mp4, dvd iso, RealMedia, ... was properly handled. I didn't care for HD content, mainly because my TV was a plain old CRT tube and couldn't tell the difference between a 720x480 mpeg2 and a 1080p h.264 movie anyway.
Last month I did get me a HDTV finally, and my original transcoding script wasn't ready for it.
Last week I finally got me a Boxee Box. Since this thing does everything I want and more when it comes to movies and series, I don't have any use for mediatomb anymore. So, while I'll keep the articles online... I mostlikely won't be making any changes/bugfixes to the script anymore :-)
In hindsight, there were two crucial things wrong with my original setup:
- I didn't check which codecs were used in the source file. Everything was transcoded to MPEG-2, even if the source codec was supported by the PS3.
- Transcoding HD content was problematic: transcoding 720p worked (barely!), but 1080p was plain impossible, cpu-wise.
So I had two major points to fix: first of all checking the source file's internals, and related to that, remuxing where possible instead of transcoding. It took me a few days of trial-and-error, but this is the result for now:
#!/bin/bash
#
# General all-covering MediaTomb transcoding script.
#
#############################################################################
# Edit the parameters below to suit your needs.
#############################################################################
# Subtitles imply transcoding; set to 1 to disable subtitle rendering.
# For divx this doesn't matter much but for mp4, mkv and DVD it does.
DISABLESUBS=1
# Change this to enable different DVD subtitle languages.
SUBS="nl,en"
# Change this line to set the average bitrate.
# Use something like 8000 for wired connections; lower to 2000 for wireless.
AVBIT=8000
# Change this line to set the maximum bitrate.
# Use something like 12000 for wired connections; lower to 5000 for wireless.
MVBIT=12000
# Change this line to set the MPEG audio bitrate in kbps. AC3 is fixed to 384.
AABIT=256
# Change this line to set your favourite subtitle font.
SFONT="/etc/mediatomb/DejaVuSans.ttf"
# Change this line to set the size of subtitles. 20-25 is okay.
SUBSIZE=20
# Enable downscaling of transcoded content to 720 pixels wide (DVD format)?
DOWNSCALE=1
# If downscaling is enabled, anything over this width (pixels) will be downscaled.
MAXSIZE=900
# Enable logging to file?
LOGGING=1
# If logging is enabled, log to which file?
LOGFILE="/var/log/mediatomb-transcode.log"
#############################################################################
# Do not change anything below this line.
#############################################################################
# Variables
#############################################################################
FILE=$1
VERSION="0.12"
MENCODER=$(which mencoder)
MEDIAINFO=$(which mediainfo)
FFMPEG=$(which ffmpeg)
LSDVD=$(which lsdvd)
XML=$(which xmlstarlet)
M_TR_M="-oac lavc -ovc lavc -of mpeg -lavcopts \
abitrate=${AABIT}:vcodec=mpeg2video:keyint=1:vbitrate=${AVBIT}:\
vrc_maxrate=${MVBIT}:vrc_buf_size=1835 \
-mpegopts muxrate=12000 -af lavcresample=44100 "
M_TR_A="-oac lavc -ovc copy -of mpeg -lavcopts \
abitrate=${AABIT} -af lavcresample=44100 "
M_RE_M="-oac copy -ovc copy -of mpeg -mpegopts format=dvd -noskip -mc 0 "
F_TR_M="-acodec ac3 -ab 384k -vcodec copy -vbsf h264_mp4toannexb -f mpegts -y "
F_RE_M="-acodec copy -vcodec copy -vbsf h264_mp4toannexb -f mpegts -y "
SUBOPTS="-slang ${SUBS} "
SRTOPTS="-font ${SFONT} -subfont-autoscale 0 \
-subfont-text-scale ${SUBSIZE} -subpos 100 "
SIZEOPTS="-vf harddup,scale=720:-2 "
NOSIZEOPTS="-vf harddup "
S24FPS="23.976"
S24OPT="-ofps 24000/1001 "
S30FPS="29.970"
S30OPT="-ofps 30000/1001 "
VCODEC=""
ACODEC=""
VWIDTH=""
VFPS=""
QPEL=""
AVCPROF=""
OPTS=("")
declare -i MODE=0
#############################################################################
# Functions
#############################################################################
function log {
if [ "${LOGGING}" == "1" ] ; then
echo -e "$(date +'%Y/%m/%d %H:%m:%S') \t $1" >> ${LOGFILE}
fi
}
function mediainfo {
MIOUT=$(mktemp /tmp/tmp.mediainfo.XXXXXX)
log "Logging mediainfo XML to ${MIOUT}."
${MEDIAINFO} --output=xml "${FILE}" > ${MIOUT}
VCODEC=$(${XML} sel -t -m ".//track[@type='Video']" -v "Format" ${MIOUT} )
ACODEC=$(${XML} sel -t -m ".//track[@type='Audio']" -v "Format" ${MIOUT} )
VWIDTH=$(${XML} sel -t -m ".//track[@type='Video']" -v "Width" \
${MIOUT} | sed 's/ pixels//' )
VFPS=$(${XML} sel -t -m ".//track[@type='Video']" -v "Frame_rate" \
${MIOUT} | sed 's/ fps//' )
AVCPROF=$(${XML} sel -t -m ".//track[@type='Video']" -v "Format_profile" \
${MIOUT} | sed 's/[^0-9]//g' )
QPEL=$(${XML} sel -t -m ".//track[@type='Video']" -v "Format_settings__QPel" \
${MIOUT} )
log "Variables found: \
${VCODEC} | ${ACODEC} | ${VWIDTH} | ${VFPS} | ${AVCPROF} | ${QPEL} "
rm -f ${MIOUT}
}
function tropts {
if [ "${DOWNSCALE}" == "1" -a ${VWIDTH} -gt ${MAXSIZE} ] ; then
log "Rescaling to 720 pixels wide."
OPTS+=(${SIZEOPTS})
else
log "Rescaling disabled or file within limits."
OPTS+=(${NOSIZEOPTS})
fi
if [ "${VFPS}" == "${S24FPS}" ] ; then
log "Framerate adjusted for mencoder."
OPTS+=(${S24OPT})
else if [ "${VFPS}" == "${S30FPS}" ] ; then
log "Framerate adjusted for mencoder."
OPTS+=(${S30OPT})
else
log "Framerate acceptable for mencoder."
fi
fi
}
function getmode {
# Fixed case: DVD ISO.
if [ "${FEXT}" == "ISO" ] ; then
CHAPTER=$(${LSDVD} "${FILE}" | grep Longest | sed 's/.* //')
log "DVD iso image found: Longest chapter is ${CHAPTER}."
MODE+=${DISABLESUBS}1000000
return 0
fi
# Fixed case: subtitle found: transcode by default.
if [ "${DISABLESUBS}" == "0" -a -e "$(echo $FILE | sed 's/...$/sub/')" ] ; then
log "SRT subtitle found."
SUB=$(echo $FILE | sed 's/...$/sub/')
MODE+=100000
return 0
elif [ "${DISABLESUBS}" == "0" -a -e "$(echo $FILE | sed 's/...$/srt/')" ] ; then
log "SUB subtitle found."
SUB=$(echo $FILE | sed 's/...$/srt/')
MODE+=100000
return 0
fi
log "No subtitles found, or subtitle rendering disabled."
mediainfo
case ${VCODEC} in
"AVC")
if [ "${AVCPROF}" -gt "41" ] ; then
# Cannot handle h.264 4.1+
MODE+=10000
else
# We can handle the rest
MODE+=1
fi ;;
"MPEG-4 Visual")
if [ "${QPEL}" == "No" ] ; then
# No QPEL: we could remux the video
MODE+=100
else
# QPEL: just transcode it all
MODE+=10000
fi ;;
* )
# Transcode everything we don't know
MODE+=10000 ;;
esac
case ${ACODEC} in
"AC-3" | "MPEG Audio" )
# These should be wellknown
MODE+=1 ;;
* )
if [ "${MODE}" -lt "100" ] ; then
# If video is AVC, transcode audio in m2ts
MODE+=10
else
# Otherwise in other container
MODE+=1000
fi ;;
esac
}
function processmode {
log "Mode is ${MODE}."
if [ ! "${MODE}" -lt "10000000" ] ; then
EXEC="${MENCODER} -dvd-device"
OPTS+=(dvd://${CHAPTER} ${M_RE_M} -o )
elif [ ! "${MODE}" -lt "1000000" ] ; then
EXEC="${MENCODER} -dvd-device"
OPTS+=(dvd://${CHAPTER} ${SUBOPTS} ${M_TR_M} -o )
elif [ ! "${MODE}" -lt "100000" ] ; then
EXEC=${MENCODER}
tropts
OPTS+=(${M_TR_M} -sub ${SUB} ${SRTOPTS} -o )
elif [ ! "${MODE}" -lt "10000" ] ; then
EXEC=${MENCODER}
tropts
OPTS+=(${M_TR_M} -o )
elif [ ! "${MODE}" -lt "1000" ] ; then
EXEC=${MENCODER}
tropts
OPTS+=(${M_TR_M} -o)
elif [ ! "${MODE}" -lt "100" ] ; then
EXEC=${MENCODER}
OPTS+=(${M_TR_M} -o)
elif [ ! "${MODE}" -lt "10" ] ; then
EXEC="${FFMPEG} -i"
OPTS+=(${F_TR_M})
elif [ ! "${MODE}" -lt "1" ] ; then
EXEC="${FFMPEG} -i"
OPTS+=(${F_RE_M})
else
log "I'm sorry Dave, I'm afraid I can't do mode=0."
fi
}
#############################################################################
# Main method
#############################################################################
log "Starting MediaTomb Multifunctional Transcoder (version ${VERSION})."
FEXT=$(echo $FILE | sed 's/.*\.//' | tr [a-z] [A-Z])
log "${FEXT} file specified: \"${FILE}\""
getmode
processmode
log "Starting exec:"
log "${EXEC} \"${FILE}\" ${OPTS[@]} ${2} &>/dev/null"
exec ${EXEC} "${FILE}" ${OPTS[@]} "${2}" &>/dev/nullSome explanation on how this works: first of all, the script checks the source file extension. Unlike the old script however, this is no longer the final source of info. A variable "MODE" has been introduced, which is being modified by various checks based on mediainfo output of the source file. In short: every digit has a meaning. If MODE has one digit, it means that both audio and video have been checked, and can be remuxed to a container the PS3 supports. Most common example: h.264 video, AC3 audio. If MODE has two digits after running through the checks, the video stream can be remuxed, but the audio stream needs to be transcoded. This happens quite a lot with MP4s where the video codec works well, but the PS3 has issues with the audio stream.
Three or four digits is a case I haven't cracked yet. Basically, three digits means that both audio and video are MPEG-4 (DivX, XviD) codecs that are natively supported by the PS3, so in theory, we might remux those into a container and serve it. You'll notice that most AVIs will have such a properly supported video stream and MP3 audio; they end up in this case. Four digits means only the audio needs to be transcoded, and the video can stay. Big problem there: the PS3 doesn't like it when you serve it an AVI that you've remuxed... something for me to investigate. For now, they get the same treatment as the five-digit MODEs - transcoded into a big ol' MPEG-2 stream, like all the other unsupported crap out there.
Six digits means any random media with a subtitle, which results in MPEG-2. Seven means a transcoded DVD iso (with subtitles); eight is a remuxed DVD iso (without subtitles). And nothing stops you from adding more subclasses if you'd see a need for it.
Once the MODE is set, all the script needs to do is pick the proper encoder (ffmpeg or mencoder), add the proper options, and exec it.
You'll also notice an extra dependency was introduced: XMLStarlet. This is needed to propery parse the XML dump that is created by running mediatomb on a source file. Well, 'needed'... it makes life a hell of a lot easier. And this way you don't have to call mediainfo half a dozen times on the same file to pull it through grep.
All in all, I'm happy with the result. I still need to investigate on how to remux an avi using this script (which has mimetype video/mpeg in config.xml; might have something to do with it?) but that's something for later.
Enjoy!
- Add new comment
- 39670 reads

Hi, I'm having some issues with mediatomb and your script. I'm somewhat new to linux, but I've got mediatomb running properly (if I don't try to implement this awesome sounding script) however when I swap in your config.xml file and the mediatomb-transcode.sh I get a vague error in the mediatomb log, and nothing in the mediatomb-transcode log.
Here's the mediatomb log:
2012-02-01 08:55:11 INFO: Loading configuration from: /home/scott/.mediatomb//-p/config.xml
2012-02-01 08:55:11 INFO: Checking configuration...
2012-02-01 08:55:11 INFO: Setting filesystem import charset to UTF-8
2012-02-01 08:55:11 INFO: Setting metadata import charset to ISO-8859-15
2012-02-01 08:55:11 INFO: Setting playlist charset to ANSI_X3.4-1968
2012-02-01 08:55:11 INFO: Configuration check succeeded.
2012-02-01 08:55:11 INFO: Initialized port: 49152
2012-02-01 08:55:11 INFO: Server bound to: XXX.XXX.XXX.XXX
2012-02-01 08:55:12 INFO: MediaTomb Web UI can be reached by following this link:
2012-02-01 08:55:12 INFO: http://XXX.XXX.XXX.XXX:49152/
2012-02-01 08:55:28 INFO: Arguments: %in %out
2012-02-01 08:55:28 ERROR: process terminated early
2012-02-01 08:55:42 INFO: Arguments: %in %out
2012-02-01 08:55:42 ERROR: process terminated early
2012-02-01 08:55:57 INFO: Arguments: %in %out
2012-02-01 08:55:57 ERROR: process terminated early
I've checked the permissions on all the related files and made them either 555 or 777
as far as I can tell the mediatomb-transcode.sh isn't getting called (nothing in the log) and I can't figure out why.
I studied programming in college so I'm comfortable with code, but I don't know where to start with this.
Any ideas?
- reply
Submitted by Scott (not verified) on Wed, 01/02/2012 - 16:05.Also:
I'm running openSUSE 11.3
if that helps.
- reply
Submitted by Scott (not verified) on Wed, 01/02/2012 - 17:30.Hi there,
I kept getting Command not found: sel Error.
It took me forever to figure out, that the xmlstarlet command on line 57 has to be adjusted to:
XML=$(which xml)
This is because the FreeBSD Command for XMLStarlet is xml NOT xmlstarlet.
- reply
Submitted by stonie Excited (not verified) on Sun, 20/11/2011 - 13:29.Only works when there are no empty characters. (i.e. 1492.mkv works but The 1492.mvk not)
Second, now there were no thumbnails shown. Without the script they were shown.
Any solutions about that?
Regards
Jose
- reply
Submitted by Jose1701 (not verified) on Fri, 04/11/2011 - 23:03.That sounds strange, since virtually all of my filenames have spaces, and I never had this problem. It might be related to a quoting problem - check that all variables that contain filenames, are properly quoted.
- reply
Submitted by Lennert on Sat, 05/11/2011 - 11:26.Well, I have to look for it. Do you mean in the multi script?
That's not the only problem I do have. :-(
Some mkv were played for a few second and stop, and again. Then I tried to play a HD mpg and video looks good (up to 25Mbps - so it isn't a cpu prob) but sound is asynchron.
- reply
Submitted by Jose1701 (not verified) on Sat, 05/11/2011 - 21:10.Has anyone found the solution to the "Permission Denied" on lines 108 and 110 of the mediatomb-multifunctional.sh? I have checked the permissions to the tmp directory and to the mediatomb-multifunctional.sh script and still can't seem to figure this out. Any help would be appreciated
2011-08-19 12:54:36 INFO: Arguments: %in %out
2011-08-19 12:54:36 INFO: Arguments: %in %out
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 108: /tmp/tmp.mediainfo.rMxNy7: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 110: /tmp/tmp.mediainfo.rMxNy7: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 108: /tmp/tmp.mediainfo.gpke2J: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 110: /tmp/tmp.mediainfo.gpke2J: Permission denied
2011-08-19 12:54:36 INFO: Arguments: %in %out
2011-08-19 12:54:36 INFO: Arguments: %in %out
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 108: /tmp/tmp.mediainfo.sVqGdT: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 110: /tmp/tmp.mediainfo.sVqGdT: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 108: /tmp/tmp.mediainfo.mwSFx3: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 110: /tmp/tmp.mediainfo.mwSFx3: Permission denied
2011-08-19 12:54:45 INFO: Arguments: %in %out
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 108: /tmp/tmp.mediainfo.10SNLy: Permission denied
warning: failed to load external entity " "
/usr/local/bin/mediatomb-multifunctional.sh: line 110: /tmp/tmp.mediainfo.10SNLy: Permission denied
- reply
Submitted by justtech (not verified) on Fri, 19/08/2011 - 18:57.Just in case someone else is having this problem... the way I got around this and was able to fix it was to log in as "root" using the "su" in the terminal and then use the "mediatomb" command to start the server. Everything is playing fine now from what I can tell.
- reply
Submitted by justtech (not verified) on Fri, 19/08/2011 - 19:10.Nevermind... that just created a new config.xml file in root directory and allowed a few of the movies to play that weren't playing before... but now all of my .mkv files aren't working because the default config.xml file does not use the .sh script for transcoding....
... so back at square one with Permision Denied issues on line 108 and 110 :\
- reply
Submitted by justtech (not verified) on Fri, 19/08/2011 - 21:18.Well it is day three of me working on mediatomb and it appears that your script is just what I wanted - sadly I just can't get it to work. I think I have everything installed for it... When I go to run a MKV it just says data unsupported or data corrupt. The script does create a log file.
2011/06/13 22:06:33 Starting MediaTomb Multifunctional Transcoder.
2011/06/13 22:06:33 OGM/MKV file specified: "/data/media/anime/One Piece/One Piece 487.mkv"
2011/06/13 22:06:33 Tempfile is /tmp/tmp.mediainfo.C3XGmy
2011/06/13 22:06:33 Width of 640 and FPS of 23.810 detected.
2011/06/13 22:06:33 Rescaling disabled or file within limits.
2011/06/13 22:06:33 Framerate acceptable for mencoder.
2011/06/13 22:06:33 No external subtitles.
2011/06/13 22:06:33 Starting mencoder:
2011/06/13 22:06:33 /usr/bin/mencoder "/data/media/anime/One Piece/One Piece 487.mkv" -aid 0 -sid 0 -oac lavc -ovc lavc -of mpeg -lavcopts abitrate=256:vcodec=mpeg2video:keyint=1:vbitrate=8000:vrc_maxrate=12000:vrc_buf_size=1835 -mpegopts muxrate=12000 -af lavcresample=44100 -font /etc/mediatomb/DejaVuSans.ttf -subfont-autoscale 0 -subfont-text-scale 20 -subpos 100 -vf harddup -o "/tmp/mt_transcode_W6FUWV"
2011/06/13 22:06:33 Script ended.
- reply
Submitted by ArchAngel714 (not verified) on Tue, 14/06/2011 - 04:47.That's quite curious. An mkv, supposing it's h264, should not be handled by mencoder at all. What kind of codecs are in that mkv?
Besides that, try running the mencoder command manually in a terminal and check what it says. Might be the framerate - 23.810 is a *very* weird number.
- reply
Submitted by Lennert on Tue, 14/06/2011 - 09:27.Well I deleted the database and started everything up again today - no luck. I have the following log however if they are at all helpful. Thanks again for all the help. I am just so lost and frustrated with this - glad to know I am talking to the experts.
2011-06-14 19:54:47 INFO: Configuration check succeeded.
2011-06-14 19:54:47 WARNING: Sqlite3 database seems to be corrupt or doesn't ex$
2011-06-14 19:54:47 INFO: no sqlite3 backup is available or backup is corrup$
2011-06-14 19:54:48 INFO: database created successfully.
2011-06-14 19:54:48 INFO: Initialized port: 49152
2011-06-14 19:54:48 INFO: Server bound to: XXX.XXX.XXX.XXX
2011-06-14 19:54:49 INFO: MediaTomb Web UI can be reached by following this $
2011-06-14 19:54:49 INFO: http://XXX.XXX.XXX.XXX:49152/
2011-06-14 20:08:53 INFO: Arguments: %in %out
2011-06-14 20:12:37 INFO: Arguments: %in %out
------------------------------------------------------------------------
2011/06/14 20:06:54 Starting MediaTomb Multifunctional Transcoder.
2011/06/14 20:06:54 OGM/MKV file specified: "/data/media/anime/One Piece/O$
2011/06/14 20:06:54 Tempfile is /tmp/tmp.mediainfo.B5tG7R
2011/06/14 20:06:54 Width of 640 and FPS of 23.810 detected.
2011/06/14 20:06:54 Rescaling disabled or file within limits.
2011/06/14 20:06:54 Framerate acceptable for mencoder.
2011/06/14 20:06:54 No external subtitles.
2011/06/14 20:06:54 Starting mencoder:
2011/06/14 20:06:54 /usr/bin/mencoder "/data/media/anime/One Piece/One Pie$
2011/06/14 20:06:54 Script ended.
2011/06/14 20:06:37 Starting MediaTomb Multifunctional Transcoder.
2011/06/14 20:06:37 Regular file specified: "/data/media/tv/House/Season 7$
2011/06/14 20:06:37 Tempfile is /tmp/tmp.mediainfo.rKeVYM
2011/06/14 20:06:43 Width of 640 and FPS of 59.940 detected.
2011/06/14 20:06:43 Rescaling disabled or file within limits.
2011/06/14 20:06:43 Framerate acceptable for mencoder.
2011/06/14 20:06:43 No external subtitles.
2011/06/14 20:06:43 Starting mencoder:
2011/06/14 20:06:43 /usr/bin/mencoder "/data/media/tv/House/Season 7/House$
2011/06/14 20:06:43 Script ended.
Maybe the streams are not getting passed back to mediatomb?! permissions issue? idk...
Thanks again
- reply
Submitted by ArchAngel714 (not verified) on Wed, 15/06/2011 - 02:22.Output from mediainfo is as follows
ME@Server:~$ mediainfo /data/media/anime/One\ Piece/One\ Piece\ 487.mkv
General
Unique ID : 196801525543001988175702038501177949050 (0x940E98596B6EB4FC8C740ACFB137FB7A)
Complete name : /data/media/anime/One Piece/One Piece 487.mkv
Format : Matroska
File size : 228 MiB
Duration : 23mn 31s
Overall bit rate : 1 353 Kbps
Encoded date : UTC 2011-02-13 02:03:39
Writing application : mkvmerge v4.0.0 ('The Stars were mine') built on Jun 6 2010 16:18:42
Writing library : libebml v1.0.0 + libmatroska v1.0.0
Video
ID : 1
Format : VP6
Format profile : Heightened Sharpness
Codec ID : VP6F
Codec ID/Hint : On2
Duration : 23mn 31s
Bit rate : 1 198 Kbps
Width : 640 pixels
Height : 368 pixels
Display aspect ratio : 16:9
Frame rate : 23.810 fps
Bits/(Pixel*Frame) : 0.214
Stream size : 202 MiB (89%)
Audio
ID : 2
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 3
Codec ID : A_MPEG/L3
Codec ID/Hint : MP3
Duration : 23mn 31s
Bit rate mode : Constant
Bit rate : 128 Kbps
Channel(s) : 2 channels
Sampling rate : 44.1 KHz
Compression mode : Lossy
Stream size : 21.5 MiB (9%)
Below is mencoder - not sure of command line arguments - and sadly I have to run to work before I can look into it... On a side note if it offer any more clues some of avi files do not work either and I DID have SOME of my mkv working but using a different script (but it was not a good script - some MKV had no sound / no caption / etc...)
ME@Server:~$ mencoder /data/media/anime/One\ Piece/One\ Piece\ 487.mkv -o /home/ME/temp.mpg
MEncoder 1.0rc4-4.5.2 (C) 2000-2010 MPlayer Team
WARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.
success: format: 0 data: 0x0 - 0xe3ae5d0
[mkv] Track ID 1: video (V_MS/VFW/FOURCC), -vid 0
[mkv] Track ID 2: audio (A_MPEG/L3), -aid 0, -alang und
[mkv] Will play video track 1.
Matroska file format detected.
VIDEO: [VP6F] 640x368 24bpp 23.810 fps 0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:31 fourcc:0x46365056 size:640x368 fps:23.810 ftime:=0.0420
No audio encoder (-oac) selected. Select one (see -oac help) or use -nosound.
Exiting...
could it have something to do with FOURCC (currently I have not using it (and I don't know what the command does) but the old config.xml used it for mkv if I remember correctly - would it help to paste my config.xml and the script? Thanks for the help!
- reply
Submitted by ArchAngel714 (not verified) on Tue, 14/06/2011 - 12:23.I got mediatomb and all the dependencies set up and installed. When I try to play any video from my PS3, I get the following error on the PS3: Media Server Error: A Network Error has Occured (000000000)
In mediatomb, this shows up:
INFO: Arguments: %in %out/usr/local/bin/mediatomb-multifunctional.sh: 2: Home: not found
/usr/local/bin/mediatomb-multifunctional.sh: 3: Info: not found
/usr/local/bin/mediatomb-multifunctional.sh: 4: ICT: not found
/usr/local/bin/mediatomb-multifunctional.sh: 5: Photo: not found
/usr/local/bin/mediatomb-multifunctional.sh: 6: Various: not found
/usr/local/bin/mediatomb-multifunctional.sh: 7: Contact: not found
/usr/local/bin/mediatomb-multifunctional.sh: 8: Home: not found
/usr/local/bin/mediatomb-multifunctional.sh: 13: MediaTomb: not found
/usr/local/bin/mediatomb-multifunctional.sh: 19: Last: not found
/usr/local/bin/mediatomb-multifunctional.sh: 20: Syntax error: "(" unexpected
Any thoughts?
- reply
Submitted by Sathed (not verified) on Fri, 20/05/2011 - 19:26.Figured it out. Accidentally deleted a line of code. With a few tweaks, this is working brilliantly.
- reply
Submitted by Sathed (not verified) on Tue, 31/05/2011 - 18:47.I spent a lot of time fixing this script to play most of my movies, music videoclips correctly: read below.
Philips 37PFL9603 DLNA : can only play mpeg2 videos and mp3 music files (and jpg's).
with this tv the video bit rate for HD 1920x1080 mpeg2 needs to be lowered to a certain threshold otherwise the processor of the tv can't decode fast enough. So you can't enjoy every "bit" of your original movie file but sitting from the screen at 2 meters it is not noticeable for me.
I assume newer tv's can decode better codecs (x264 etc) so if I ever earn lots of money I will buy me a new led tv that can play as many codecs possible.
Transcoding HD Movies (720p, 1080p) in real-time results in annoying glitches on the tv that appear every once in a while. Therefore I manually convert them to .mpg files using the mencoder command of mediatomb-multifunctional.sh with specific variables (like "-sid 1" to add the second subtitle from the mkv file or SUBSIZE=40 for HD movies or -subpos 85 etc: see below for details).
The heaviest movie that I converted to .mpg (x264 15 GB .mkv file to 28 GB .mpg file) can play on the tv but sometimes the video stutters or slows down. This quality loss was a bit annoying but I didn't want to spend more time on it trying a lower video bit rate.
Transcoding non-HD movies (mostly xvid) in real-time works: they play instantly on the tv without problem but on a big HD tv screen the image is not so nice. So I prefer HD versions.
A problem with transcoding in real-time is that you can only pause the video. You can't do fast rewind or fast forward. Only if the movie is served as a .mpg file can my tv do fast rewind or fast forward (actually on my tv it is kinda slow so it is only good for rewinding a few seconds or minutes if you have missed parts of a scene)
I first have to set my tv to the PC network, then I have to start the mediatomb program on my computer. Only then does my tv sees the mediatomb directories.
In MediaTomb Web UI I also had to to change the mimetype of some videoclips from "video/x-msvideo" to "video/transcode".
Fix for the function mediainfo:
The Width and Height extracted by the mediainfo program has a space in it when it is over 1000, like "1 200" so I added " | sed 's/ //g'" to the command to remove that space:
VWIDTH=$(${XML} sel -t -m ".//track[@type='Video']" -v "Width" \
${MIOUT} | sed 's/ pixels//' | sed 's/ //g' )
VHEIGHT=$(${XML} sel -t -m ".//track[@type='Video']" -v "Height" \
${MIOUT} | sed 's/ pixels//' | sed 's/ //g' )
vatbier@home videoclips]$ /usr/local/bin/mediatomb-multifunctional.sh Lena_Meyer-Landrut_-_Satellite_Eurovision_Song_Contest_2010_SC_X264_720p.mkv test.mpg
warning: failed to load external entity " "
if you get this warning, then remove the space behind
VWIDTH=$(${XML} sel -t -m ".//track[@type='Video']" -v "Width" \
and behind
VFPS=$(${XML} sel -t -m ".//track[@type='Video']" -v "Frame_rate" \
The fix for subtitles with spaces in their file name:
#OPTS=("")
#OPTS+=(${NOSIZEOPTS})
#echo OPTS: "${OPTS[@]}"
# with command "bash -x ..." you can see that it begins with ''
OPTS=()
# OPTS+=(${M_TR_M} -sub ${SUB} ${SRTOPTS} -o )
# changed to
# OPTS+=(-sub ${SUB} ${M_TR_M} ${SRTOPTS} -o )
# changed to (for subtitles with spaces in filename double quotes are necessary around SUB)
OPTS+=(-sub "${SUB}" ${M_TR_M} ${SRTOPTS} -o )
#exec ${EXEC} "${FILE}" ${OPTS[@]} "${2}" &>/dev/null
# double quotes necessary around OPTS:
exec ${EXEC} "${FILE}" "${OPTS[@]}" "${2}" &>/home/vatbier/.mediatomb/mencoder.log
For the heaviest movie (x264 x264 15 GB .mkv file to 28 GB .mpg file) it was extremely frustrating to find parameters that did not result in buffer underflow with the mencoder command (my tv can't handle buffer underflows in the encoded mpg):
I changed vrc_maxrate to 24000
vrc_buf_size to5350
I added "vbuf_size=400" to -mpegopts
MPEG muxer (-mpegopts)
vbuf_size=<40-1194>
Sets the size of the video decoder's buffer, expressed in kilobytes. Specify it only if the bitrate of the
video stream is too high for the chosen format and if you know perfectly well what you are doing. A too high
value may lead to an unplayable movie, depending on the player's capabilities. When muxing HDTV video a value
of 400 should suffice.
I changed muxrate to 3000000
SUBSIZE=20
# for some hd movies
SUBSIZE=40
# If downscaling is enabled, anything over this width (pixels) will be downscaled.
MAXSIZE=1280
#AABIT=256
# changed to:
AABIT=320
#for 1080p like A.:
#also good for D.
M_TR_M="-sid 1 -slang eng -oac lavc -ovc lavc -of mpeg -lavdopts threads=2 -lavcopts \
abitrate=${AABIT}:vcodec=mpeg2video:keyint=1:vbitrate=20000:\
vrc_maxrate=24000:vrc_buf_size=5350 \
-mpegopts vbuf_size=400:muxrate=3000000 -af lavcresample=44100 "
I put these lines completely to the left (column 0) because otherwise I got a space for the mencoder command: "...vbitrate=20000: vrc_maxrate=24000:..."
# for N. 1080p 10GB
M_TR_M="-sid 0 -slang eng -oac lavc -ovc lavc -of mpeg -lavdopts threads=2 -lavcopts \
abitrate=${AABIT}:vcodec=mpeg2video:keyint=1:vbitrate=20000:\
vrc_maxrate=24000:vrc_buf_size=5350 \
-mpegopts vbuf_size=400:muxrate=3000000 -af lavcresample=44100 "
#added for wmv clips that have wma sound:
ACODECERBIJ="-oac lavc -ovc lavc -of mpeg -lavdopts threads=2 -lavcopts \
acodec=libmp3lame:abitrate=${AABIT}:vcodec=mpeg2video:keyint=1:vbitrate=${AVBIT}:\
vrc_maxrate=${MVBIT}:vrc_buf_size=1835 \
-mpegopts muxrate=100000 -af lavcresample=44100 "
I added "-lavdopts threads=2" in the hope it would process faster.
The "-sid 1" or "-sid 0" depends on the subtitle you want from a .mkv (use mediainfo to see which subtitle you want).
SRTOPTS="-font ${SFONT} -subfont-autoscale 0 \
-subfont-text-scale ${SUBSIZE} -subpos 95 "
# for N.:
SRTOPTS="-font ${SFONT} -subfont-autoscale 0 \
-subfont-text-scale ${SUBSIZE} -subpos 85 "
for each HD movie that is not 16/9 I have to use mediainfo to see what the resolution is and then expand it to 1920x1080 or 1280x720:
#for D.:
SIZEOPTS="-vf harddup,scale=1920:1040,expand=1920:1080 "
#for N. 3 GB:
SIZEOPTS="-vf harddup,scale=1920:796,expand=1920:1080 "
#for N. 10 GB:
SIZEOPTS="-vf harddup,scale=1920:800,expand=1920:1080 "
#for N. 720p:
#SIZEOPTS="-vf harddup,scale=1280:528,expand=1280:720 "
#original:
#SIZEOPTS="-vf harddup,scale=720:-2 "
#changed to
SIZEOPTS="-vf harddup,scale=1280:-2 "
NOSIZEOPTS="-vf harddup "
#OPTS=("")
#OPTS+=(${NOSIZEOPTS})
#echo OPTS: "${OPTS[@]}"
# with command "bash -x ..." you can see that it begins with ''
OPTS=()
added
VHEIGHT=$(${XML} sel -t -m ".//track[@type='Video']" -v "Height" \
${MIOUT} | sed 's/ pixels//' | sed 's/ //g' )
log "Variables found: \
${VCODEC} | ${ACODEC} | ${VWIDTH} | ${VHEIGHT} | ${VFPS} | ${AVCPROF} | ${QPEL} "
function tropts {
((VW9=VWIDTH * 9))
((VH16=VHEIGHT * 16))
((VW3=VWIDTH * 3))
((VH4=VHEIGHT *4))
if [ "${DOWNSCALE}" == "1" -a \( ${VWIDTH} -gt ${MAXSIZE} -o ! \( $VW9 == $VH16 \) \) ]; then
# log "Rescaling to 720 pixels wide."
log "Rescaling to 1280 pixels wide or to 720 if vwidth is lower than 721"
if [ "${VWIDTH}" -lt "721" ]; then
SIZEOPTS="-vf harddup,scale=720:-2 "
fi
if [ "${VHEIGHT}" == "566" ]; then
log "Michael 1000x566"
SIZEOPTS="-vf harddup,scale=1280:720 "
fi
if [ "${VWIDTH}" == "620" -a "${VHEIGHT}" == "256" ]; then
log "Sunshine 620x256"
# SIZEOPTS="-vf harddup,scale=720:297,expand=720:576 " : subs are overlapping
SIZEOPTS="-vf harddup,scale=720:297,expand=720:576,scale=720:576 "
SUBSIZE=20
SRTOPTS="-font ${SFONT} -subfont-autoscale 0 \
-subfont-text-scale ${SUBSIZE} -subpos 85 "
fi
if [ "${VWIDTH}" == "720" -a "${VHEIGHT}" == "540" ]; then
log "Poker 720x540 (4/3)"
SIZEOPTS="-vf harddup,scale=720:540,expand=720:576 "
fi
if [ $VW3 == $VH4 ]; then
log "tender.wmv 640x480 (4/3)"
log "alle 320x240 en ook die ene 480x360"
SIZEOPTS="-vf harddup,scale=640:480,expand=1280:720 "
fi
if [ "${VHEIGHT}" == "380" ]; then
log "Inna"
SIZEOPTS="-vf harddup,scale=640:380,expand=640:480 "
fi
if [ "${VWIDTH}" == "1200" -a "${VHEIGHT}" == "544" ]; then
log "Calabria"
SIZEOPTS="-vf harddup,scale=1200:544,expand=1280:720 "
fi
if [ "${VWIDTH}" == "1000" -a "${VHEIGHT}" == "556" ]; then
log "kissed"
SIZEOPTS="-vf harddup,scale=1000:556,expand=1280:720 "
# hm, the tv still scales the black bands away
fi
OPTS+=(${SIZEOPTS})
else
added
else if [ "${VFPS}" == "15.000" -o "${VFPS}" == "30.000" -o "${VFPS}" == "25.000" ] ; then
log "Framerate adjusted for mencoder."
OPTS+=(-ofps 25)
else
log "Framerate acceptable for mencoder."
I added the ""${VFPS}" == "25.000"" because for one .wmv videclip mencoder tried to encode it to 1000 fps.
moved mediainfo to beginning of function getmode:
function getmode {
mediainfo
elif [ ! "${MODE}" -lt "100000" ] ; then
EXEC=${MENCODER}
tropts
# OPTS+=(${M_TR_M} -sub ${SUB} ${SRTOPTS} -o )
# changed to
# OPTS+=(-sub ${SUB} ${M_TR_M} ${SRTOPTS} -o )
# changed to (for subtitles with spaces in filename double quotes are necessary around SUB)
OPTS+=(-sub "${SUB}" ${M_TR_M} ${SRTOPTS} -o )
elif [ ! "${MODE}" -lt "10000" ] ; then
EXEC=${MENCODER}
tropts
# OPTS+=(${M_TR_M} -o )
# changed to
if [ ! \( "${MODE}" == "11000" -a "${ACODEC}" == "WMA" \) ] ; then
OPTS+=(${M_TR_M} -o )
else
OPTS+=(${ACODECERBIJ} -o )
fi
elif [ ! "${MODE}" -lt "10" ] ; then
# EXEC="${FFMPEG} -i"
# OPTS+=(${F_TR_M})
# changed to:
EXEC=${MENCODER}
tropts
# OPTS+=(${M_TR_M} -o)
# for N. 1080p 10 GB:
OPTS+=( ${M_TR_M} ${SRTOPTS} -o )
#exec ${EXEC} "${FILE}" ${OPTS[@]} "${2}" &>/dev/null
# double quotes necessary around OPTS:
exec ${EXEC} "${FILE}" "${OPTS[@]}" "${2}" &>/home/vatbier/.mediatomb/mencoder.log
- reply
Submitted by vatbier (not verified) on Wed, 27/04/2011 - 23:19.I have some problems getting this to work. The good news is that videos that previously showed up as unsupported now looks supported on the PS3. But when I try to play them I only get one of these in mediatomb.log
INFO: Arguments %in %out
Nothing is writting in the transcoding log, so it seems the script is not called.
Also, if I try to run the script from the shell I get an error message back:
~$ sudo bash /usr/local/bin/mediatomb-multifunctional.sh
/usr/local/bin/mediatomb-multifunctional.sh: line 120: [: too many arguments
What can be wrong here?
- reply
Submitted by Goran (not verified) on Wed, 30/03/2011 - 14:08.You can see in mediatomb-transcode.log that mediainfo has not run so ${VWIDTH} is not known.
Let mediainfo run at the beginning of function getmode.
- reply
Submitted by vatbier (not verified) on Wed, 27/04/2011 - 23:28.I have some problems getting this to work. The good news is that videos that previously showed up as unsupported now looks supported on the PS3. But when I try to play them I only get one of these in mediatomb.log
INFO: Arguments %in %out
Nothing is writting in the transcoding log, so it seems the script is not called.
Also, if I try to run the script from the shell I get an error message back:
~$ sudo bash /usr/local/bin/mediatomb-multifunctional.sh
/usr/local/bin/mediatomb-multifunctional.sh: line 120: [: too many arguments
What can be wrong here?
- reply
Submitted by Goran (not verified) on Wed, 30/03/2011 - 14:00.Thanks a lot for this great script!
One thing I'm missing though, moving from PS3Mediaserver, is the ability to pause, FF and REW. This was possible using the PS3Mediaserver (tsMuxer I think). The reason I'd rather go for Mediatomb is option to customize.
Anyonw got a clue how to support pause, ff and rew?
- reply
Submitted by Someone (not verified) on Thu, 24/03/2011 - 15:13.Pause is easy - just press the PS button. Fast forward and rewind are not possible with MT though, unless you remux all your files to m2ts upfront.
- reply
Submitted by Lennert on Thu, 24/03/2011 - 15:18.I changed the script slightly to allow for deinterlacing of interlaced content.
I introduced two new variables for the video format:
SIZEOPTS="-vf harddup,scale=720:-2 "
NOSIZEOPTS="-vf harddup "
SIZEOPTS_DE="-vf pp=fd,scale=720:-2 "
NOSIZEOPTS_DE="-vf pp=fd "
and a variable to hold the information from mediainfo:
VFPS=""
VSCAN=""
QPEL=""
It is set in the mediainfo function as follows:
VSCAN=$(${XML} sel -t -m ".//track[@type='Video']" -v "Scan_type" ${MIOUT} )
I then changed the first section in the tropts function:
function tropts {
if [ "${DOWNSCALE}" == "1" -a ${VWIDTH} -gt ${MAXSIZE} ] ; then
if [ "${VSCAN}" == "Interlaced" ] ; then
log "Deinterlacing and rescaling to 720 pixels wide."
OPTS+=(${SIZEOPTS_DE})
else
log "Rescaling to 720 pixels wide."
OPTS+=(${SIZEOPTS})
fi
else
if [ "${VSCAN}" == "Interlaced" ] ; then
log "Deinterlacing and rescaling disabled or file within limits."
OPTS+=(${NOSIZEOPTS_DE})
else
log "Rescaling disabled or file within limits."
OPTS+=(${NOSIZEOPTS})
fi
fi
I am sure it can be done better than using those nested if statements, but I am not much of a shell script programmer. It works though :)
- reply
Submitted by Roenbaeck (not verified) on Sun, 20/03/2011 - 12:56.do you have any idea, why audio isn't working in mkv's? im' using lgTV for dlna streaming..
- reply
Submitted by Someone (not verified) on Wed, 16/03/2011 - 01:00.Hi,
I'm having trouble running the script. I am using Ubuntu 10.10. The error appears reports as the following.
2011-03-01 20:15:24 INFO: Arguments: %in %out
/usr/local/bin/multifunctional.sh: line 104: sel: command not found
/usr/local/bin/multifunctional.sh: line 105: sel: command not found
/usr/local/bin/multifunctional.sh: line 107: sel: command not found
/usr/local/bin/multifunctional.sh: line 108: /tmp/tmp.mediainfo.nqsBp6: Permission denied
/usr/local/bin/multifunctional.sh: line 109: sel: command not found
/usr/local/bin/multifunctional.sh: line 110: /tmp/tmp.mediainfo.nqsBp6: Permission denied
/usr/local/bin/multifunctional.sh: line 111: sel: command not found
/usr/local/bin/multifunctional.sh: line 113: sel: command not found
/usr/local/bin/multifunctional.sh: line 120: [: too many arguments
It would appear that the sel command is missing but I can't find it anywhere...any ideas?
Thanks
- reply
Submitted by zef (not verified) on Tue, 01/03/2011 - 22:20.same problem. any solved this already?
- reply
Submitted by mekulot-noob (not verified) on Thu, 03/03/2011 - 18:13.Yep... you don't have xmlstarlet installed. :-)
- reply
Submitted by Lennert on Thu, 03/03/2011 - 18:19.thank you for the response but after i installed xmlstarlet i got a diff error.
its says:
mediatomb-multifunctional.sh: line 103: --output=xml: command not found
- reply
Submitted by mekulot (not verified) on Sat, 12/03/2011 - 07:31.that was stupid
i didnt have mediainfo installed now i have this:
INFO: Arguments: %in %out
i am able to play divx avi's but not avi's that are h264
please help!
- reply
Submitted by mekulot (not verified) on Sat, 12/03/2011 - 07:57.I dont know whati did. i got drunk last night and when i turned my ps3 on and i was able to watch the vid.
by the way you guyabout:homesabout:home rule
- reply
Submitted by mekulot (not verified) on Sun, 13/03/2011 - 05:17.I'm an idiot...I installed xmlstarlet and got further. Now fails with
2011-03-01 20:52:22 INFO: Arguments: %in %out
warning: failed to load external entity " "
/usr/local/bin/multifunctional.sh: line 108: /tmp/tmp.mediainfo.8UNxK3: Permission denied
warning: failed to load external entity " "
/usr/local/bin/multifunctional.sh: line 110: /tmp/tmp.mediainfo.8UNxK3: Permission denied
/usr/local/bin/multifunctional.sh: line 120: [: too many arguments
- reply
Submitted by zef (not verified) on Tue, 01/03/2011 - 22:57.