Audio file encode to a video file

I wanted to convert an MP3 file to a video file to be able to use it on my PS3. The PS3 has an audio player but it doesn’t remember the position. It was an audiobook so it was best for me to convert it to a video file.

#!/usr/bin/bash
# Create video file from audio file.

# Required programs.
if ! hash ffmpeg 2>&- ; then
  echo "Requires program: ffmpeg"; exit 1; fi

# Usage.
if [ $# != 2 ] ; then
    echo "${0##*/} <image> <audio> - create video file from an audio file."
    exit 1; fi

# Files existent test.
if [ ! -f "$1" ] ; then
    echo "non-existent image: "$1""
    exit 1; fi
if [ ! -f "$2" ] ; then
    echo "non-existant audio: "$2""
    exit 1; fi

vid_nme="${2%.*}".mp4
ffmpeg -f image2 -loop 1 -i "$1" -i "$2" -c:v libx264 -tune stillimage 
  -c:a copy -strict experimental -shortest "$vid_nme"

#ffmpeg -f image2 -loop 1 -i "$1" -i "$2" -c:v libx264 -tune stillimage 
#  -c:a aac -strict experimental -b:a 192k -shortest "$3".mp4

Monitor Hardware Calibration

00-post1

A calibrated monitor will help images feel more natural and will help ease eye strain with tasks like reading. It may be preferable to some that when a new monitor is acquired to have it calibrated. This is a guide to show how to do such.

My Experience

I read documents on my computer all the time and occasionally do graphic design work. I appreciate having a calibrated monitor. I have a background in developing color photography which has helped my eye to recognize correct image reproduction. I have also worked for computer laboratories that has allowed me to calibrate a good number of varying monitors. Others will know more than me, however, this should be a good layman’s approach.

Monitor Setup Knowledge

  • the monitor should be left on ten+ minutes to let the bulb warm up to its standard operating color
  • the monitor’s angle at which it is viewed is important, for older or less expensive monitors a non-direct view of a few degrees can effect the display image… angle the monitor so that it is perpendicular to the eyes
  • hardware calibration should come before any software calibration, and software calibration only when necessary… hardware calibration would be helped if software calibration were disable beforehand
  • some monitor controls are extracurricular, eg better flesh tone or crushing black levels… for initial setup these controls should be turned off
  • some images are scalable so they can be view accurately at full screen, I would recommend doing so to help with one’s attention

Gamma Correction

Gamma Correction is an adjustment of the mid-luminosity level of the bulb to correct for a light source that is unique (ie not the sun) that the natural eye adjusts to non-linearly. A monitor that needs Gamma Correction the display will look light and glowy; excessive Gamma Correction will look dark and over-saturated. Most monitors today use the 2.2 sRGB Gamma Correction standard.

The test image displays four channels for setting Gamma Correction: a composite, red, green, and black. This image will need to be viewed in its original size, ie 100%, for it to work correctly.

Some monitors have Gamma Correction controls; for others it may be tied to the RGB controls… and some monitors will require to have it set with a software program. Adjust the controls up and down and match the circle luminosity to the surrounding area.

01-gamma

If changing the RGB controls do not effect gamma, I would recommend a software calibrator; proper gamma correction is essential to proper monitor output. For Linux xgamma can be used, and Windows has its own calibration tool. (As a side note: this test works because the brain averages the black and light lines of the background to an aggregate luminosity; the circle is a 73% luminosity.

Contrast

Contrast, sometimes called Picture or White Level, defines the luminance range of a monitor. A contrast that is high would have lightness-values extended to black or white; a contrast that is low would lightness-values toward middle grays.

The test image displays columns of circles with increasing lightness toward the center of the image. The center circle has a lightness of 254/255; the background is a pure white of 255.

Begin the test by turning down the contrast to zero, then turn it up until circles begin disappearing; turn down the contrast again until the most inner-most circle that is capable of being displayed is displayed. This defines the maximum contrast. The monitor might only be able to display some of these upper contrasts, an acceptable amount I am told is the 245 of 255 range (the third outer-most circle). For certain monitors high contrasts values may alter the temperature of the bulb.

02-white-level

Brightness

Brightness refers to the power level of the bulb, its physical brightness. Black level refers to black reproduction, or more elaborately the accuracy of displaying the lowest shades of black. The brightness setting may have an effect on both.

The test image displays columns of circles with decreasing lightness toward the center of the image. The center circle has a lightness of 1/255; the background lacks lightness of 0/255.

Begin the test by turn up the brightness to 100, then turn it down until circles begin disappearing; turn up the brightness again until the inner-most circle that is capable of being displayed is displayed. This defines the minimum brightness.

For brightness, I like to recommend reading light level. A good light to read a book with is a good light to read from the screen. What feels comfortable to the eye is usually better.

03-black-level

Black should be black and the shades near it are nice if visible too. A lower value acceptable for this is probably 10/255 again. If turning the brightness down has no effect on the black level visibility, leave it at the top or what is comfortable to the eye.

Color Balance

04-color-wheel

Fine tuning color balance can take years of practice to develop a trained eye–reds can look purple, cyan can look green…

The test image displays a variety of grays. If the images lacks the feel of being gray, adjust the RGB controls from 100 down to fix. Play with the controls up and down and get a feel for the color. Our eyes naturally adjust to the conditions they are in so this test can take time to learn how to do well. Periodic breaks can help reset the eyes. To fine tune the color, more can done later with the overall image, also the Gamma Correction test image can be of help adjusting color.

04-color-balance

Fine Tuning

neutral chroma-free gray scale. This is the most critical component of monitoring and is accomplished through a White Balance Adjustment–Bennet Cain

After all the controls have been set I recommend going back and fine tuning them if necessary. I have been told that flat-panel monitors controls function independently. This means that one controls adjustments effect only that control—for CRT monitors control settings were dependent meaning that other controls could be effected by another control. To be sure of one’s settings though it is good to go back and check that all the control settings feel right.

Below is the skin tone test which works well for an additionally test to determine color balance. Skin tone is a good test for image reproduction.

05-test-photo

Software Calibration

Fine-tooth calibration of a monitor through software calibration can help a monitor display more accurately. Otherwise, software calibration should be avoided–it is a second level adjustment and inaccurate at that. Software calibration, for example, can look like it is bringing in those blacks that the monitor originally could not display, but what it is doing making a two black in to a ten black. Software calibration also is a dependent control; for example, adjusting brightness with a software calibrator will effect contrast. The only acceptable software calibration to me is Gamma Correction and EDID.

EDID information is supplied in the monitor’s ROM. It contains information representing how accurately the monitor is able to produce color and lightness. EDID information is meant to be grabbed by the Operating System and used as an ICC profile to better render the display and share color information with other devices.

Software Video Players and the Plunging PLUGE Line

CRT monitors, generally for television, if setup deliberately for video production, used PLUGE controls to “black-crush” the bottom 7.5 IRE (7.5% visible luminance spectrum). This could have been done originally because early CRT monitors had difficulty displaying this value or possibly it was done for dramatic effect; I have yet to learn why. Some DVD players are able to produce an IRE below 7.5. It may be necessary to calibrate a “black-crush” on the software video player to render videos correctly.

To Do

  • Use an ffmpeg Command to Create Video from Images

See Also

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"