Interesting work in DTV reception

Gerard gerard.teichman at
Thu Jan 22 20:41:43 GMT 2009

I wanted to pass along what appears to be an example of the creative
work going on in small ways in the FOS community.

I thought plugging in my tv tuner and receiving over the air DBV would
be simple. NOT. There are many variables, and most of all it takes
knowledge about the physics of what has to occur to the signal after it
is picked up by the receiver.   The signal has to be changed to a form
that is human readable--in other words there is a second process that
has to take place. Thinking about that helped to lead to a solution to
my task of getting my desk-top to receive DTV.  I asked Matyas for help
with getting ASTC.  Not only did he know how to do this, he could record
the signal, save it, replay it on an ipod with closed captioning! Below
is his solution: 

"So once you get your card capture the video stream it will save it as
an mpg
file.  MythTV does that on my system.  Then I use the following steps to
produce the encoding:

1.  I use mencoder to cut the video.  Actually, I do this in two steps,
because in my experience the OTA broadcasts have messed up time markings
the -ss option does not work right away.  (The mpg file reports
movie length too.)  So first I do:

mencoder /scratch/mythtv/1181_20081109190000.mpg -oac copy -ovc copy
-channels 6 -aid 52 -o MONKEYS.avi

Note that I picked the audio id and used -channels 6, because I wanted
surround sound to be encoded.  Many broadcasts have more than one audio
streams, for example for the above -aid 53 picked a 2 channel (stereo)
Even though I  do not have a surround system at the moment I am getting
for the time when I get one.  You may use -af
pan=2:1:.2:.2:1:.4:-.4:-.4:.4:1:1:1:1 to play back the six channel audio
stereo mode.  In order to find the right audio id and other info about
video I use the mplayer options: -identify -frames 0.

Next I determine the cut points.  (I encode shows without commercials
on the public channel, so I only cut off the beginning and the end.)

mencoder -oac copy -ovc copy -channels 6 -ss 5 -endpos 3200 MONKEYS.avi

(The MONKEYS.avi file was not needed after this and can be removed.)

2. Find the crop values.  I use the mplayer option -vf cropdetect *and*
visual inspection.  The latter is important, because sometimes the black
are not completely black or some parts of the movie has embedded parts
extra  black bars (typical for documentaries) or there is a logo on the

3. I run a 2 pass mencoder encode.  This takes a long time.  I copy the
with -oac pcm, because I want it to recompress with ogg vorbis.  If you
prefer the original AC-3 you will have to use -oac copy.

4. I extract the audio to a wav file and reencode it with oggenc.

5. I extract the closed captions with ccextractor avialable from

6. I mux all the files into a matroska container.  I include a message
documenting the encoding parms, times, psnr, ssim, errors as an
in the mkv file.

The script below does steps 3-6:


# We want to cut the video first.  The time stamps are bogus on the OTA
# recording so we copy it first with mencoder:
# mencoder /scratch/mythtv/1181_20081109190000.mpg -oac copy -ovc copy
-channels 6 -aid 52 -o MONKEYS.avi
# Note that we used an audio id above.  The default -aid 53 also
# included an extra narration.
# We identified the cuts and then:
#mencoder -oac copy -ovc copy -channels 6 -ss 5 -endpos 3200 MONKEYS.avi
# You can encode a sample:
#SAMPLE="-endpos 30"
# Use -af pan=2:1:.2:.2:1:.4:-.4:-.4:.4:1:1:1:1 to play back in stereo.
# For different runs you may set TAG to mark them:

echo "Running $0:" >> $MSG
echo "###########" >> $MSG
cat $0 >> $MSG
echo "###########" >> $MSG
echo $(date) >> $MSG


echo "First pass started on $(date)." >> $MSG
nice -n $NICE \
time mencoder $SRC -cache 8192 $SAMPLE \
-o /dev/null -vf $FILTER -sws 9 -mc 0 \
-ovc x264 -x264encopts $X264OPTS_PASS1 \
-af volnorm=2 -oac pcm -channels $CHANNELS \
-passlogfile $WORK/passlog$TAG \
2>> $MSG
let ET=$TOC-$TIC
echo "First pass done in $ET seconds." >> $MSG

echo "Second pass started on $(date)." >> $MSG
nice -n $NICE \
time mencoder $SRC -cache 8192 $SAMPLE \
-o $WORK/$FILE.avi \
-vf $FILTER -sws 9 -mc 0 \
-ovc x264 -x264encopts $X264OPTS_PASS2 \
-af volnorm=2 -oac pcm -channels $CHANNELS \
-passlogfile $WORK/passlog$TAG \
2>> $MSG
let ET=$TOC-$TIC
echo "Second pass done in $ET seconds." >> $MSG

mkfifo audio.wav
nice -n $NICE oggenc -q 6 audio.wav -o audio.ogg &
nice -n $NICE mplayer $WORK/$FILE.avi -vc null -vo null -nocache
$CHANNELS -ao pcm:fast:file=audio.wav >/dev/null 2>&1
let ET=$TOC-$TIC
echo "Extracted $CHANNELS audio channels in $ET seconds." >> $MSG

~/src/ccextractor.0.52/linux/ccextractor $SRC -o
let ET=$TOC-$TIC
echo "Extracted closed captions in $ET seconds." >> $MSG

echo "Encoding finished on $(date)." >> $MSG

mkvmerge --noaudio $WORK/$FILE.avi audio.ogg
--attachment-description "Message file." --attachment-mime-type plain
--attach-file $MSG -o $WORK/$FILE.mkv

echo "Created $WORK/$FILE.mkv."
# Check the log file and the results before removing any intermediary

I am not an avid or good script programmer.  Feel free to modify the
above to
your needs.  If you want to reference my work (in case you are putting
together a documentation, or writing an enhanced script based on the
use my full name: Matyas A. Sustik."

I'm so impressed! It is way over my head, but I have a better
understanding than I did before trying this. I may eventually just try
to record to disk and watch a digital recording instead of "live" tv. My
problem now is that a weak signal causes the frame rate to be out of
sync with the audio which is not effected. I think I have a fix for
this--or not.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Ubuntu-us-ma mailing list