[mythtv-users] A few comments / ideas on editing MPEG2 material, asynch AV streams and mastering to DVD

Darksoul darksoul71 at gmx.de
Wed Nov 2 12:16:38 EST 2005


 Hi list,

I hope that ideas and comments from a Windoze user are accepted here in the
list. <ggg>

I´ve been following the discussions within the user list for a long time.
Unfortunately my PVR USB2.0 is not very well supported under linux (in other
words: It doesn´t run under MythTV). So I´m stuck to WinXP with my PVR :-|

There have been a lot of e-mails exchanged on this list in regard to post
processing MPEG2 captures and getting async audio under certain
circumstances. Esp. unstable analogue signals (bad receiption of analogue TV
or captures from old VHS tapes) often cause dropped frames / corrupted
frames within the MPEG2 streams captured using the PVR type of cards. The
same seems to be true for some DVB-X recordings.

To me it seems that the problems begin once you start using AVIDemux for
editing your MPEG2 captures. Sometimes peoples are getting async audio with
their final MPEGs.

I´ve seen comments that demuxing your MPEG2 stream breaks the sync. From my
experiences this is only partially true. At least under Windows there is a
tool called Cuttermaran which is able to handle dropped frames / corupted
MPEG captures even if the MPEG stream is demuxed.

See: http://www.cuttermaran.de/

Cuttermaran somehow is able to calculate the individual offset required for
separate segmets, e.g. the first segment you have cut might have an audio
offset of -80 ms. The second one might have 0 ms offset. The third one might
have +40 ms offset.

For me Cuttermaran has proven to work as I have captured and edited somewhat
like 50 VHS tapes (a lot of them were third generation copies and had
extremely low qualitiy). All resulting DVDs were perfect in terms of AV
sync.

The author of Cuttermaran offers the source code under GPL if you contact
him via e-mail.

For details see: http://www.cuttermaran.de/site/293/default.aspx

I shurely understand that suggesting a .NET application something like 1 MB
big seems to be overkill for "just cutting MPEG2 streams" but:

a) someone could use Mono (http://www.mono-project.com/Main_Page) instead of
.NET and port Cuttermaran over to Linux

or

b) someone could extract the relevant code segments (if they are not
depending to a specific lib of .NET) and port it over to standard C. From my
amateurish understanding C# is just another dialect of C. Similar to Java.

Worst case: you/me would have to understand the way the code works and
"rebuilt" it in Linux compatible code.

BTW: Cuttermaran provides a pretty unique functionality: Frame-based
cutting. Any resulting group with missing I-,  B- and P-frame gets
reencoded. This this is limited to a single GOP, thus cutting is very fast.



Speaking from a Windows user perspective and being developer of several
audio/video related tools based on AVISynth, BeSweet, etc. another approach
comes to my mind. I´ve written a small application in AutoIt (which is a
simple scripting language using a Basic like syntax) called Komprezz2MPEG
which automatizes the whole process of "editing" a MPEG2 capture, mastering
a DVD with defined chapters and generating a burnable ISO afterwards. This
tool uses a diversity of freeware tools and many of them were ported over
from linux (mplex, dvdauthor, mkisofs).

I´m trying to give you a rough description how my tool works (Warning: The
following description includes a lot of windoze specific tools :)

* A fake AVI is generated using DGIndex and AVISynth. DGIndex does demuxing
of the audio track as well as generating a DVD2AVI project file (D2V). My
tool adresses any existing offset for audio using AVISynth.

* Do automatic crop, resize and denoise using AVISynth.

* Remove any commercials based on a VirtualDub cutlist which also includes
fade in / fade out and cross fades.

* Generate a normalized MP2 audio stream using AVS2WAV and BeSweet.

* Encode video using the Cinema Craft Encoder. This includes OPV encoding
based on the DSRoBa approach (= finding the constant quality value for your
encoder which matches your target size) as well as quality-based resize,
e.g. automatically resize from Full D1 (720x576 PAL) to Half D1 (352x576
PAL) if the first CQ encoding revealed a too bad quality value (e.g. below
70% quality).

* Finally do all the dvd mastering stuff similar to the approach described
within the MythTV manual (mplex, dvdauthor, mkisofs).

This encoding / mastering script is called multiple times by another
frontend script which automates fast generation of cutlists. Using AVISynth
and D2V-files for editing is much faster than any MPEG2 editor I´ve seen.

The approach is pretty simple and my guess is that I would have had to spent
a lot less time automating GUI tools if Windows would have the same variety
of CLI tools that Linux has <ggg>

One other possible solution (beside Cuttermaran) would be either modifying
Komprezz2MPEG to run under Wine, generating an AVISynth script, using
AVS2YUV as interface from AVISynth to any Linux based encoder
(http://students.washington.edu/lorenm/src/avisynth/avs2yuv/) and do the
rest (DVD mastering) under linux. Of course any skilled developer could
rebuild the same functionality that Komprezz2MPEG provides, using a shell
script. My AVISynth interface is only a text file into which AVISynth dumps
the video infos such as width, height, length.

All in all it might look strange to use a combination of a Windoze tool(s)
under wine with a linux encoder but speaking from a user perspective: I
wouldn´t care how something is implemented if it works fine :^)

I know that my approach is quite different to others since I encode every of
my encodings. Keeping this in mind I record using pretty high bitrates (12
MBit V/ 384 kBit A).

Komprezz2MPEG also supports AVISynth and any AVI as input. So you can even
use a non-hardware encoder card to capture lossless in Huffyuv and transcode
to MPEG2 afterwards.

Those of you who simply want to cut prior mastering are not able to use this
approach.

My experiments with CLI cutting tools such as MPGTX were never successful (=
async audio, freezing video). Cuttermaran provides a XML interface to do CLI
cutting but I could never get a hang on this, although using this CLI in
combination with wine and a cutlist extracted from the MythTV database could
be the fasted approach to have cutted MPEG2 file in perfect sync for
mastering.

Not shure but may be the MythBurn scripts would be the best place where to
integrate this ?

Sorry for my lengthy posting. I just wanted to share my ideas.

Hopefully my ideas, thoughts and explanations were not too confusing.

Any feedback is apreciated unless you answer the standard "Windows sucks !
Linux rulez !" kind of stuff ;)

Best regards,
D$

P.S.: I´ve set up my PIII box with FC4 and the latest RPM version of Wine
but currently I´m out of time to try things out. When I have some spare time
I will experiment with AVISynth, Wine and AVS2YUV.



More information about the mythtv-users mailing list