Announcement

Collapse
No announcement yet.

Mplayer VDPAU auto codec selection script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mplayer VDPAU auto codec selection script

    I recently wrote a script such that I could easily playback files easily in mythtv. It just finds out which codec the file in question is using, and launches mplayer with the correct codec. Nothing much, but I thought someone might find it useful. Just change the $mplayerlocation to wherever it is on your computer and uncomment the last if fi statement to enable vc-1.

    Code:
    #!/bin/bash
    #Script to automatically find out which codec a file is using and determine whether or not to use VDPAU.
    
    #if no input display usage
    if [ -z "$1" ]; then
    	echo usage: $0 /path/to/file
    	exit
    fi
    
    #remember to change this to the path of your mplayer binary
    mplayerlocation=/usr/local/bin/mplayer-vdpau-3263604/mplayer-vdpau
    cd $mplayerlocation
    
    #kinda a lame way to do it, but bring up mplayer and pipe the output to a temporary file, then read which codec the file is
    ./mplayer -identify -vo vdpau $1 > /tmp/VIDEOCODEC &
    sleep 0.5
    killall mplayer
    videocodec=`cat /tmp/VIDEOCODEC | grep ID_VIDEO_CODEC | cut -c 16-25`
    rm /tmp/VIDEOCODEC
    
    echo "VIDEO CODEC: $videocodec"
    
    if [ $videocodec = "ffh264" ]; then
    	codec='h264'
    	echo \n Playing $1 with $codec codec \n
    	./mplayer -vo vdpau -vc ffh264vdpau $1
    
    	exit
    fi
    
    if [ $videocodec = "ffmpeg2" ]; then
    	codec='MPEG2'
    	echo \n Playing $1 with $codec codec \n
    	./mplayer -vo vdpau -vc ffmpeg12vdpau $1
    
    	exit
    fi
    
    if [ $videocodec = "ffwmv3" ]; then
    	codec='WMV3'
    	echo \n Playing $1 with $codec codec \n
    	./mplayer -vo vdpau -vc ffwmv3vdpau $1
    
    	exit
    fi
    
    #VC1 is not supported on most gpus
    #uncomment if it is supported on your gpu
    #if [ $videocodec = "ffvc1" ]; then
    #	codec='VC1'
    #	echo \n Playing $1 with $codec codec \n
    #	./mplayer -vo vdpau -vc ffvc1vdpau $1
    #
    #	exit
    #fi
    
    #if it isnt one of those it is not supported by vdpau
    #so we should play without vdpau
    ./mplayer $1
    exit

  • #2
    Isn't it simpler to use the xine-vdpau solution?

    Comment


    • #3
      Yes, it is probably simpler, but from what I can gather, the xine solution is much less stable at the moment, although I havent actually tried xine yet.

      Comment


      • #4
        Originally posted by Kano View Post
        Isn't it simpler to use the xine-vdpau solution?
        xine-vdpau still doesn't support containers that are commonly used for HD (mkv,mov), mplayer already does. xine-vdpau is focusing first on the vdr stream playback part of things first

        Comment


        • #5
          slightly modified version

          I made a few minor changes to the script above, largely getting rid of the /tmp/ bits.
          iapitus

          Code:
          #!/bin/bash
          # Script to automatically find out which codec a file is using and determine whether or not to use VDPAU.
          # Rev.0 - bal_zac original - posted on phoronix
          # Rev.2 - largely stylistic changes - removed need for tmp files and changed if statements to a single case statement
          
          IAM=$0
          FILE=$1
          
          #if no input display usage
          if [[ -z "$FILE" ]]; then
          	echo usage: $0 /path/to/file
          	exit
          fi
          
          MPLAYER=/usr/bin/mplayer
          MPLAYEROPTS="-fs -zoom -af volnorm=2 -ao pulse"
          VCODEC=$($MPLAYER -identify -vo vdpau -frames 0 "$FILE" | grep ID_VIDEO_CODEC | cut -c 16-25)
          
          
          echo "VIDEO CODEC: $VCODEC"
          
          case $VCODEC in
           ffh264) 
            echo -e "Playing h.264 file $FILE:\n"
            MPLAYEROPTS="$MPLAYEROPTS -vo vdpau -vc ffh264vdpau"
          ;;
           ffmpeg2)
            echo -e "Playing MPEG2 file $FILE:\n"
            MPLAYEROPTS="$MPLAYEROPTS -vo vdpau -vc ffmpeg12vdpau"
          ;;
           ffwmv3)
            echo -e "Playing WMV3 file $FILE:\n"
            MPLAYEROPTS="$MPLAYEROPTS -vo vdpau -vc ffwmv3vdpau"
          ;;
           # VC-1 is largely unsupported by nvidia - uncomment this section if you're sure your card supports it.
           #ffvc1)
           # echo -e "Playing VC-1 file $FILE:\n"
           # MPLAYEROPTS="$MPLAYEROPTS -vo vdpau -vc ffvc1vdpau"
           #;;
           *)
            echo -e "Playing normal file $FILE:\n"
            MPLAYEROPTS="$MPLAYEROPTS -vo xv"
          ;;
          esac
          
          $MPLAYER $MPLAYEROPTS $FILE

          Comment


          • #6
            You can always use -vo vdpau, also you can use

            case $VCODEC in
            ffh264|ffwmv3|ffmpeg12)
            VCODEC=${VCODEC}vdpau
            ;;
            esac

            and then just execute - in that case you can add even more options.

            $MPLAYER -vo vdpau -vc $VCODEC "$@"

            Comment


            • #7
              Why not just put a list of the video outputs and codecs you want to try in your ~/.mplayer/config file? As in:

              # default to using vdpau output and codecs

              # add ffvc1vdpau if your hardware supports it

              # the trailing comma in each setting tells mplayer to
              # fall back to standard codecs if necessary
              vo=vdpau,xv,
              vc=ffh264vdpau,ffmpeg12vdpau,

              Comment


              • #8
                Originally posted by ashwb View Post
                Why not just put a list of the video outputs and codecs you want to try in your ~/.mplayer/config file? As in:

                # default to using vdpau output and codecs

                # add ffvc1vdpau if your hardware supports it

                # the trailing comma in each setting tells mplayer to
                # fall back to standard codecs if necessary
                vo=vdpau,xv,
                vc=ffh264vdpau,ffmpeg12vdpau,
                This works!

                Comment


                • #9
                  What is your expert opinion on the recent release of Nvidia 180 series featuring VDPAU in LINUX. Can it be taken as an equivalent with Pure video on Windows? Can VDPAU et hardware decoding of MPEG, VCI Video etc if we had installed a suitable driver and a proper video player. I heard that MPlayer works in VDPAU with some configuration done. Is it trustworthy? The latest NVidia driver is required for that. Am I correct?

                  Comment

                  Working...
                  X