Page 1 of 1

how to make a ffmpeg wrapper ?

PostPosted: Thu Dec 08, 2011 12:34 pm
by xrensgory
Hi!
I use serviio 0.6.0.1 on FreeBSD/amd64 from ports collection. And I have some problems when playing videos on xbox360 slim.
Playing is very laggy.
My hardware is intel quad-core Q6600 running at 2,4GHz with 8GB of RAM.
Careful study showed that FFmpeg works in one thread. I wrote a ffmpeg wrapper called ffmpeg-mt, which clearly indicated the parameters:
/usr/local/bin/ffmpeg-mt
  Code:
#!/bin/sh
/usr/local/bin/ffmpeg -threads 4 $@


And edited /usr/local/sbin/serviiod
  Code:
gsed -i 's/ffmpeg"/ffmpeg-mt"/' /usr/local/sbin/serviiod


cat /usr/local/sbin/serviiod
  Code:
#!/bin/sh
### ====================================================================== ###
##                                                                          ##
##  Serviio start Script                                                    ##
##                                                                          ##
### ====================================================================== ###

SERVIIO_HOME=/usr/local/share/java/classes/serviio
SERVIIO_CLASS_PATH="$SERVIIO_HOME/serviio.jar"
# Setup the classpath
for j in derby jcs concurrent freemarker httpcore jaudiotagger  \
    jul-to-slf4j jcl-over-slf4j log4j sanselan slf4j-api        \
    slf4j-log4j12 org.restlet org.restlet.ext.xstream xstream   \
    rome rome-modules jdom groovy-all winp org.restlet.ext.gson gson
do
        SERVIIO_CLASS_PATH="$SERVIIO_CLASS_PATH:$SERVIIO_HOME/$j.jar"
done
SERVIIO_CLASS_PATH="$SERVIIO_CLASS_PATH:/usr/local/etc/serviio"

# Setup Serviio specific properties
JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Dderby.system.home=/var/db/serviio -Dserviio.home=$SERVIIO_HOME -Dffmpeg.location=/usr/local/bin/ffmpeg-mt"


# A kludge to get the -D... flags to Java, rather than to Serviio itself:
for o in "$@"
do
        case $o in
        -D*)
                JAVA_OPTS="$JAVA_OPTS $o"
                ;;
        esac
done

# Execute the JVM in the foreground
exec java -Xmx384M $JAVA_OPTS -classpath "$SERVIIO_CLASS_PATH" org.serviio.MediaServer "$@"


In this case the wrapper correctly work from the command line, but does not runs from serviio.

grep -A 3 ffmpeg-mt /var/log/serviio/serviio.log
  Code:
2011-12-08 06:30:48,121 WARN  [ProcessExecutor] Process /usr/local/bin/ffmpeg-mt has a return code of 1! This is a possible error.
2011-12-08 06:30:55,726 ERROR [ResourceTransportRequestHandler] Error while processing resource, sending back 500 error. Message: Transcoded file '/home/archive/pub/tmp/Serviio/transcoding-temp-26192-ASF.stf' cannot be found, FFmpeg execution probably failed
java.io.IOException: Transcoded file '/home/archive/pub/tmp/Serviio/transcoding-temp-26192-ASF.stf' cannot be found, FFmpeg execution probably failed
        at org.serviio.delivery.resource.AbstractTranscodingDeliveryEngine.retrieveTranscodedResource(AbstractTranscodingDeliveryEngine.java:115)


How do I correctly specify serviio to run ffmpeg in 4 threads?

Re: how to make a ffmpeg wrapper ?

PostPosted: Thu Dec 08, 2011 1:45 pm
by zip
The wmv encoder in FFMpeg only works with 1 thread, that's why it fails and that's why Serviio ignores the threads setting for wmv encoding.

Re: how to make a ffmpeg wrapper ?

PostPosted: Thu Dec 08, 2011 2:02 pm
by xrensgory
damn.. i forgot it.. But anyway thank you for your help :)

Re: how to make a ffmpeg wrapper ?

PostPosted: Mon Dec 19, 2011 8:47 am
by abeloin
Maybe useful to some.

I have a similar lag issue on the Xbox 360's with transcoded 1920x1080 video. Changing the bitrate didn't helped and as my TV is only 480p, I've resized the video in the transcoding phase(meaning any transcoded video will be resized).

EX: Serviio reside in /opt/serviio

Create a file ffmpeg-custom in the folder /opt/serviio/bin. Make it executable.
  Code:
#!/bin/bash
args=("$@")
/usr/bin/ffmpeg -vf scale=640:-1 "${args[@]}"


Edit /opt/serviio/bin/serviio.sh and add the following in JAVA_OPTS:
  Code:
-Dffmpeg.location=/opt/serviio/bin/ffmpeg-custom

Re: how to make a ffmpeg wrapper ?

PostPosted: Mon Dec 19, 2011 8:56 am
by Illico
You coud also use ServiioService.exe.vmoptions: -Dffmpeg.location=
Like this
viewtopic.php?f=11&t=2956&start=30#p27617