Hi Nicolas

> Here is my workflow :
> - input = PAL DV
> - work, work, work, work on my project
> - render in Quicktime DV to see what the parts look like. The file is
>   perfectly played with mplayer
> - I export = YUV4MPEG
> - I use mpeg2enc to encode to mpeg2 with :
> /usr/local/bin/y4munsharp | /usr/local/bin/yuvmedianfilter -T 3 -t 0 |
> /usr/local/bin/mpeg2enc -v 0 -n p -a 2 -r 32 -4 1 -2 1 -F 3 -B 256 -b
> 7500 -f 9 -o $1
> - I export mp2 audio from cinelerra
> - I mplex everything with -f 8 option
> 
> The video is "bottom field first".

At first glance this actually looks pretty good.  I also have done many DVDs
with Cinelerra and haven't encounted your problem, so it's definitely
fixable.  Admittedly my workflow is somewhat different to the above and
recently changed as detailed below.

The first question I have is what version of mjpegtools are you using?  This
is the package which gives mpeg2enc along with a lot of other useful things.
The latest version is 1.8.0 and if possible that is the version you should
be using.  The previous stable release (1.6.2, released a *long* time ago)
was OK but there were a few bugs which you need to know about regarding DVD
output.  If you are using anything earlier than that then you are going to
run into trouble.

I notice that you specify "-f 9" to mpeg2enc.  While there are references to
"-f 9" being the dvdauthor profile in ancient manpages dating from the early
2000's, it hasn't been correct since at least version 1.6.2 and possibly
earlier (1.6.2 being the earliest version I've had anything to do with). 
Assuming you're running version 1.6.2 or later, the "-f 9" specification
won't work properly when written to a DVD.  DVDs require special additions
called NAV packets to be inserted into the MPEG2 stream, and "-f 9" doesn't
do this.  Without these packets things will go pear-shaped.  Although not
guaranteed to be the source of all your problems I suspect it is
contributing.  The correct specification to use when writing an MPEG2 stream
for DVDs is "-f 8".

Another random thoughts regarding your mpeg2enc usage: you shouldn't have to
specify "-n" (video norm), "-F" (frame rate) or "-a" (aspect ratio).  This
should all be taken care of automatically and correctly by the yuv4mpeg
stream.

So, first up I'd make sure your running mjpegtools 1.6.2 or (preferably)
1.8.0 and then use "-f 8" in your mpeg2enc call.

In cinelerra there are options for the yuv4mpeg output (at least when doing
an MPEG2 export) accessed via the little spanner icon.  I would assume the
yuv4mpeg export has a similar thing.  Make sure that the "bottom field
first" option is selected in here as well.  This option is independent of
the project field order; just because you have a bottom field first project
does not ensure that the yuv4mpeg "bottom field first" option is also
selected.  The default is to have this not selected, so it's possible that
this is also part of the problem you're seeing.

Using mplex with "-f 8" is correct.

A final comment; in versions of mjpegtools prior to 1.8.0 (so 1.6.2 and
earlier), the default behaviour was to implement an encoding method called
dual prime motion estimation (DPME).  This can cause some issues.  Firstly,
under certain circumstances the DPME code could overflow, causing nasty
visual artifacts when playing back.  This was apparently fairly hard to 
trigger though.  Of greater concern is that some hardware players choke
on DPME MPEG2 streams.  Your player might be one of those.  Therefore,
if you're using mjpegtools 1.6.2 you should try using the "--no-dual-prime"
option to mpeg2enc.

Now a word on my workflow which might assist you.  Up until recently I
rendered to a Qt/DV file and then used this as an input to mpeg2enc.  From
here you can encode using mpeg2enc.  Basing things roughly on your command
options given above (but corrected as noted), something like

  lav2yuv filename.mov | /usr/local/bin/y4munsharp
    /usr/local/bin/yuvmedianfilter -T 3 -t 0 |
    /usr/local/bin/mpeg2enc -v 0 -r 32 -4 1 -2 1 -B 256 -b 7500 -f 8 
    -o output.m2v

should do the trick, where "filename.mov" is obviously replaced with the
name of the actual output Qt/DV file you exported from Cinelerra. 
Output.m2v is the name of the file containing your mpeg2 video stream.  Note
also that lav2yuv comes as part of mpjpegtools - the same place you
get mpeg2enc and friends.

This works pretty well, except that I have discovered that there is a bug in
libdv's encoder which causes artifacts to appear during periods of rapid
horizontal movement.  This has since been confirmed on the libdv mailing
list.  The practical upshot is that if you have rapid horizontal movement,
going via a DV intermediate created by libdv will cause flickering artifacts
at those times.  The cause of the bug isn't known yet and unfortunately no
one seems to be doing much libdv development at this time, so the bug is
unlikely to be fixed soon.  There has been some suggestion that libdv really
needs a rewrite, and that this bug could be fixed then.  However, nothing
has been done on this as far as I know and I haven't had time to do anything
either.

Part of the reason I haven't pursued this is that around the time we
discovered this bug cinelerra 2.0 (and CVS quite some time ago) came out
with the direct yuv4mpeg export option.  This gave a stream which could go
straight into mpeg2enc.  As you have noticed however, the options provided
in cinelerra for controlling mpeg2enc are somewhat restrictive.  I got
around this by replacing the mpeg2enc.plugin with a shell script which calls
mpeg2enc with *my* choice of parameters. Note that the mpeg2enc options
presented by cinelerra (as opposed to the stream options like "bottom field
first" in the same dialog) only change command line options passed to
cinelerra's mpeg2enc plugin.  If you replace this with a script which
ignores the options then they won't do anything. In any case, using this
approach gives one full control over mpeg2enc - just what I wanted.

I'm happy to bring this script from home and post it here if you're
interested.  Others might already have done this or have such things
available on the net.

BTW, the reason I do this instead of a yuv4mpeg export is that I don't 
have the disk space to store a 2+ hour yuv4mpeg stream, and cinelerra
blocks if you try to write to a FIFO.

> The video is jerky on my standalone (Philips) DVD player. The "speed" of
> the DVD isn't constant. It doesn't stop either. It just plays slowly for
> a 1/10th of a second, and restart at the good rate for 1 second or so.

Sounds funky, but as described above there are probably good reasons for 
this.

> It plays fine on my computer using mplayer to play it.

mplayer (like most other software players) plays almost any MPEG2 stream
correctly,  Standalone DVD players will only play a very small subset of
MPEG2 streams.  It is incredibly easy to make an MPEG2 stream which plays
fine on a computer but breaks badly when playing on a standalone box.

> I tried to export mpeg2 directly from cinelerra, and it fails:
> FileMPEG::open_file: Running /usr/local/lib/cinelerra/mpeg2enc.plugin -b
> 7500 -q 0 -a 2 -F 4 -I 1 -M 1 -z b -f 9 -g 45 -G 45 -R 0 -o
> '/mnt/Seagate_200Go/video/chevreuse/dv_output/export_direct_mpeg2_depuis_=
> cinelerra.mpeg'
> **ERROR: [mpeg2enc.plugin] -q option requires arg 1 .. 32

This would tend to indicate that cinelerra is passing "0" as the
quality level; check what quality factor is specified in the dialog box
since it seems the default isn't appropriate.

> I try to export using fixed bitrate. The command line shouldn't include
> -q by the way...
> It also fails if I export using quantization :
> Running /usr/local/lib/cinelerra/mpeg2enc.plugin -b 0 -q 10 -a 2 -F 4 -I
> 1 -M 1 -z b -f 9 -g 45 -G 45 -R 0 -o
> '/mnt/Seagate_200Go/video/chevreuse/dv_output/export_direct_mpeg2_depuis_=
> cinelerra.mpeg'
> **ERROR: [mpeg2enc.plugin] Sample rate is greater than permitted in
> specified Level

Can't comment on this - I don't do CBR encoding since it's not really
appropriate for DVD usage.  In this case it looks like cinelerra is
passing a bitrate of 0 to mpeg2enc which doesn't seem appropriate.

In both cases the mpeg2 profile being selected by cinelerra is "-f 9".  
I'm pretty sure that the mpeg2enc used by cinelerra is later than 1.6.2,
in which case this stream won't work for DVDs.  The fact that cinelerra did
this was one reason I moved to using my own wrapper script.

Another thing to note: "-F 4" is selecting NTSC output but your project is
PAL.

I don't think this method is easy to get working because of the limited
access you get to mpeg2enc's encoding options.  IMHO your best bet would
be one of the methods I outlined previously:

 * using the MPEG2 export with the wrapper script
 * using a DV intermediate file
 * using a YUV4MPEG intermediate file

> Quicktime DV can't be used to encode. Or at least, I don't know how to
> encode into mpeg2 suitable for DVD.

This is explained above.  lav2yuv will take your Quicktime/DV file and
spit out a yuv4mpeg2 stream which can be piped into the other lavtools 
and mpeg2enc itself.

This has become a lengthy email.  Feel free to follow up privately off-list
to discuss any of this in greater detail; a summary could then be posted to
the list to wrap things up.

Best regards
  jonathan

_______________________________________________
Cinelerra mailing list
[email protected]
https://init.linpro.no/mailman/skolelinux.no/listinfo/cinelerra

Reply via email to