📄 mjpeg_howto.txt
字号:
2 25 999 This file can be fed into glav or lavplay, or you can pipe it into mpeg2enc with lav2yuv or combine the whole stuff into one single mjpeg file with lavtrans or lav2yuv|yuv2lav. 7. Converting the stream to MPEG or DIVx videos First there is some general description in the encoding process and afterwards there is a detailed description of some commonly used output formats. If you want a one command conversation to mpeg videos try lav2mpeg in the scripts directory The encoding with the lav2mpeg script looks like this for mpeg1 output: >lav2mpeg -a 160 -b 2110 -d 320x240 -m mpeg1 -o output.mpg file.eli o Will create a mpeg1 with videobitrate of 2110kBit/sec and audiobitrate of 160 kBit/sec o at a resolution of 320x240 Or for the generation of mpeg2 output: lav2mpeg -o mpeg2 -O output.mpg file.eli o Will create a mpeg2 with default bitrate in same resolution as the input resolution Better results can be accomplished, however, by trying various options and find out which ones work best for you. These are discussed below. The creation of MPEG1 movies is explained with more examples and in greater detail because most of the things that can be used for MPEG1 also work for the other output formats For the creation of of VCD/SVCD Stills sequences (-f 6, -f 7 in mpeg2enc) you should see: http://www.mir.com/DMG/ Still sequences are needed for the creation of menus in VCD/SVCD. The creation of menus is described in the doku of vcdimager. 7.1. Creating sound MPEG-1 videos need MPEG1-layer2 sound files. For MPEG-2 videos you can use MPEG1-Layer2 and MPEG1-Layer3 (MP3). Layer 3 (MP3) audio is not an offically valid audio format but many VCD players will recognize it. MP3 audio is not valid for DVDs. You should stick to MPEG1-Layer2 because most of the MPEG2 players (DVD Player for example usually the different Winxx Versions have great problems with this too) are not able to play MPEG2-Video and MPEG1-Layer3 sound. mp2enc is a MPEG1-layer 2 Audio encoder. The toolame encoder is also able to produce an layer 2 file. You can use that one as well. Toolame is much faster than mp2enc but toolame does not peform resampling (48000 to 44100 samples/second). Many hardware players will play SVCDs using 48000 rate audio. For mp3 creation I'm be sure you have an encoder. Example: > lav2wav stream.avi | mp2enc -o sound.mp2 This creates a mpeg sound file out of the stream.avi with 224kBit/sec bitrate and a sample rate of 48kHz. If you audio file has 44.1kHz mp2enc resamples the audio to create a 48kHz output. If you want a 44.1kHz output sample rate you have to add -r 44100 to the mp2enc command Example > cat sound.wav | mp2enc -v 2 -V -o sound.mp2 This creates a VCD (-V bitrate=224, stereo, sampling rate:44100) compatible output from the wav file. With -v 2 mp2enc is more verbose, while encoding you see the number of sec of audio already encoded. You can test the output with: > plaympeg sound.mp2 NOTE: plaympeg is a MPEG1 Player for Linux, you can use other players as well, for MPEG audio testing you can also use mpg123. 7.2. Converting video You can create MPEG1 and MPEG2 videos. Normally the first video you create is not the best. For optimal quality/size you need to play with the bitrate, search radius, noise filter .... The options of mpeg2enc are described in the manpage of mpeg2enc. Example: lav2yuv stream.avi stream1.avi | mpeg2enc -o video.m1v This creates an video file with the default constant bitrate of 1152kBit/sec. This is the bitrate you need if you want to create VCDs. You can specify more files and also use the placeholder %nd. Where n describes the number. Example: > lav2yuv streami%02d.avi | mpeg2enc -b 1500 -r 16 -o video.m1v mpeg2enc creates a video with a bitrate of 1500kBit/s uses an search radius of 16. That means when trying to find similar 16*16 macroblocks of pixels between frames the encoder looks up to 16 pixels away from the current position of each block. It looks twice as far when comparing frames 1 frame apart and so on. Reasonable values are 16 or 24. The default is 16 so adding the option here is silly. Lower values (0, 8), improve the encoding speed but you get lower quality (more visible artifacts) while higher values (24, 32) improve the quality at the cost of the speed. With the file description of stream%02d.avi all files are processed that match this pattern with 00, 01.... 7.2.1. Scaling Using yuvscaler one can now also scale the video before encoding it. This can be useful for users with a DC10 or DC10+ cards which captures at -d 1 768x576 or -d 2 384x288 (PAL/SECAM) or -d 1 640x480 (NTSC). You get a full description of all commands by reading the manpage or running: >yuvscaler -h Example: > lav2yuv stream.avi | yuvscaler -O VCD | mpeg2enc -o video.m1v This will scale the stream to VCD size which for PAL/SECAM is 352x288 and for NTSC is 352x240. The scaled yuvstream is encoded to MPEG-1. It can also do SVCD scaling to 480x480 (NTSC) or 480x576 (PAL/SECAM): > lav2yuv stream.avi | yuvscaler -O SVCD -M BICUBIC | mpeg2enc -o video.m1v The mode keyword (-M) forces yuvscaler to use the higher quality bicubic algorithms for downscaling and not the default resample algorithms. Upscaling is always done using the bicubic algorithm. Example > lav2yuv stream.avi | yuvscaler -I USE_450x340+20+30 -O SIZE_320x200 | mpeg2enc -o video.m1v Here we only use a part of the input and specify a nonstandard output resolution. NOTE: yuvscaler can set a active area, and set everything else to black using: -I ACTIVE_WidthxHeight+WidthOffset+HeightOffset Testing is done by: > plaympeg video.m1v NOTE:These are only examples. There are more options you can use. You can use most of them together to create high quality videos with the lowest possible bitrate. NOTE2:The higher you set the search radius the longer the conversion will take. In general the more options used the longer encoding takes. NOTE3:MPEG1 was not designed to be a VBR (variable bitrate stream) !! So if you encode with -q 15 mpeg2enc sets the maximal bitrate -b to 1152. If you want a VBR MPEG1 you have to set -b very high (2500). NOTE4:Maybe you should give better names than video.mpg. A good idea is to use the options as part of the filename (for example: video_b1500_r16_41_21.m1v). Another possibility is to call all the layer 2 files ".mp2" all the MPEG-1 video files ".m1v" and all MPEG-2 video files ".m2v" Easy to see what's happening then. Reserve .mpg for multiplexed MPEG-1/2 streams. 7.3. Putting the streams together Example: > mplex sound.mp2 video.m1v -o my_video.m1v Puts the sound.mp2 and the video.m1v stream together to my_video.mpg Now you can use your preferred MPEG player and watch it. All players (gtv for example) based on the SMPEG library work well for MPEG-1. Other players (which can play MPEG-2 as well as MPEG-1 movies) are: xmovie, xine, and MPlayer. NOTE: If you have specified the -S option for mpeg2enc mplex will automatically split the files if there is in the output filename a %d (looks like: -o test%d.mpg) The files generated this way are separate stand-alone MPEG steams! NOTE2: xine might have a problem with seeking through videos. mplayer has a problem with the "seek backward/forward" with variable bitrate streams because it goes forward in the file the amount of data for a constant bitrate stream. That amount might be significantly more than 10 seconds or one minute (those are the amount mplayer seeks for each press of the arrow keys). So don't wonder if it seeks much more time forward or backward than you expect. Variable bit-rate multiplexing: Remember to tell mplex you're encoding VBR (-V option) as well as mpeg2enc (see the example scripts). It *could* auto-detect but it is not working yet. You should tell mplex a video buffer size at least as large as the one you specified to "mpeg2enc" Sensible numbers for MPEG-1 might be a ceiling bit-rate of 2800Kbps, a quality ceiling (quantization floor) of 6 and a buffer size of 400K. Example: > mplex -V -r 1740 audio.mp2 video_vbr.m1v -o vbr_stream.mpg Here we multiplex a variable bitrate stream. mplex is now a single pass multiplexer so it can't detect the maximal bitrate and we have to specify it. The data rate for the output stream is: audio bitrate + peak videobitrate + 1-2% for mplex information. If audio (-b 224) has 224kBit, video has 1500kBit (was encoded with -b 1500 -q 9) then we have 1724 * 1.01 or about 1740kBit. Example: > plaympeg my_video.mpg oder > gtv my_video.mpg 7.4. Creating MPEG1 Videos For MPEG1 you can use mpeg layer 2 Audio and mpeg1 video. A subset of MPEG1 movies are VCD's. You can use VBR (Variable BitRate) for the Video (although VCDs are almost always use CBR video) but the Audio has to be CBR (Constant BitRate). MPEG1 is recommended for picture sizes up to 352x288 for PAL and 352x240 for NTSC for larger sizes MPEG2 is the better choice. There is no exact resolution where MPEG1 is better than MPEG2. Just to make soure, MPEG1 can't handle interlaced sources. If you video is interlaced you need MPEG2 to get it proper encoded. . 7.4.1. MPEG1 Audio creation Example > lav2wav editlist.eli | mp2enc -r 44100 -o sound.mp2 You can save some bits by telling mp2enc to use a lower bitrate (-b option) like 160 or 192 kBit/s. The -r 44100 option forces mp2enc to generate a 44.1kHz audio file. > lav2wav editlist.eli | mp2enc -b 128 -m -o sound.mp2 This creates a mono output with an bitrate of 128kBit/sec bitrate. The input this time is the editlistfile (can have any name) created with glav so all changes you made in glav are direct processed and handed over to mp2enc. You do NOT have to create an edited stream with lavtrans to get it converted properly. 7.4.2. MPEG1 Video creation Example > lav2yuv editlist.eli | mpeg2enc -b 2000 -r 24 -q 6 -o video.m1v mpeg2enc creates an video with an bitrate of 2000kBit/s (or 2048000Bit/s) but the -q flag activates the variable bitrate and a quality factor of 6. It uses a search radius of 24. Explanation:when mpeg2enc is invoked without the 'q' flag it creates "constantbit-rate" MPEG streams. Where (loosely speaking) the strength of compression (and hence picture quality) is adjusted to ensure that on average each frame of video has exactly the specified number of bits. Such constant bit-rate streams are needed for broadcasting and for low-cost hardware like DVD and VCD players which use slow fixed- speed player hardware. Obviously this is fairly inefficient as it means inactive scenes use up bits that could better be "spent" on rapidly changing scenes. Setting the 'q' flag tells mpeg2enc to generate variable bit-rate streams. For such streams the bit-rate specified is simply the maximum permissible. The 'q' parameter specifies the minimum degree of compression to be applied by specifying how exactly picture information is recorded. Typically, 'q' would be set so that quiet scenes would use less than the specified maximum (around 6 or 8) but fast moving scenes would still be bit-rate limited. For archival purposes setting a maximum bit-rate high enough never to be reached (e.g. 10Mbps) and a q of 2 or 3 are reasonable choices. Example: > lav2yuv stream.avi | yuvscaler -I ACTIVE_352x240+0+24 | mpeg2enc -b 1152 -r 16 -4 1 -2 1 -o video.m1v Usually there is at the top and at the bottom a nearly black border and a lot of bandwidth is used for something you do not like. The yuvscaler -I ACTIVE option sets everything that is not in the described area to black, but the imagesize (352x288) is not changed. So you have a real black border the encoder only uses a few bits for encoding them. You are still compatible with the VCD's format in this example. To determine the active window extract one frame to the jpeg format: > lavtrans -f i -i 100 -o frame.jpg test.avi Than use your favorite graphic display program to determine the active size. The -4 1 and -2 1 options improves the quality about 10% but conversion is slower. At the size of 352x288 (1/2 PAL size, created when using the -d 2 option when recording) the needed bitrate is/should be between 1000 - 1500kBit/s. For NTSC it should be about the same, because the image is smaller, but there are more frames per second than in PAL. Anyways, the major factor is quality of the original and the degree of filtering. Poor quality unfiltered material typically needs a higher rate to avoid visible artifacts. If you want to reduce bit-rate without annoying artifacts when compressing broadcast material you should try one (or more) of the noise filters. Example: > lav2yuv stream.avi | mpeg2enc -b 1500 -n s -g 6 -G 20 -P -o video.m1v Here the stream.avi will be encoded with:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -