Regular videos convert for PSP viewing



I like to put videos on my PSP` to watch later. To be able to remember the options I put this in a bash script.

pspvidconv [-d*] <dir.*> <video(s)> — convert videos to PSP

The PSP allows the creation/use of a supplementary single-depth directory. The directory option (-d) will ask if the user wants to create a new directory, if the answer is no, it will present the existing folders.

#!/usr/bin/bash
# Convert videos to PSP

# Settings
vid_dir=/run/media/$USER/PSP/VIDEO  # For Gnome 3, Gnome 2: /media/PSP/VIDEO
vid_vcd="-vcodec mpeg4 -vtag xvid"  # Video codec: xvid
vid_vcd="-vcodec libx264"           # Video codec: x264
vid_vcd="-vcodec h264"
vid_res=320x240                     # 320x240 for PSP 1001, 480x272 for 2001
vid_vbr=768k                        # Video bit rate, was 1024
vid_vfr=29.97                       # Video frame rate
vid_acd=aac                         # Audio codec to use (libfaac for some)
vid_aab=64k                         # Audio bit rate
vid_aar=48000                       # Audio sampling frequency
vid_aac=2                           # Audio number of channels
fns_snd=/usr/share/sounds/alsa/Front_Center.wav

# Usage
if [[ -z "$@" ]]; then
  echo "${0##*/} [-d*] <dir.*> <video(s)> — convert videos to PSP"
  exit
fi

# Check that PSP is plugged in
if [ ! -d $vid_dir ]; then
  echo "It appears that the PSP is not plugged in, no "$vid_dir"."
  exit
fi

# Use sub-directory
if [ "$1" == "-d" ]; then
  while true; do
    read -p " Create a new directory? (y/n): " yn
    case $yn in
      [Yy] )  read -p " Directory name (no spaces): " newdir
              vid_dir="$vid_dir"/"$newdir"
              mkdir "$vid_dir" && break 2;;
      [Nn] )  printf " Select PSP VIDEO sub-directory:n"
              select vid_sub in "$vid_dir"/*/
                do
                  vid_dir="$vid_sub"
                  test -n "$vid_dir" && break 2
                  echo " Select 1, 2, ..."
                done ;;
      * )     echo " Answer (y)es or (n)o."
    esac
  done
  shift
fi

# Check if selection(s) exists
for vid in "$@"; do
  if [ ! -f "$vid" ]; then
    echo " Selection ""$vid"" does not exist."
    exit
  fi
done

# Convert, save to PSP video directory
for vid in "$@"; do
  vid_out="${vid/:/-}"            # ffmpeg not allowing outputs of ':', '?'
  vid_out="${vid_out/?/}"        # http://tinyurl.com/ffmpeg-filename-colon
  #vid_out="${vid_out%.*}"-PSP.mp4 # Append '-PSP' to filename
  thm_out="${vid_out%.*}".thm
  # Encode video
  ffmpeg -i file:"$vid" $(printf '%s' "$vid_vcd") -s "$vid_res" -b:v "$vid_vbr" -r "$vid_vfr" -acodec "$vid_acd" -b:a "$vid_aab" -ar "$vid_aar" -ac "$vid_aac" -f psp -strict -2 -y "$vid_dir"/"$vid_out"
  # Create thumbnail
  ffmpeg -i file:"$vid" -f image2 -ss 50 -vframes 1 -s 160x120 "$vid_dir"/"$thm_out"
done && aplay "$fns_snd"

About Todd Partridge (Gently)

Good times, good people, good fun.

Posted on 2012-07-16, in Command Line, Multimedia, Script. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 58 other followers

%d bloggers like this: