Multimedia from the command line.

Various command-line recipes - much quicker than operating through some pointy-clicky interface!

To convert a stack of mp3s to .wav files

  for x in \*.mp3; do lame —decode $x; done

To convert ogg to mp3

for file in \*.ogg;do oggdec -o - "$file"|lame -h -V 4 –-vbr-new - "$(basename "$file" .ogg).mp3";done

BIG WAV FILES

can be chopped up using wavbreaker see - /usr/ports/audio/wavbreaker

How to convert YouTube videos to Avi.

(I found this recipe here.)

Save the following lines as flv2avi.sh. Make the file executable with chmod 755 flv2avi.sh and copy it in a directory in your PATH (/usr/local/bin is a good candidate):

  \#!/bin/sh

if [ -z "$1" ]; then
  echo "Usage: $0 {-divx|-xvid} list_of_flv_files"
  exit 1
fi

# video encoding bit rate
V_BITRATE=1000

while [ "$1" ]; do
  case "$1" in
    -divx)
      MENC_OPTS="-ovc lavc -lavcopts \
        vcodec=mpeg4:vbitrate=$V_BITRATE:mbd=2:v4mv:autoaspect"
      ;;
    -xvid)
      MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
      ;;
    )

> if file "$1" grep -q "Macromedia Flash Video"; then

        mencoder "$1" $MENC_OPTS -vf pp=lb -oac mp3lame \
          -lameopts fast:preset=standard -o \
          "`basename $1 .flv`.avi"
      else
        echo "$1 is not Flash Video. Skipping"
      fi
      ;;
  esac
  shift
done

Usage is simple: flv2avi.sh -divx first_vid.flv second_vid.flv etc.flv

But then we want to be able to burn this onto a dvd and watch it on TV?

* Converting the files to MPEG-2

First, you must convert your file to MPEG-2 for the video and to AC3 for the audio, in order to be compliant with the DVD video specifications. If the audio on your file is already encoded in AC3 format, you can use it as is without re-encoding it. Run this command to check the audio format of the file:

> mplayer -vo dummy -ao dummy -identify your_video.avi 2>&1 grep AUDIO_FORMAT cut -d '=' -f 2

If it returns hwac3, the audio part of your file is encoded in AC3, and you can convert the file to MPEG-2 with the following command:

mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9 \
-ofps 25 -o your_video.mpg your_video.avi

If it isn't encoded in AC3, run this command:

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup \
-srate 48000 -af lavcresample=48000 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9:\
acodec=ac3:abitrate=192 -ofps 25 -o your_video.mpg your_video.avi

The previous commands create an MPEG-2 file in phase-alternating line (PAL) format with an aspect ratio of 16:9. PAL is used in most of Europe (except France). If you don't have a wide-screen TV, you should encode your file with an aspect ratio of 4:3 by replacing aspect=16/9 with aspect=4/3.

MPlayer's man page provides detailed explanations about each option used in these commands.

Creating the DVD structure

Now you can use dvdauthor to create the layout of the DVD from the MPEG-2 file of your video. Although you can pass any options to dvdauthor directly from the command line, it's easier and more flexible to create an XML file with the appropriate options instead. Open your favorite editor and create a file called dvd.xml with the following contents:

<dvdauthor>
  <vmgm />
    <titleset>
      <titles>
        <pgc>
          <vob file="your_video.mpg" chapters="0,0:10,0:20,0:30,0:40,0:50" />
        </pgc>
      </titles>
    </titleset>
</dvdauthor>

I split my hour-long video into six 10-minute chapters. Adjust the chapters= option for your video, or remove the option from your XML file if you don't want chapters.

Type

dvdauthor -o dvd -x dvd.xml

to create the layout of the DVD; the -o switch defines the output directory, and -x is used for the XML file. Once it completes, you'll have a directory named dvd with two subdirectories: AUDIO_TS and VIDEO_TS. Before burning the video to a disc, you can check it by running mplayer dvd:// -dvd-device ./dvd.

If the video plays correctly, you can burn it onto a DVD disc with growisofs by running

growisofs -dvd-compat -Z /dev/dvdrw -dvd-video ./dvd/

Make sure to replace /dev/dvdrw with the device name of your DVD recorder.

Capturing streaming media with mplayer

MPlayer can play files from the network, using the HTTP, FTP, MMS or RTSP/RTP protocol.

Playing works simply by passing the URL on the command line. MPlayer honors the http_proxy environment variable, using a proxy if available. Proxies can also be forced:

mplayer http_proxy://proxy.micorsops.com:3128/http://micorsops.com:80/stream.asf

MPlayer can read from stdin (not named pipes). This can for example be used to play from FTP:

> wget ftp://micorsops.com/something.avi -O - mplayer -

Note

It is also recommended to enable -cache when playing from the network:

> wget ftp://micorsops.com/something.avi -O - mplayer -cache 8192 -

Saving streamed content

Once you succeed in making MPlayer play your favorite internet stream, you can use the option -dumpstream to save the stream into a file. For example:

mplayer http://217.71.208.37:8006 -dumpstream -dumpfile stream.asf

Mplayer will save the content streamed from http://217.71.208.37:8006 into stream.asf. This works with all protocols supported by MPlayer, like MMS, RSTP, and so forth.

Back to FreeBSD page

Last edited: Fri Nov 21 10:45:57 GMT 2008