mjpegtools.1
来自「Motion JPEG编解码器源代码」· 1 代码 · 共 2,296 行 · 第 1/5 页
1
2,296 行
First there is some general description in the encoding process and afterwardsthere is a detailed description of some commonly used output formats. .PPIf you want a one command conversation to mpeg videos try lav2mpeg inthe scripts directory.PPThe encoding with the lav2mpeg script looks like this for mpeg1 output:.PP\fB>lav2mpeg -a 160 -b 2110 -d 320x240 -m mpeg1 -o output.mpg file.eli\fP.PP.nr ll +1.nr t\n(ll 0.if \n(ll>1 .RS.nr bi 1.PPWill create a mpeg1 with videobitrate of 2110kBit/sec and audiobitrate of 160 kBit/sec.nr bi 1.PPat a resolution of 320x240.if \n(ll>1 .RE.nr ll -1.PPOr for the generation of mpeg2 output:.PP\fBlav2mpeg -o mpeg2 -O output.mpg file.eli\fP.PP.nr ll +1.nr t\n(ll 0.if \n(ll>1 .RS.nr bi 1.PPWill create a mpeg2 with default bitrate in same resolution as the inputresolution.if \n(ll>1 .RE.nr ll -1.PPBetter results can be accomplished, however, by trying various optionsand find out which ones work best for you. These are discussed below..PPThe creation of MPEG1 movies is explained with more examples and ingreater detail because most of the things that can be used for MPEG1 also work for the other output formats.PPFor the creation of of VCD/SVCD Stills sequences (-f 6, -f 7 in mpeg2enc) youshould see:Still sequences are needed for the creation of menus in VCD/SVCD. Thecreation of menus is described in the doku of vcdimager..PP.SH Creating sound.PPMPEG-1 videos need MPEG1-layer2 sound files. For MPEG-2 videos you canuse MPEG1-Layer2 and MPEG1-Layer3 (MP3). Layer 3 (MP3) audio is not anoffically valid audio format but many VCD players will recognize it. MP3audio 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 havegreat problems with this too) are not able to play MPEG2-Video andMPEG1-Layer3 sound..PP.PPmp2enc is a MPEG1-layer 2 Audio encoder. The toolame encoder is also ableto produce an layer 2 file. You can use that one as well. Toolame is muchfaster than mp2enc but toolame does not peform resampling (48000 to 44100samples/second). Many hardware players will play SVCDs using 48000 rateaudio. For mp3 creation I'm be sure you have an encoder..PPExample:.PP\fB> lav2wav stream.avi \(br mp2enc -o sound.mp2\fP.PPThis creates a mpeg sound file out of the stream.avi with 224kBit/secbitrate and a sample rate of 48kHz. If you audio file has 44.1kHz mp2encresamples 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.PPExample.PP\fB> cat sound.wav \(br mp2enc -v 2 -V -o sound.mp2\fP.PPThis creates a VCD (-V bitrate=224, stereo, sampling rate:44100)compatible output from the wav file..PPWith -v 2 mp2enc is more verbose, while encoding you see the number of sec ofaudio already encoded..PPYou can test the output with:.PP\fB> plaympeg sound.mp2\fP.PP\fBNOTE:\fP plaympeg is a MPEG1 Player for Linux, you can use other playersas well, for MPEG audio testing you can also use mpg123..PP.SH Converting video.PPYou can create MPEG1 and MPEG2 videos..PPNormally the first video you create is not the best. For optimalquality/size you need to play with the bitrate, search radius, noisefilter .... The options of mpeg2enc are described in the manpage ofmpeg2enc..PPExample:.PP\fBlav2yuv stream.avi stream1.avi \(br mpeg2enc -o video.m1v\fP.PPThis 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 morefiles and also use the placeholder %nd. Where \fBn\fP describesthe number..PPExample:.PP\fB> lav2yuv streami%02d.avi \(br mpeg2enc -b 1500 -r 16 -o video.m1v\fP.PP.PPmpeg2enc creates a video with a bitrate of 1500kBit/s usesan search radius of 16. That means when trying to find similar 16*16macroblocks of pixels between frames the encoder looks up to 16pixels away from the current position of each block. It looks twice asfar when comparing frames 1 frame apart and so on. Reasonable valuesare 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 lowerquality (more visible artifacts) while higher values (24, 32) improve thequality at the cost of the speed. With the file description ofstream%02d.avi all files are processed that match this patternwith 00, 01.....PP.PPScaling.PPUsing yuvscaler one can now also scale the video before encoding it.This can be useful for users with a DC10 or DC10+ cards which capturesat -d 1 768x576 or -d 2 384x288 (PAL/SECAM) or -d 1 640x480 (NTSC)..PPYou get a full description of all commands by reading the manpage or running:.PP\fB>yuvscaler -h\fP.PPExample:.PP\fB> lav2yuv stream.avi \(br yuvscaler -O VCD \(br mpeg2enc -o video.m1v\fP.PPThis will scale the stream to VCD size which for PAL/SECAM is 352x288 andfor NTSC is 352x240. The scaled yuvstream is encoded to MPEG-1..PPIt can also do SVCD scaling to 480x480 (NTSC) or 480x576 (PAL/SECAM):.PP\fB> lav2yuv stream.avi \(bryuvscaler -O SVCD -M BICUBIC \(br mpeg2enc -o video.m1v\fP.PPThe mode keyword (-M) forces yuvscaler to use the higher qualitybicubic algorithms for downscaling and not the default resamplealgorithms. Upscaling is always done using the bicubic algorithm..PPExample.PP\fB> lav2yuv stream.avi \(br yuvscaler -I USE_450x340+20+30-O SIZE_320x200 \(br mpeg2enc -o video.m1v \fP.PPHere we only use a part of the input and specify a nonstandard output resolution..PP\fBNOTE:\fP yuvscaler can set a active area, and set everything else toblack using: -I ACTIVE_WidthxHeight+WidthOffset+HeightOffset .PPTesting is done by:.PP\fB> plaympeg video.m1v\fP.PP\fBNOTE:\fPThese are only examples. There are more options you can use. Youcan use most of them together to create high quality videos with thelowest possible bitrate..PP\fBNOTE2:\fPThe higher you set the search radius the longer the conversionwill take. In general the more options used the longer encoding takes..PP\fBNOTE3:\fPMPEG1 was not designed to be a VBR (variable bitrate stream) !!So if you encode with -q 15 mpeg2enc sets the maximal bitrate -b to1152. If you want a VBR MPEG1 you have to set -b very high (2500)..PP\fBNOTE4:\fPMaybe you should give better names than video.mpg. A good ideais to use the options as part of the filename(for example: \fBvideo_b1500_r16_41_21.m1v\fP).Another possibility is to call all the layer 2 files \(rq\&.mp2\(rq all theMPEG-1 video files \(rq\&.m1v\(rq and all MPEG-2 video files \(rq\&.m2v\(rq Easy to see what's happening then. Reserve .mpg formultiplexed MPEG-1/2 streams..PP.SH Putting the streams together.PPExample:.PP\fB> mplex sound.mp2 video.m1v -o my_video.m1v\fP.PPPuts the sound.mp2 and the video.m1v stream together to my_video.mpg.PPNow you can use your preferred MPEG player and watch it. All players (gtv forexample) 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..PP\fBNOTE:\fP If you have specified the \fB-S\fP option for mpeg2encmplex will automatically split the files if there is in the output filenamea %d (looks like: -o test%d.mpg) The files generated this wayare separate stand-alone MPEG steams!.PP\fBNOTE2:\fP xine might have a problem with seeking through videos.mplayer has a problem with the \(rqseek backward/forward\(rq with variable bitrate streams because it goes forward in the file the amount ofdata for a constant bitrate stream. That amount might be significantly morethan 10 seconds or one minute (those are the amount mplayer seeks for eachpress of the arrow keys). So don't wonder if it seeks much more timeforward or backward than you expect..PP\fBVariable bit-rate multiplexing:\fPRemember to tell mplex you're encoding VBR (-V option) as well asmpeg2enc (see the example scripts). It *could* auto-detect but it is notworking yet. You should tell mplex a video buffer size at least as largeas the one you specified to \(rqmpeg2enc\(rq Sensible numbers forMPEG-1 might be a ceiling bit-rate of 2800Kbps, a quality ceiling(quantization floor) of 6 and a buffer size of 400K..PPExample:.PP\fB> mplex -V -r 1740 audio.mp2 video_vbr.m1v -o vbr_stream.mpg\fP.PPHere we multiplex a variable bitrate stream. mplex is now a singlepass multiplexer so it can't detect the maximal bitrate and we have tospecify it. The data rate for the output stream is: audio bitrate + peak videobitrate + 1-2% for mplex information. If audio (-b 224) has224kBit, video has 1500kBit (was encoded with -b 1500 -q 9) then wehave 1724 * 1.01 or about 1740kBit..PPExample:.PP\fB> plaympeg my_video.mpg\fP.PPoder.PP\fB> gtv my_video.mpg\fP.SH Creating MPEG1 Videos.PPFor MPEG1 you can use mpeg layer 2 Audio and mpeg1 video. A subset ofMPEG1 movies are VCD's. You can use VBR (Variable BitRate) for theVideo (although VCDs are almost always use CBR video) but the Audio has to be CBR (Constant BitRate)..PPMPEG1 is recommended for picture sizes up to 352x288 for PAL and352x240 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 videois interlaced you need MPEG2 to get it proper encoded. ..PP.PPMPEG1 Audio creation Example.PP\fB> lav2wav editlist.eli \(br mp2enc -r 44100 -o sound.mp2\fP.PPYou can save some bits by tellingmp2enc 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..PP\fB> lav2wav editlist.eli \(br mp2enc -b 128 -m -o sound.mp2\fP.PPThis 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 streamwith lavtrans to get it converted properly..PP.PPMPEG1 Video creation Example.PP\fB> lav2yuv editlist.eli \(br mpeg2enc -b 2000 -r 24 -q 6 -o video.m1v\fP.PPmpeg2enc creates an video with an bitrate of 2000kBit/s (or2048000Bit/s) but the -q flag activates the variable bitrate and aquality factor of 6. It uses a search radius of 24..PP.PP\fBExplanation:\fPwhen mpeg2enc is invoked without the 'q'flag it creates \(rqconstantbit-rate\(rq MPEG streams. Where (looselyspeaking) the strength of compression (and hence picture quality) isadjusted to ensure that on average each frame of video has exactly thespecified number of bits. Such constant bit-rate streams are needed forbroadcasting and for low-cost hardware like DVD and VCD players which useslow fixed-speed player hardware..PPObviously this is fairly inefficient as it means inactive scenes useup bits that could better be \(rqspent\(rq on rapidly changing scenes.Setting the 'q' flag tells mpeg2enc to generate variable bit-ratestreams. For such streams the bit-rate specified is simply the maximumpermissible. The 'q' parameter specifies the minimum degree ofcompression to be applied by specifying how exactly pictureinformation is recorded. Typically, 'q' would be set so that quietscenes would use less than the specified maximum (around 6 or 8) butfast moving scenes would still be bit-rate limited. For archivalpurposes setting a maximum bit-rate high enough never to be reached(e.g. 10Mbps) and a q of 2 or 3 are reasonable choices..PPExample:.PP\fB> lav2yuv stream.avi \(br yuvscaler -I ACTIVE_352x240+0+24\(br mpeg2enc -b 1152 -r 16 -4 1 -2 1 -o video.m1v\fP.PPUsually there is at the top and at the bottom a nearly black borderand a lot of bandwidth is used for something you do not like. Theyuvscaler -I ACTIVE option sets everything that is not in thedescribed area to black, but the imagesize (352x288) is not changed.So you have a real black border the encoder only uses a few bits forencoding 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:.PP\fB> lavtrans -f i -i 100 -o frame.jpg test.avi\fP.PPThan use your favorite graphic display program to determine the active size.The -4 1 and -2 1 options improves the quality about 10% but conversionis slower..PPAt 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..PP.PP.PPAnyways, the major factor is quality of the original and the degree offiltering. Poor quality unfiltered material typically needs a higherrate to avoid visible artifacts.If you want to reduce bit-rate without annoying artifacts whencompressing broadcast material you should try one (or more) of the noise filters..PPExample:.PP\fB> lav2yuv stream.avi \(br mpeg2enc -b 1500 -n s -g 6 -G 20 -P -ovideo.m1v\fP.PPHere the stream.avi will be encoded with:.PP.nr ll +1.nr t\n(ll 2.if \n(ll>1 .RS.IP "-b 1500".nr bi 1.PPa Bitrate of 1500kBit/sec.IP "-n s".nr bi 1.PPthe input Video norm is forced to SECAM
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?