I own a Sony DV camcorder (NTSC interlaced, bottom field first), and I want to store all recordings on DVD media (keeping tapes seems more expensive and less convenient). I want to preserve the original dv as best as I can within the hardware DVD spec, even if that means storing some noise.
The mjpeg tools appear to be very powerful but I have discovered it isn't clear what encoding options I should use. Although my application is very basic, I understand that there is no objectively optimal way to preserve quality in video encoding. I do know that there are many ways to significantly degrade video quality, however, so I have tried to figure out what to do via googling and trial-and-error. I have some questions, but first here are some of my results. (My questions are clearly marked at the end.) I recorded a 114-second sequence (input.dv) while walking through my house, using a reasonably-steady panning movement most of the time (lots of side-to-side action). For clarity, I have removed the sound file from commands where applicable. Versions: Mjpegtools 1.6.2 Kino 0.73 Transcode 0.6.12 After downloading the file via dvgrab, I tried encoding to DVD with Kino - it issues the following commands: mpeg2enc -v 0 -f 8 -I 1 -n n -a 2 -o kinofile.mpv mplex -v 0 -f 8 -o kinofile.mpeg kinofile.mpv Someone at http://www.linuxquestions.org/questions/showthread.php?s=&forumid=57&threadid=242686 pointed out that Kino issuing -f 8 to mpeg2enc results in DVD's that aren't hardware playable - he said -f 3 should be used in mpeg2enc and -f 8 in mplex. This individual gave his usage with transcode, so I tried that. However, by default transcode passed a de-interlace command (-I 0) to mpeg2enc, which is not a good idea as my source is as interlaced as you can get (each field sampled at a different time instant). I then used --encode_fields b to correct this. transcode -i inputfile.dv --encode_fields b -y mpeg2enc -w 7500 -b 224 -s 2 -F 3,"-G 18 -c" -V -o tcfile.mpeg Resulting mpeg2enc command: mpeg2enc -v 0 -I 1 -q 3 -f 3 -4 2 -2 3 -b 7500 -s -F 4 -n n -a 2 -o tcfile.mpeg.m2v -G 18 -c I've read that a hardware DVD player supports average total bitrates up to 8000 kb/s with a peak of somewhere around 9800 kb/s, so I passed a bitrate of 7500 kb/s to transcode (although I've read that DVDR media may cause that bitrate to be limited to something like 6800 kb/s in some players). To my surprise the bitrate wasn't constant - transcode passed -q 3 with a max bitrate of 7500 to mpeg2enc. To control the process more carefully, I grabbed most of the options transcode set and used smil2yuv as the input to mpeg2enc. Next I encoded my "default" file - this file, on a DVD+RW, does play on my Sony DVP-NS300 (online forums and personal experience indicate this is a problematic player) with only one decoding glitch - I'm not sure yet if it's the player or the media (maybe the instantaneous bitrate is too high for the media/player combo). Default clip, Average bitrate: 7195 kb/s smil2yuv inputfile.dv | mpeg2enc -v 0 -I 1 -q 3 -f 3 -4 2 -2 3 -b 7500 -s -F 4 -n n -a 2 -G 18 -c -o mpdefault.m2v Next I tried filtering with yuvdenoise, yuvmedianfilter and throwing away high-frequency blocks (-N). Radii of 2 and 1 were tried with the median filter and -N 1 and -N 2 were tried in removing high-frequency blocks. Let ... = -v 0 -I 1 -q 3 -f 3 -4 2 -2 3 -b 7500 -s -F 4 -n n -a 2 -G 18 -c Average bitrate: 7057 kb/s smil2yuv inputfile.dv | yuvdenoise | mpeg2enc ... -o mpdn.m2v Average bitrate: 4965 kb/s smil2yuv inputfile.dv | yuvmedianfilter | mpeg2enc ... -o mpmfdef.m2v Average bitrate: 7184 kb/s smil2yuv inputfile.dv | yuvmedianfilter -r 1 -R 1 | mpeg2enc ... -o mpmfr1.m2v Average bitrate: 7135 kb/s smil2yuv inputfile.dv | mpeg2enc ... -N 1 -o mpmfr1.m2v Average bitrate: 6716 kb/s smil2yuv inputfile.dv | mpeg2enc ... -N 2 -o mpmfr1.m2v VISUAL RESULTS: I used snapshots to evaluate the results - I had almost the same frame from each clip (see question at end). Lots of detail is present in the moment I chose. I couldn't really tell a difference between the default clip, the "-r 1 -R 1" median filter clip, and the "-N 1" clip - maybe there is a difference in peak-bitrate portions but I did not attempt to discover that in this test. The "-N 2" clip was little too blocky and given that the bitrate didn't drop much, I didn't investigate any other -N values and dropped this from consideration. Yuvdenoise clip Yuvdenoise does not seem to be a good filter for clips with lots of motion (panning in this case). The temporal lowpass filtering washed out some textures much more than the other methods; the motion-blur compensation added a slight spatial "ringing" (i.e. white-biased pixels next to dark edges) and it passed noise around objects in motion. I dropped this filter from consideration as the bitrate reduction vs. perceived quality was insignificant. Median-filtered clip The median filter at the default settings seems more satisfying as a) it appears to work in space and not time and b) it is nonlinear so edges should be preserved well. Results were reasonable - noise was reduced somewhat but textures weren't washed out. The only drawback I noticed is that the color space seems compressed slightly - whites in the picture seem to be greyed slightly - nothing major but noticable if you are looking for it. The major advantage of this filter appears to be that it gives a good result while lowering the bitrate by 30%. The picture is degraded somewhat but no "blocky" artifacts appear to be introduced - the picture is noise-reduced with no noticable blur and a slight compression of the color space of detailed areas (I assume this is the "softening" mentioned in the man page). Current conclusions and questions >From a bitrate perspective it seems I should just keep the "default" settings of mpeg2enc with no filter - although I haven't explored how high-motion/high-detail frames might suffer when noise isn't reduced (does anyone have any advice here?). If I am concerned about reducing the bitrate due to media/hardware limitations I should use the median filter - apparently I can get a 30% reduction in average bitrate without changing the quality or max bitrate settings. This savings is bought with a slight softening of the image but no "blocky" artifacts appear to be introduced. Question: The man page I have for yuvmedianfilter says: "This filter looks around the current point for a radius and averages the values that fall inside a threshold." If this is correct, shouldn't it be called yuvmeanfilter? Calculating the median makes more sense in preserving detail, but at small thresholds and search radii there probably isn't much difference between the median and the mean. Question: What does looking "around the current point" mean when median filtering an interlaced signal? Does the filter look solely in the "left and right" direction of the current point, does it look "up and down" into the adjacent lines of the same field, or does it look up and down into the adjacent lines of the same frame (nearest lines in the other field)? Also, can anyone point me to an explanation of how frame-by-frame-based encoding is adapted to interlaced signals? (Field-by-field encoding is similar to progressive frame-by-frame encoding, right?) Question: Should I use -I 2 instead of -I 1? What are the trade-offs? Is -I 2 no longer being maintained? (My Debian binary segfaults with this option, and I thought I read somewhere that it isn't being maintained.) Is this field-by-field encoding supported in hardware DVD players? Question: I wanted to provide links to bitmaps of the frames I used, but they were grabbed with a snapshot program and I wasn't entirely convinced I was comparing "apples to apples". How can I grab exactly the same frame from each clip for comparison? I am using Debian so I am unable to locate packages for an mpeg2 nle like LVE, and Mplayer and Xine don't seem to support stepping through a clip in a frame-by-frame manner. Kino supports frame-by-frame stepping but can't read mpeg files. Lav2yuv won't read the m2v files. Is there a command-line tool (or pipe-connected tools) that grabs a specified frame from an mpeg file and outputs it in a bitmap file format? Question: Since I am interested in primarily "preserving the original", should I even be considering variable bitrates? Should I just max out the bitrate? What are the disadvantages of doing this (besides reducing playing time of a disc). At constant, high bitrates will I notice a difference between high and low-detail frames? Question: If variable bitrates are the way to go, would I get better results using an encoder that supports two-pass encoding? My understanding is that mpeg2enc is single-pass. The only free-software competitor I am aware of that does two-pass encoding is ffmpeg. What is the opinion of mjpeg-users of high-vbr, two-pass encoding quality of ffmpeg compared to high-vbr mpeg2enc? Given the above commands, can anyone suggest a two-pass set of commands that I should try with ffmpeg? Question: Does mjpeg2enc do any [16...235] to [0...255] conversion? Should I be interested in keeping the range as it is? Question: Are there any errors in my assumptions, understanding, or reasoning? Any other advice is appreciated. Again, my primary goal is to use DVD media as my primary video storage medium, and I want to preserve the original dv as best as I can within the hardware DVD spec. Thanks in advance for any help, and thanks to the mjpeg developers for such a great set of tools! - Matt ------------------------------------------------------- This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8 _______________________________________________ Mjpeg-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/mjpeg-users