Sign up here and you can log into the forum!

Auto framerate/resolution plugin for WDLXTV

Here is the place to inquire about app.bins--Only currently available apps for sigma 8655 based wdtv's belong in this forum. requests go in 'Application Questions'

Auto framerate/resolution plugin for WDLXTV   

Postby psychodad » Mon Jun 21, 2010 10:21 am


Auto framerate/resolution plugin for WDLXTV


***** Download *************

Version 0.40 - http://www.mediafire.com/download.php?wudgjgzyn2y
Version 0.41 - http://www.mediafire.com/?2gn2nmjouoh
Version 0.42 - http://www.mediafire.com/?azzdzj2lm5j
Version 0.50 - http://www.mediafire.com/?4i8ly0ghzsonxbh
Version 0.52 - http://www.mediafire.com/?c0et1nsidogbn43
Version 0.53 - http://www.mediafire.com/?rmcsfc5f4jzpnfc

***** Features *************

  • on-the-fly selection of the best fitting resolution and/or framerate when playing videos,
    based on a video analysis with ffmpeg (works with hdmi connections only)
  • preselection of an audio track based on the track's codec (and/or language for mkv/m2ts files)
  • preselection of an subtitle track based on the tracks' language and/or mode (full/forced) for mkv files
  • on-the-fly selection of an audio output mode (stereo/digital) based on the audio track's codec
  • includes b-rad's autozoom plugin to help people with overscan issues
  • the leds on the WD player can be disabled for video playback

***** Required firmware ******

WDLXTV-Plus - 1.03.29
WDLXTV-Live - 1.02.21
WDLXTV-G2 - 1.01.77

***** How to install *******

Put the files "autores.app.bin" AND "autores.conf" into your usb stick's root and turn on your WD TV with the usb stick plugged in. The plugin will load automatically.

***** Attention *******

This package is integrated into 1.02.21 based WDLXTV-Live & 1.01.77 based WDLXTV-G2 - you do NOT need this app.bin

***** Configuration ********

Edit the autores.conf on the usb stick.
All options in the config file are commented, read carefully!

********* Notes *************

If multiple output modes are available the script uses ffmpeg to choose the best setting.
Selection priority is in the following order:

1. Framerate
2. Resolution

********* Changelog *************

Version 0.53
- fixed a bug which prevented displaying the correct name and language of subtitles and audio tracks
- automatic audio/subtitle selection are disabled by default, edit autores.conf to enable
- updated autores.conf to version 7, older configs are not valid anymore

Version 0.52
- added support for WDLXTV-Plus 1.03.29
- added automatic audio track selection based on codec (and language for mkv/m2ts files)
- added automatic subtitle selection based on language and mode (forced/full) for mkv files
- audio output mode selection can be disabled for particular audio modes
- all features except resolution/framerate selection are working with rgb output too
- video analysis will be canceled after 15 seconds to prevent OSD hanging
- included a custom ffmpeg binary to detect forced subtitles
- removed mediainfo binary and libs
- updated autores.conf to version 6, older configs are not valid anymore
- an autores.conf file with windows line breaks will be automatically converted to unix format,
e.g. if you use the filemanager in the webend

Version 0.50
- integrated b-rad's autozoom plugin
- you can remove the usb stick after booting
- the autores.conf file must be always on the usb stick now
- single quotes in filenames are allowed now
- plugin will always prefer progressive mode, interlaced mode has to be enforced with filepath filter
- suggested_video_mode variable in the video info file was incorrect sometimes
- logging errors to /tmp/autores.log

Version 0.42
- fixed a bug with filename handling (mostly occurs with some media servers)

Version 0.41
- now the plugin works with with the UMSP media server too (e.g. apple trailers)
- configuration can be done by placing autores.conf on usb stick
- fixed a problem with audio mode detection


psychodad
Last edited by psychodad on Sat Oct 16, 2010 4:31 am, edited 6 times in total.
psychodad
Developer
 
Posts: 186
Joined: Thu May 06, 2010 8:42 am

Re: Auto framerate/resolution plugin for WDLXTV   

Postby thespecialist » Mon Jun 21, 2010 1:09 pm

Ah, the first public release ? Nice, congrats, I couldn't use the WDTV Live without your plugin anymore ;)
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Auto framerate/resolution plugin for WDLXTV   

Postby inspectah_deck » Tue Jun 22, 2010 4:51 pm

nice work, but i have no idea how to properly edit the autores.conf.
would be great if you could comment a litte bit for the not so tech-savvy people on how to change the settings.
what do i have to change to always let the script choose the correct framerate, based on mediainfo/ffmpeg.
i have a 1080p panel with all the videomodes supported.

Code: Select all
#####################  start of config  ########################
#
#  Set the video output resolutions/framerates you want.
#
#  BE SURE TO SET ONLY OUTPUT MODES YOUR TV SUPPORTS, OTHERWISE WITH ENABLED FORCEHDMI OPTION YOU GET A BLACK SCREEN !!!
#
#  The format is:
#
#  video_modes="
#  <pathfilter1>:<resolution1>|<resolution2>|...
#  <pathfilter2>:<resolution1>|<resolution2>|...
#  ...
#  "
#  pathfilter is an egrep pattern. The first filter matching the video filepath wins the race. Do NOT use spaces anywhere!
#
#  Below is my setting as an example, it contains all valid video output modes too:
#  My video filenames contain the refresh rate already ([60], [50], [24], [23.976]) and I want 1080p output.
#  If the refresh rate is missing let the script choose the best resolution/framerate, based on mediainfo/ffmpeg.
#  Just remove the resolutions you do not want (or your tv doesn't support)
#
video_modes="
\[60\]:1080p60
\[50\]:1080p50
\[24\]:1080p24
\[23.976\]:1080p23
*:1080p60|1080p50|1080p24|1080p23|1080i60|1080i50|720p60|720p50|576p50|576i50|480p60|480i60
"


#  Use the next setting to force an audio output mode for specific files.
#
#  The format is:
#
#  audio_modes="
#  <pathfilter1>:<audio_mode>
#  <pathfilter2>:<audio_mode>
#  ...
#  "
#
#  pathfilter is an egrep pattern. Valid audio modes are: digital, stereo
#  If no filter matches, the audio mode configured in the WD TV settings menu will be used.
#
audio_modes="
"


#  Audio output mode configuration based on parsing of ffmpeg output (mediainfo currently not supported).
#  This is an option for advanced users! Change it only, if you know what you're doing!
#  Currently used to set audio output mode to stereo for aac multichannel.
#
#  The format is:
#
#  audio_modes_filters="
#  <egrep_pattern>:<audio_mode>
#  <egrep_pattern>:<audio_mode>
#  ...
#  "
#
audio_modes_filters="
Audio.*aac.*(5\.1|channels):stereo
"


#  Set the allowed video extensions (without dot), all others will be ignored
#
#  !!! WARNING !!!
#    ISO files are not supported by ffmpeg! Add this extension at your own risk!
#
valid_video_extensions="avi|mkv|vob|wmv|mpeg|mpg|m2ts|mov|mp4|3gp|3g2|ts"


#  1 = turn off leds when playing video files
#
turn_off_leds_on_play=1


#  1 = turn on leds after playing video files
#
turn_on_leds_after_play=1


#  1 = after playback return to the video output mode configured in the WD TV video settings menu
#  0 = leave menu output mode as it is.
#
set_menu_video_mode=1


#  Additional to the video output mode set in the WD TV gui you can define here which output modes
#  are valid for menu display too. Thus reducing hdmi reconfigurations to a minimum.
#
additional_menu_video_modes="1080p60|1080p50|1080p24|1080p23|1080i60|1080i50|720p60|720p50"


#####################  end of config  ##########################
inspectah_deck
WDTVer
 
Posts: 22
Joined: Wed Jun 16, 2010 4:49 pm

Re: Auto framerate/resolution plugin for WDLXTV   

Postby thespecialist » Tue Jun 22, 2010 5:09 pm

This is the line you will want to edit:

*:1080p60|1080p50|1080p24|1080p23|1080i60|1080i50|720p60|720p50|576p50|576i50|480p60|480i60

In this line simply remove the resolution/framerates your TV doesn't support. For example, let's say you have a US TV, then it will most likely (there are exceptions !) not support 50 hz. (Most european TV's support both the european 50 hz and the US 60 hz standard, not sure if that's an indication of arrogance of one of those continents ? ;) )

Also let's say your TV supports both 24h and 23.976 hz but only for 1080p (like my XBR9 does). In that case you'll end up with something like:

*:1080p60|1080p24|1080p23|1080i60|720p60|480p60|480i60
Last edited by thespecialist on Tue Jun 22, 2010 7:40 pm, edited 5 times in total.
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Auto framerate/resolution plugin for WDLXTV   

Postby thespecialist » Tue Jun 22, 2010 5:21 pm

And to explain this part:

\[60\]:1080p60
\[50\]:1080p50
\[24\]:1080p24
\[23.976\]:1080p23

I'm not using this functionality myself, but here is what it does: you can bypass the whole 'video detection' phase, by adding something to your filename. For example, if you add [60] to your filename, then it will bypass detection and just use 1080p60 for that particular video file. If you remove that part from the config, then it won't do this. But if you don't plan on using it (like me), then you don't need to change anything here.

So for most users, all you need to do is edit that line that I explained in my previous post.
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Auto framerate/resolution plugin for WDLXTV   

Postby inspectah_deck » Tue Jun 22, 2010 5:38 pm

thanks for the quick reply. :)
i edited the line, but it´s kind of strange, my wd doesnt change the framerate according to the videofile.
i have the app.bin in the root of the usbdrive with all my movies in it.
the resolution is set to hdmi(auto) in the settings menu (which is 1080p60hz), but it doesn't change when i select a 23,976 fps movie for example. it always stays at 60hz. :cry:
inspectah_deck
WDTVer
 
Posts: 22
Joined: Wed Jun 16, 2010 4:49 pm

Re: Auto framerate/resolution plugin for WDLXTV   

Postby thespecialist » Tue Jun 22, 2010 7:34 pm

inspectah_deck wrote:thanks for the quick reply. :)
i edited the line, but it´s kind of strange, my wd doesnt change the framerate according to the videofile.
i have the app.bin in the root of the usbdrive with all my movies in it.
the resolution is set to hdmi(auto) in the settings menu (which is 1080p60hz), but it doesn't change when i select a 23,976 fps movie for example. it always stays at 60hz. :cry:

The easy way to see if the plugin is even active is to watch the LEDS: by default the plugin switches off the LED's during video play. If that doesn't happen, the plugin hasn't been loaded/doesn't work.

Apart from that, I'm not sure how you concluded that the plugin doesn't work, it SEEMS you came to that conclusion by watching the menu but the menu itself never changes: the plugin just auto switches when you start playing a video and switches it back when you stop the video. Maybe your TV shows the used resolution/frequency on screen (mine does by switching it on/off), that's also an easy way of verifying that it works.
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Auto framerate/resolution plugin for WDLXTV   

Postby KAD » Tue Jun 22, 2010 8:48 pm

awsome thanks, now if I can get my daughter off the tv, I'll try it out

KAD
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
PM's are for private matters. Post support questions to the appropriate forum, or they will be ignored.
User avatar
KAD
Global Moderator
 
Posts: 5103
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: Auto framerate/resolution plugin for WDLXTV   

Postby psychodad » Tue Jun 22, 2010 11:07 pm

inspectah_deck wrote:thanks for the quick reply. :)
i edited the line, but it´s kind of strange, my wd doesnt change the framerate according to the videofile.
i have the app.bin in the root of the usbdrive with all my movies in it.
the resolution is set to hdmi(auto) in the settings menu (which is 1080p60hz), but it doesn't change when i select a 23,976 fps movie for example. it always stays at 60hz. :cry:


if you have access to your wd via telnet/ssh:
1) check contents of file /tmp/autores.log, it should contain something like "patching... all done".
2) during video playback do "cat /tmp/autores.tmp" on console. the file should contain infos about the video and the used resolution.

thx specialist for explaining some things ;)
psychodad
Developer
 
Posts: 186
Joined: Thu May 06, 2010 8:42 am

Re: Auto framerate/resolution plugin for WDLXTV   

Postby inspectah_deck » Wed Jun 23, 2010 2:26 am

thespecialist wrote:The easy way to see if the plugin is even active is to watch the LEDS: by default the plugin switches off the LED's during video play. If that doesn't happen, the plugin hasn't been loaded/doesn't work.

Apart from that, I'm not sure how you concluded that the plugin doesn't work, it SEEMS you came to that conclusion by watching the menu but the menu itself never changes: the plugin just auto switches when you start playing a video and switches it back when you stop the video. Maybe your TV shows the used resolution/frequency on screen (mine does by switching it on/off), that's also an easy way of verifying that it works.


my samsung has an info button on the remote, where i can always see the current resolution/refreshrate, so it was during movie playback.
seems like the plugin isn´t working for me, the leds don´t turn off during playback.

psychodad wrote:if you have access to your wd via telnet/ssh:
1) check contents of file /tmp/autores.log, it should contain something like "patching... all done".

i think this looks fine:
Code: Select all
# cat autores.log
Waiting for dmaosd ...
Found dmaosd process (1633) ...
Found dmaosd version "WD TV Live 1.02.21", patching ...
All done!

psychodad wrote:2) during video playback do "cat /tmp/autores.tmp" on console. the file should contain infos about the video and the used resolution.

autores.tmp is not there, but i have an autores.sh.
this is what it shows during playback of a 23,976fps 1080p mkv, looks like alot of errors:
Code: Select all
# cat autores.sh
#!/bin/sh

if [[ $(echo "$1" | egrep -c "\.xml$") -eq 1 && "$1" != "video_run.xml" && "$1" != "screensaver.xml" ]]; then
  exit 1
fi

PATH=/apps/autores/bin:$PATH
LD_CONFIG=/apps/autores/lib:$LD_CONFIG
export PATH LD_CONFIG

############# functions ################


_exit()
{
  echo "*****************************************************************************************************"
  exit $1
}

_set_video_mode_and_exit()
{
  echo "INFO: current video output mode=$current_video_mode, requested video output mode=$1"
  if [ "$1" != "$current_video_mode" ]; then
    config_tool -c VIDEO_OUT_RESOLUTION=$1 >/dev/null
    echo "INFO: setting new video output mode ..."
    _exit 0
  else
    echo "INFO: no change required ..."
    _exit 1
  fi
}

_set_audio_mode()
{
  echo "INFO: current audio output mode=$current_audio_mode, requested audio output mode=$1"
  if [ "$1" != "$current_audio_mode" ]; then
    if [ "$1" == "digital" ]; then
      config_tool -c AUDIO_OUT=1 >/dev/null
    elif [ "$1" == "stereo" ]; then
      config_tool -c AUDIO_OUT=0 >/dev/null
    fi
    echo "INFO: setting new audio output mode ..."
  else
    echo "INFO: no change required ..."
  fi
}

_launch_mediainfo()
{
  mediaresults_all=$($mediainfo "--Inform=Video;%FrameRate%,%Width%,%Height%,%Format%" "$file")
  mediaresults="$mediaresults_all"
  if [ $? -ne 0 ]; then
    echo "ERROR: failed to launch mediainfo: $mediainfo --Inform=Video;%FrameRate%,%Width%,%Height%,%Format% $file"
    echo "ERROR: exiting ..."
    _exit 1
  fi
  video_fps=$(echo "$mediaresults" | cut -d \, -f 1)
  video_width=$(echo "$mediaresults" | cut -d \, -f 2)
  video_height=$(echo "$mediaresults" | cut -d \, -f 3)
  video_format=$(echo "$mediaresults" | cut -d \, -f 4)
  case "$video_fps" in
    23.976 | 24.000 | 25.000 | 29.970 )
      ;;
    * )
      video_fps="29.970"
      echo "INFO: can not detect video frame rate, setting fps to $video_fps"
      ;;
  esac
}

_launch_ffmpeg()
{
  mediaresults_all=$($ffmpeg -i "$file" 2>&1)
  mediaresults=$(echo $mediaresults_all | egrep -io -m 1 "Video:.*tbc" | tr ' ' ',')
  if [ "$mediaresults" == "" ]; then
    echo "ERROR: failed to launch ffmpeg: $ffmpeg -i $file"
    echo "ERROR: exiting ..."
    _exit 1
  fi
#  echo "$mediaresults"
#  Video:,mpeg4,,yuv420p,,640x272,[PAR,1:1,DAR,40:17],,23.98,tbr,,23.98,tbn,,23.98,tbc,Stream
  video_format=$(echo "$mediaresults" | cut -d \, -f 2)
  tmp=$(echo "$mediaresults" | cut -d \, -f 6)
  video_width=$(echo "$tmp" | cut -d \x -f 1)
  video_height=$(echo "$tmp" | cut -d \x -f 2)
  case "$mediaresults" in
    *,25,*|*,50,* )
      video_fps="25.000"
      ;;
    *,29.97,*|*,59.94,* )
      video_fps="29.970"
      ;;
    *,23.98,*|*,47.95,* )
      video_fps="23.976"
      ;;
    *,24,*|*,48,*|*,24.01,* )
      video_fps="24.000"
      ;;
    * )
      video_fps="29.970"
      echo "INFO: can not detect video frame rate, setting fps to $video_fps"
      ;;
  esac
}


########################### main ################################


echo "*****************************************************************************************************"
echo "*                                                                                                   *"
echo "*                         auto resolution/framerate plugin by psychodad                             *"
echo "*                                                                                                   *"
echo "*****************************************************************************************************"

### default config ####

video_modes=
valid_video_extensions=
turn_off_leds_on_play=1
turn_on_leds_after_play=1
set_menu_video_mode=1
additional_menu_video_modes=

### load config file ###

configfile="/conf/autores.conf"
if [ ! -f "$configfile" ]; then
  echo "ERROR: config file $configfile does not exist!"
  _exit 1
fi
source "$configfile"
if [ "$video_modes" == "" ]; then
  echo "ERROR: video_modes not set in config file $configfile!"
  _exit 1
fi
if [ "$valid_video_extensions" == "" ]; then
  echo "ERROR: valid_video_extensions not set in config file $configfile!"
  _exit 1
fi

### initialization ####

VER=030
file="$1"                        # input file
mediainfo="mediainfo"            # path to mediainfo binary
ffmpeg="ffmpeg"                  # path to ffmpeg binary
selected_media_tool="ffmpeg"     # ffmpeg is default because its faster
tmpfile="/tmp/autores.tmp"       # file for saving menu output mode and video parameters

current_output_mode=$(cat /conf/config | grep "VIDEO_OUT=" | cut -d \' -f 2 | tr '[A-Z]' '[a-z]')
if [ "$current_output_mode" != "hdmi" ]; then
  echo "ERROR: current video output mode is not set to HDMI, exiting ..."
  _exit 1
fi

### get current video output mode ###

current_video_mode=$(cat /conf/config | grep "VIDEO_OUT_RESOLUTION=" | cut -d \' -f 2 | tr '[A-Z]' '[a-z]')

### get current audio output mode ###

current_audio_mode=$(cat /conf/config | grep "AUDIO_OUT=" | cut -d \' -f 2)
if [ "$current_audio_mode" == "1" ]; then
  current_audio_mode="digital"
elif [ "$current_audio_mode" == "0" ]; then
  current_audio_mode="stereo"
else
  echo "ERROR: current audio output mode is invalid, exiting ..."
  _exit 1
fi


############## handle menu output mode ################

if [ "$file" == "video_run.xml" ]; then
  echo "INFO: playback stopped!"
  ### turn on leds ###
  if [ "$turn_on_leds_after_play" == "1" ]; then
    echo "INFO: turning on leds"
    echo "power led on" > /proc/led
    if [ $(df -ah | egrep -ci "/dev/sda") -gt 0 ]; then
      echo "status led on" > /proc/led
    fi
  fi
  ### set menu output mode ###
  if [ ! -f "$tmpfile" ]; then
    echo "ERROR: file "$tmpfile" not found, exiting ..."
    _exit 1
  fi
  saved=$(cat "$tmpfile")
  rm $tmpfile

  ### reset audio mode ###
  menu_audio_mode=$(echo "$saved" | grep "menu_audio_mode=" | cut -d \= -f 2)
  _set_audio_mode "$menu_audio_mode"

  ### reset video mode ###
  if [ "$set_menu_video_mode" == "1" ]; then
    menu_video_mode=$(echo "$saved" | grep "menu_video_mode=" | cut -d \= -f 2)
    additional_menu_video_modes=$(echo "$menu_video_mode|$additional_menu_video_modes" | tr '|' ' ')
    echo "INFO: available menu video output modes -> $additional_menu_video_modes"
    if [ $(echo "$additional_menu_video_modes" | egrep -ci "$current_video_mode") -eq 1 ]; then
      echo "INFO: current video output mode $current_video_mode is valid for menu"
    else
      echo "INFO: current video output mode $current_video_mode is not valid for menu, setting video output mode back to $menu_video_mode"
      _set_video_mode_and_exit "$menu_video_mode"
    fi
  fi
  _exit 1
fi

############## handle screensaver ################

if [ "$file" == "screensaver.xml" ]; then
  echo "INFO: screensaver stopped!"
  if [ ! -f "$tmpfile" ]; then
    echo "INFO: no video playback, exiting ..."
    _exit 1
  fi
  ### turn off leds ####
  if [ "$turn_off_leds_on_play" == "1" ]; then
    echo "INFO: turning off leds"
    echo "power led off" > /proc/led
    echo "status led off" > /proc/led
  fi
  _exit 1
fi

############### handle video playback #################

#if [ $(echo "$1" | egrep -ci "^file:///tmp/.*/.+\.($valid_video_extensions)$") -eq 0 ]; then
if [ `echo "$1" | egrep -ci "^file:///tmp/.*/.+\.($valid_video_extensions)$"` -eq 0 ]; then
  echo "ERROR: $1 is not an accepted video file, exiting ..."
  exit 1
fi
file=${file:7}      # strip "file://"
echo "INFO: selected file -> $file"

### turn off leds ####

if [ "$turn_off_leds_on_play" == "1" ]; then
  echo "INFO: turning off leds"
  echo "power led off" > /proc/led
  echo "status led off" > /proc/led
fi

### get audio output mode based on pathfilter ###

set_audio_mode=$current_audio_mode
for audio_mode in $audio_modes; do
  path=$(echo "$audio_mode" | cut -d \: -f 1)
  if [ $(echo "$file" | egrep -ci ".*$path.*") -eq 1 ]; then
    set_audio_mode=$(echo "$audio_mode" | cut -d \: -f 2 | tr '|' ' ' | tr '[A-Z]' '[a-z]')
    echo "INFO: file matches filter '$path' -> setting audio output mode to: $set_audio_mode"
    break
  fi
done

### get available video output modes based on pathfilter ###

for video_mode in $video_modes; do
  path=$(echo "$video_mode" | cut -d \: -f 1)
  if [ $(echo "$file" | egrep -ci ".*$path.*") -eq 1 ]; then
    video_modes=$(echo "$video_mode" | cut -d \: -f 2 | tr '|' ' ')
    echo "INFO: file matches filter '$path' -> setting available video output modes to: $video_modes"
    break
  fi
done

### determine video/audio output mode, call mediainfo/ffmpeg if necessary ###

if [ $(echo "$video_modes" | wc -w) -eq 1 ]; then
  echo "INFO: one video output mode available only, skipping video detection with $selected_media_tool ..."
  if [ $(echo "$video_modes" | egrep -ci ".*p.*") -eq 1 ]; then
    target_scantype="p"
  else
    target_scantype="i"
  fi
  target_resolution=$(echo "$video_modes" | cut -d $target_scantype -f 1)
  target_fps=$(echo "$video_modes" | cut -d $target_scantype -f 2)
else
  echo "INFO: multiple video output modes available, launching $selected_media_tool for video detection ..."
  time_start=`date +%s`
  if [ "$selected_media_tool" == "mediainfo" ]; then
    _launch_mediainfo
  elif [ "$selected_media_tool" == "ffmpeg" ]; then
    _launch_ffmpeg
  else
    echo "ERROR: selected_media_tool must be set to either 'mediainfo' or 'ffmpeg'"
    _exit 1
  fi
  time_end=`date +%s`
  time_elapsed=$((time_end - time_start))
  echo "INFO: $selected_media_tool returned in $time_elapsed seconds -> format=$video_format, width=$video_width, height=$video_height, fps=$video_fps"
  ### fps -> Hz ###
  if [ "$video_fps" == "23.976" ]; then
    target_fps=23
  elif [ "$video_fps" == "24.000" ]; then
    target_fps=24
  elif [ "$video_fps" == "25.000" ]; then
    target_fps=50
  else
    target_fps=60
  fi
  ### video width -> resolution ###
  if [ $video_width -eq 1920 ]; then
    target_resolution=1080
  elif [ $video_width -eq 1280 ]; then
    target_resolution=720
  elif [[ $video_width -eq 720 && $target_fps -eq 50 ]]; then
    target_resolution=576
  elif [[ $video_width -eq 720 && $target_fps -eq 60 ]]; then
    target_resolution=480
  else
    echo "INFO: video width $video_width does not match any available resolution, scaling up to maximum possible resolution"
    target_resolution=1080
  fi
  ### scantype conversion ###
  if [[ $video_width -gt 1280 && $target_fps -gt 24 ]]; then
    target_scantype="i"
  else
    target_scantype="p"
  fi
  ### advanced audio output mode configuration ###
  if [ "$selected_media_tool" == "ffmpeg" ]; then
    for audio_mode in $audio_modes_filters; do
      pattern=$(echo "$audio_mode" | cut -d \: -f 1)
      if [ $(echo "$mediaresults_all" | egrep -ci ".*$pattern.*") -gt 0 ]; then
        set_audio_mode=$(echo "$audio_mode" | cut -d \: -f 2 | tr '|' ' ' | tr '[A-Z]' '[a-z]')
        echo "INFO: ffmpeg output matches pattern '$pattern' -> setting audio output mode to: $set_audio_mode"
        break
      fi
    done
  fi
fi

echo "INFO: suggested video output mode set to $target_resolution$target_scantype$target_fps, matching against available ones ..."

########## match suggested output mode against available modes ###########

### match fps ###

new_modes=""

if [[ $target_fps -eq 23  || $target_fps -eq 24 ]]; then
  new_modes=$(echo "$video_modes" | tr ' ' '\012' | egrep -i "(i|p)$target_fps")
  if [ "$new_modes" == "" ]; then
    tmp_fps=60
    echo "INFO: frame rate selection -> ${target_fps}Hz not available, switching to ${tmp_fps}Hz"
    target_fps=$tmp_fps
  fi
fi

if [ "$new_modes" == "" ]; then
  new_modes=$(echo "$video_modes" | tr ' ' '\012' | egrep -i "(i|p)$target_fps")
  if [ "$new_modes" == "" ]; then
    if [ $target_fps -eq 60 ]; then
      tmp_fps=50
    else
      tmp_fps=60
    fi
    echo "INFO: frame rate selection -> ${target_fps}Hz not available, switching to ${tmp_fps}Hz"
    target_fps=$tmp_fps
  fi
fi

if [ "$new_modes" == "" ]; then
  new_modes=$(echo "$video_modes" | tr ' ' '\012' | egrep -i "(i|p)$target_fps")
fi

if [ "$new_modes" == "" ]; then
  echo "ERROR: frame rate selection -> NO match for ${target_fps}Hz, exiting ..."
  _exit 1
fi

echo "INFO: frame rate selection -> matches: $(echo "$new_modes" | tr "\n" " ")"

video_modes="$new_modes"

### match resolution ###

resolutions="$target_resolution 1080 720 576 480"

for target_resolution in $resolutions; do
  new_modes=$(echo "$video_modes" | tr ' ' '\012' | egrep -i "$target_resolution(i|p)")
  if [ "$new_modes" != "" ]; then
    break
  fi
done

if [ "$new_modes" == "" ]; then
  echo "ERROR: resolution selection -> NO match for ${target_resolution}, exiting ..."
  _exit 1
fi

echo "INFO: resolution selection -> matches: $(echo "$new_modes" | tr "\n" " ")"

video_modes="$new_modes"

### match scan type ###

new_modes=$(echo "$video_modes" | tr ' ' '\012' | egrep -i "$target_scantype")
if [ "$new_modes" == "" ]; then
  if [ "$target_scantype" == "p" ]; then
    echo "INFO: scan type selection  -> progressive mode not available, switching to interlaced"
    target_scantype="i"
  else
    echo "INFO: scan type selection  -> interlaced mode not available, switching to progressive"
    target_scantype="p"
  fi
fi

new_modes=$(echo "$video_modes" | tr ' ' '\012' | egrep -i "$target_scantype")

if [ "$video_modes" == "" ]; then
  echo "ERROR: scan type selection -> NO match for requested scan type '$target_scantype', exiting ..."
  _exit 1
fi

echo "INFO: scan type selection  -> matches: $(echo "$new_modes" | tr "\n" " ")"

### only one mode should be leftover, but to be sure catch first one

video_modes=$(echo "$new_modes" | tr "\n" " " | cut -d ' ' -f 1)

### save video parameters and menu output modes to temp file ###

if [ -f "$tmpfile" ]; then
  menu_video_mode=$(cat "$tmpfile" | grep "menu_video_mode=" | cut -d \= -f 2)
  menu_audio_mode=$(cat "$tmpfile" | grep "menu_audio_mode=" | cut -d \= -f 2)
else
  menu_video_mode=$current_video_mode
  menu_audio_mode=$current_audio_mode
fi
echo "video_file=$file" > $tmpfile
echo "video_format=$video_format" >> $tmpfile
echo "video_width=$video_width" >> $tmpfile
echo "video_height=$video_height" >> $tmpfile
echo "video_fps=$video_fps" >> $tmpfile
echo "video_mode_suggested=$video_modes" >> $tmpfile
echo "video_mode_choosen=$target_resolution$target_scantype$target_fps" >> $tmpfile
echo "audio_mode_choosen=$set_audio_mode" >> $tmpfile
echo "menu_video_mode=$menu_video_mode" >> $tmpfile
echo "menu_audio_mode=$menu_audio_mode" >> $tmpfile

### set new output mode ###

_set_audio_mode "$set_audio_mode"
_set_video_mode_and_exit "$video_modes"
#
inspectah_deck
WDTVer
 
Posts: 22
Joined: Wed Jun 16, 2010 4:49 pm

Next

Return to WDLXTV-G2 & WDLXTV-Live/Plus app.bins

Who is online

Users browsing this forum: No registered users and 1 guest