[mythtv-users] Transcoding for best audio

Michael Stucky mike at stucky.us
Mon Jul 15 19:06:59 UTC 2013


On Sun, Jul 7, 2013 at 7:06 PM, Michael Stucky <mike at stucky.us> wrote:

> On Sun, Jul 7, 2013 at 6:00 PM, John Pilkington <J.Pilk at tesco.net> wrote:
>
>> On 07/07/13 21:26, Michael Stucky wrote:
>>
>>> On Sat, Jul 6, 2013 at 2:52 AM, Brenden Conte <brenden at thecontes.info
>>> <mailto:brenden at thecontes.info**>> wrote:
>>>
>>>     Thank you everyone for your feedback; it has been quite useful!
>>>
>>
>> <snip>
>
>> I used to use the mencoder-based script that I posted earlier as a
>> preprocessor to get rid of the problematical extra streams that probably
>> still come and go in DVB-T recordings.  I used mythtranscode --mpeg2
>> --honorcutlist on the output, usually without problems, with MythArchive
>>  with no cutlists and no transcoding then usually able to create a
>> full-sized 4.3 GiB DVD image in less than 30 min.  Each stage of the
>> process could be checked, but inexplicable failures still happened.
>>
>> For several years now I've been using ProjectX within scripts to do the
>> job instead; currently mythDVBcut.  It's a hands-on process, but I can't
>> really see it being anything else. Failures are rare, and rarer than
>> before.  There are still niggly inconveniences, but the biggest worry is
>> that changes introduced into master, or the underlying tools, will bring
>> new problems when a new version of  -fixes makes its appearance. :-)
>>
>> John
>>
>> Thank you John for sharing your work and your advice for us all to
> benefit from!
>
> Mike
>

This weekend I discovered an incredibly simple method for removing unwanted
audio streams from mpeg2 recordings using Mythffmpeg. The result remains in
an mpegts container, which means it is seekable and editable like any other
recording. The surprising thing is that the recording can now be lossless
transcoded by MythTV 0.26!!

I have written a script (OK, full disclosure, this is mostly John's code
tweaked to work as a MythTV USERJOB) that takes the first video stream and
the first audio stream and copies them to a new file that replaces the
original recording. I have this configured to auto-execute for every
scheduled recording (it has been successfully working since Saturday
evening). After this JOB runs I can go in and create my cut-list as I
always have done in the past and schedule the "Transcode" job (this is the
part that has never worked for me in MythTV 0.26). Now I have recording
 (MythTV still see it as a normal recording, i.e. seekable and editable)
with no unwanted content (ads etc.) and only the video and audio streams
that I do want and it plays on all of my media players (Mythfronted, VLC,
SageTV, etc.)!!

Brenden, if you are still following this thread... You can setup this
script (included below) as follows, give it a description like

Remove Extra Audio Streams

 and a command like

/usr/local/bin/rmExtraAudioStream.sh "%FILE%"

where "/usr/local/bin/rmExtraAudioStream.sh" is this script:

#!/bin/bash -e

# Script that works as a MythTV USERJOB to remove unwanted audio tracks from
# recordings. Create a USERJOB of the form:
# /<path to script>/rmExtraAudioStream.sh "%FILE%"
# Where "rmExtraAudioStream.sh" is the name of this script

# Change the following to your MythTV recordings directory
RECDIR=/var/lib/mythtv/recordings

if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "Usage: "$0" <recording>"
echo "<recording> is an mpeg2 file recorded by MythTV with a valid DB
entry."
echo "e.g. 1234_20100405123400.mpg in the defined RECDIR"
echo "The output file replaces the input file which is renamed to
<recording>.old"
exit 0
fi

# exit if .old file exists

if  [ -f ${RECDIR}/"$1".old ] ; then
    echo " ${RECDIR}/"$1".old exists: giving up." ; exit 1
fi

cd $RECDIR
if  [ ! -f "$1" ] ; then
    echo " "$1" not found.  Giving up"
    cd ~
    exit 1
fi

# Is it an mpeg-2 recording?

mythffmpeg -i "$1" 2>&1 | grep -B 2 -A 4 "mpeg2video (Main)" | tee
"temp$$.txt"

mpeg=$(grep -c "mpeg2video (Main)" temp$$.txt)
echo "mpeg2video (Main) stream count:  $mpeg"
if [ $mpeg != 1 ] ; then
  echo "Not mpeg2video (Main), or no or multiple video streams"
  cd ~
  exit 1
fi

#################################
# This code was taken from John Pilkington's mythDVBcut script and
# will need to be edited if you require something other than the first
# video stream and the first audio stream.
#################################
#
##    Examples
##    Stream #0.0[0xe0]: Video: mpeg2video, yuv420p, 720x576 [PAR 64:45 DAR
16:9], 15000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
##    Stream #0.1[0xc0](deu): Audio: mp2, 48000 Hz, 2 channels, s16, 256
kb/s
#
#   # Thanks to Christopher Meredith for the basic parsing magic here.

VSN=`grep "mpeg2video (Main)"  temp$$.txt | head -n1 | cut -f 1,1 -d'[' |
sed 's+.*\#++g'`

# It has to be tweaked for multiple audio streams.  This (with head -n1 )
# selects the first listed by ffmpeg.
# You may alternatively wish to select for language, format, etc.
# May be channel, programme, user dependent.
ASN=`grep Audio  temp$$.txt | head -n1 | cut -f 1,1 -d'[' | sed 's+.*\#++g'`

#####################################

# Now do the actual processing

mv  "$1" "$1".old

# use Mythffmpeg to copy the streams.
ionice -c3 mythffmpeg -i "$1".old -map "$VSN" -map "$ASN" -vcodec copy
-acodec copy -f mpegts "$1"

# rebuild seek table and update filesize
ionice -c3 mythcommflag -q --rebuild --file "$1" --logpath /var/log/mythtv

rm -f temp$$.txt

cd ~

exit 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mythtv.org/pipermail/mythtv-users/attachments/20130715/6aad8a87/attachment.html>


More information about the mythtv-users mailing list