Interesting work in DTV reception

Gerard gerard.teichman at verizon.net
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
so
the -ss option does not work right away.  (The mpg file reports
incorrect
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
the
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)
one.
Even though I  do not have a surround system at the moment I am getting
ready
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
in
stereo mode.  In order to find the right audio id and other info about
the
video I use the mplayer options: -identify -frames 0.

Next I determine the cut points.  (I encode shows without commercials
aired
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
-o
MONKEYS.cut.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
bars
are not completely black or some parts of the movie has embedded parts
with
extra  black bars (typical for documentaries) or there is a logo on the
bars.

3. I run a 2 pass mencoder encode.  This takes a long time.  I copy the
audio
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
sourceforge.

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

The script below does steps 3-6:

#!/bin/sh

#SRC=/scratch/mythtv/1181_20081109190000.mpg
# 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
-o
MONKEYS.cut.avi
SRC=MONKEYS.cut.avi
WORK=/scratch/encode/MONKEYS
NAME=MONKEYS
# You can encode a sample:
#SAMPLE="-endpos 30"
FILTER=crop=1920:1072:0:0,yadif,softskip,scale=960:536:0:0:7,harddup
CHANNELS=6
# Use -af pan=2:1:.2:.2:1:.4:-.4:-.4:.4:1:1:1:1 to play back in stereo.
BITS=3000
# For different runs you may set TAG to mark them:
TAG=
FILE=$NAME$TAG
MSG=$WORK/encode$TAG.log
NICE=10

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

COMMON_OPTS=bitrate=
$BITS:nr=250:subq=6:8x8dct:frameref=6:bframes=14:b_adapt=1:weight_b:b_pyramid:nointerlaced:nofast_pskip:trellis=1:mixed_refs:weight_b:me=umh:me_range=24:nodct_decimate:partitions=all:psy-rd=0.5,0.3:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto:psnr:ssim:log=2
X264OPTS_PASS1=pass=1:$COMMON_OPTS:turbo=2
X264OPTS_PASS2=pass=2:$COMMON_OPTS

echo "First pass started on $(date)." >> $MSG
TIC=$SECONDS
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
TOC=$SECONDS
let ET=$TOC-$TIC
echo "First pass done in $ET seconds." >> $MSG

echo "Second pass started on $(date)." >> $MSG
TIC=$SECONDS
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
TOC=$SECONDS
let ET=$TOC-$TIC
echo "Second pass done in $ET seconds." >> $MSG

TIC=$SECONDS
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
$CHANNELS -ao pcm:fast:file=audio.wav >/dev/null 2>&1
TOC=$SECONDS
let ET=$TOC-$TIC
echo "Extracted $CHANNELS audio channels in $ET seconds." >> $MSG

TIC=$SECONDS
~/src/ccextractor.0.52/linux/ccextractor $SRC -o subtitles.srt
TOC=$SECONDS
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 subtitles.srt
--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
files!

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
above)
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...
URL: https://lists.ubuntu.com/archives/ubuntu-us-ma/attachments/20090122/58c748cb/attachment-0001.htm 


More information about the Ubuntu-us-ma mailing list