mjpegtools.1
来自「Motion JPEG编解码器源代码」· 1 代码 · 共 2,296 行 · 第 1/5 页
1
2,296 行
recording at full resolution as you need to reduce to -d 2 resolutionlater anyway..PPyou can record at other sizes than the obvious -d 1/2/4. You can use combinations where you use halve horizontal size and full vertical size: -d 21.This would record for NTSC at a size of 352x480. This helps if you want tocreate SVCDs, scaling the 352 Pixles put to 480 is not that visible for the eyeas if you would use the other combination -d 12. Where you have the fullhorzontal resolution and half vertical this Version will have a size of720x288 for NTSC.PP.SH Some information about the typical lavrec output while recording.PP0.06.14:22 int: 00040 lst:0 ins:0 del:0 ae:0 td1=0.014 td2=0.029.PPThe first part shows the time lavrec is recording.\fBint:\fP the interval between two frames. \fBlst:\fP the number oflost frames. \fBins and del:\fP are the number of frames inserted anddeleted for sync correction. \fBae:\fP number of audio errors.\fBtd1 and td2\fP are the audio/video time-difference..PP.nr ll +1.nr t\n(ll 0.if \n(ll>1 .RS.nr bi 1.PP\fB(int) frame interval\fP should be around 33 (NTSC) or 40(PAL/SECAM). If it is very different, you'll likely get a bad recordingand/or many lost frames.nr bi 1.PP\fB(lst) lost frames\fP are bad and mean that something is not workingvery well during recording (too slow HD, too high CPU usage, ...) Tryrecording with a greater decimation and possibly a lower quality..nr bi 1.PP\fB(ins, del) inserted OR deleted frames\fP of them are normal \(->sync. If you have many lost AND inserted frames, you're asking too muchof your machine. Use less demanding options or trya different sound card..nr bi 1.PP\fB(ae) audio errors\fP are never good. Should be 0.nr bi 1.PP\fB(td1, td2) time difference\fPis always floating around 0, unlesssync correction is disabled (--synchronization!=2, 2 is default)..if \n(ll>1 .RE.nr ll -1.PP.SH Notes about \(rqinterlace field order - what can go wrong and how to fix it\(rq.PPFirstly, what does it mean for interlace field order to be wrong?.PPThe whole mjpegtools image processing chain is frame-oriented. Since itis video material that is captured each frame comprised a top field (the0th, 2nd, 4th and so lines) and a bottom field (the 1st, 3rd, 5th and soon lines)..PP.PPThere are three bad things that can happen with fields.PP.nr ll +1.nr el +1.nr t\n(ll 1.nr e\n(el 0 1.af e\n(el \*(f\n(el.if \n(ll>1 .RS.nr bi 1.PPThis is really only an issue for movies in PAL video where each filmframe is sent as a pair of fields. These can be sent top or bottom fieldfirst and sadly it's not always the same, though bottom-first appears to beusual. If you capture with the wrong field order (you start capturingeach frame with a bottom rather than a top or vice versa) the frames of themovie get split *between* frames in the stream. Played back on aTV where each field is displayed on its own this is harmless. The sequenceof fields played back is exactly the same as the sequence of fieldsbroadcast. Unfortunately, playing back on a Computer monitor where bothfields of a frame appear at once it looks *terrible* because eachframe is effectively mixing two moments in time 1/25sec apparent..nr bi 1.PPThe two fields can simply be swapped somehow so that top gets treatas bottom and bottom treat as top. Juddering and \(rqslicing\(rq is theresult. This occasionally seems to happen due to hardware glitches in thecapture card..nr bi 1.PPSomewhere in capturing/processing the *order* in time of the twofields in each frame can get mislabeled somehow. This is not good as itmeans that when playback eventually takes place a field containing animage sampled earlier in time comes after an image sampled later.Weird \(rqjuddering\(rq effects are the results..if \n(ll>1 .RE.nr el -1.nr ll -1.PP.PPHow can I recognize if I have one of these Problems ? .PP.nr ll +1.nr el +1.nr t\n(ll 1.nr e\n(el 0 1.af e\n(el \*(f\n(el.if \n(ll>1 .RS.nr bi 1.PPThis can be hard to spot. If you have mysteriously flickery picturesduring playback try encoding a snippet with the reverse field-orderforced (see below). If things improve drastically you know what theproblem was and what the solution is! .nr bi 1.PPThe two fields can simply be swapped somehow so that top gets treatas bottom and bottom treat as top. Juddering and \(rqslicing\(rq isthe result. This occasionally seems to happen due to hardware glitches inthe capture card. That problem lookes like that:.PPInterlacing problem.PP.PP.nr bi 1.PPSomewhere in capturing/processing the *order* in time of the twofields in each frame can get mislabeled somehow. This is not good as itmeans that when playback eventually takes place a field containing an imagesampled earlier in time comes after an image sampled later. Weird \(rqjuddering\(rq effects are the result..if \n(ll>1 .RE.nr el -1.nr ll -1.PPIf you use glav or lavplay be sure that you also use the \fB-F/--flicker\fPoption. This disables some things that make the picture look better..PPIf you want to look at the video you can also use yuvplay:.PP\fB> lav2yuv \(br ... \(br yuvplay\fP.PPIf there is a field order problem you should see it with yuvplay..PP.PPHow can you fix it? .PP.nr ll +1.nr el +1.nr t\n(ll 1.nr e\n(el 0 1.af e\n(el \*(f\n(el.if \n(ll>1 .RS.nr bi 1.PPTo fix this one the fields need to be \(rqshifted\(rq throughthe frames. Use yuvcorrect's \fB-T BOTT_FORWARD/TOP_FORWARD\fP toshift the way fields are allocated to frames. You can find out the currentfield order for an MJPEG file by looking at the first few lines of debugoutput from: \fB> lav2yuv -v 2 the_mjpeg_file > /dev/null\fP Or re-record exchanging \fB-f a\fP for \fB-F A\fP or vice-versa. .nr bi 1.PPThis isn't too bad either. Use a tool that simply swaps the topand bottom fields a second time. yuvcorrect can do this use the\fB-T LINE_SWITCH\fP\&. .nr bi 1.PPIs easy to fix. Either tell a tool someplace to relabel the fields orsimply tell the player to play back in swapped order (the latter can be done\(rqindirectly\(rq by telling mpeg2enc when encoding to \fBreverse theflag (-z b\(brt)\fP that tells the decoder which field order to use. .if \n(ll>1 .RE.nr el -1.nr ll -1.PP.PP\fBIn order to determine exactly what type of interlacing problem youhave, you need to extract some frames from the recorded stream and take alook at them:\fP.PP.DS.sp .ft RR.nf> mkdir pnm > lav2yuv -f 40 video.avi \(br y4mtoppm \(br pnmsplit - pnm/image%d.pnm > rm pnm/image?.pnm > cd pnm > xv .DE.fi .ec.ft P.sp.PPFirst we create a directory where we store the images. The lav2yuv -f 40writes only the first 40 frames to stdout. The mjpegtools y4mtoppm convertsthe frames to pnm images and the pnmsplit splits the picture into twoframes in the picture to two single pictures. Then we remove the first 10images because pnmsplit does not support the %0xd numbering. Withouta leading zero in the number, the files will be sorted in the wrong order,leading to confusing playback..PPUse your favorite graphic program (xv for example) to view the pictures. Aseach picture only contain one field out of two they will appear scaledvertically. If you look at the pictures you should see the movie slowlyadvancing..PPIf you have a film you should always see 2 pictures that are nearly the same(because the film frame is split into two field for broadcasting) after each other.You can observe this easily if you have comb effects whenyou pause the film because both fields will be displayed at the same time. Thetwo pictures that belong together should have an even number and the followingodd number. So if you take a look on pictures: 4 and 5 are nearly identical,5 and 6 differ (have movement), 6 and 7 identical, 7 and 8 differ , .....PPTo fix this problem you have to use yuvcorrect's \fB-T BOTT_FORWARD orTOP_FORWARD\fP\&. You can also have the problem that the field order(top/bottom) is still wrong. You may have to use yuvcorrect a second timewith \fB-M LINE_SWITCH\fP, or use the mpeg2enc \fB-z (b\(brt)\fP option..PPTo see if you guessed correctly, extract the frames again, reordering themusing yuvcorrect:.PP\fB> lav2yuv -f 40 video.avi \(br yuvcorrect -T OPTION \(br y4mtoppm \(br pnmsplit - pnm/image%d.pnm \fP.PPWhere \(rqOPTION\(rq is what you think it will corrects the problem.This is for material converted from film. Material produced directly for TVis addressed below..PP.PPHey, what about NTSC movies ?.PPMovies are broadcast in NTSC using \(rq3:2\(rq pulldown which meansthat half the capture frames contain fields from 1 movie frame and halffields from 2 frames. To undo this effect for efficient MPEG encoding youneed to use yuvkineco. .PPIf you have an interlaced source like a TV camera you have a frame consistsof two fields that are recorded at different points in time and shown aftereach other. Spotting the problem here is harder. You need to find somethingmoving horizontally from the left to the right. When you extract the fields,the thing should move in small steps from the left to the right, not onelarge step forward, small step back, large forward, small back......You have to use the same options mentioned aboth to correct the problem..PPDo not expect that the field order is always the same (top- or bottom-first)It may change between the channels, between the films, and it may even changewithin a film. If it changes constant you may have to encode with the mpeg2enc-I 1 or even -I 2..PPYou can only have this problems if you record at full size !!! .PPCreating videos from other sources.PPHere are some hints and descriptions of how to create the videos from othersources like images and other video types..PPYou might also be interested in taking a look at the\fBTranscoding of existing MPEG-2\fP section..PP.PP.SH Creating videos from images.PPYou can use jpeg2yuv to create a yuv stream from separate JPEG images. Thisstream is sent to stdout, so that it can either be saved into a file,encoded directly to a mpeg video using mpeg2enc or used for anything else..PPSaving an yuv stream can be done like this:.PP\fB> jpeg2yuv -f 25 -I p -j image%05d.jpg > result.yuv\fP.PPCreates the file result.yuv containing the yuv video data with 25 FPS. The-f option is used to set the frame rate. Note that image%05d.jpgmeans that the jpeg files are named image00000.jpg, image00001.jpg and soon. (05 means five digits, 04 means four digits, etc.) The -I p is neededfor specifing the interlacing. You have to check which type you have.If you don't have interlacing just choose p for progressive.PPIf you want to encode a mpeg video directly from jpeg images without savinga separate video file type:.PP\fB> jpeg2yuv -f 25 -I p -j image%05d.jpg \(br mpeg2enc -o mpegfile.m1v\fP.PPDoes the same as above but saves a mpeg video rather than a yuv video. Seempeg2enc section for details on how to use mpeg2enc..PPYou can also use yuvscaler between jpeg2yuv and mpeg2enc. If you want tocreate a SVCD from your source images:.PP\fB> jpeg2yuv -f 25 -I p -j image%05d.jpg \(br yuvscaler -O SVCD\(br mpeg2enc -f 4 -o video.m2v\fP.PPYou can use the -b option to set the number of the image to start with. Thenumber of images to be processed can be specified with the -n number. Forexample, if your first image is image01.jpg rather than image00.jpg, and you only want 60 images to be processed type:.PP\fB>jpeg2yuv -b 1 -f 25 -I p -n 60 -j image*.jpg \(br yuv2lav -o stream_without_sound.avi\fP.PPAdding the sound to the stream then:.PP\fB> lavaddwav stream_without_sound.avi sound.wav stream_with_sound.avi\fP.PPFor ppm input there is the ppmtoy4m util. There is a manpage for ppmtoy4m thatshould be consulted for additional information..PPSo to create a mpeg video try this:.PP\fB>cat *.ppm \(br ppmtoy4m -o 75 -n 60 -F 25:1 \(br mpeg2enc -o output.m1v\fP.PPCat's each *.ppm file to ppmtoy4m. There the first 75 frames (pictures) areignored and next 60 are encoded by mpeg2enc to output.m1v. You can run itwithout the -o and -n option. The -F options sets the frame rate, defaultis NTSC (30000:1001), for PAL you have to use -F 25:1..PPOther picture formats can also be used if there is a converter to ppm..PP\fB>ls *.tga \(br xargs -n1 tgatoppm \(br ppmtoy4m \(br yuvplay\fP.PPA list of filenames (ls *.tga) is given to xargs that executes the tgatoppm with one (-n 1) argument per call, and feeds the output into ppmtoy4m.This time the video is only shown on the screen. The xargs is only neededif the converter (tgatoppm), can only operate on a single image at a time..PPIf you want to use the ImageMagick 'convert' tool (a Swiss Army Knife) try:.PP\fB>convert *.gif ppm:- \(br ppmtoy4m \(br yuvplay\fP.PPThat means take all '.jpg' images in directory, convert to PPM format,and pipe to stdout, then ppmtoy4m processes them .....PP.SH Decoding streams with mplayer .PPDecoding the streams with mplayer is a nice way of bringing every videothat mplayer can play back to something you can edit or encode directly to a mpeg video with the mjpegtools. This method works with mplayer 1.0pre2 or newer.PP\fB>mkfifo stream.yuv\fP.PP\fB>mplayer -nosound -noframedrop -vo yuv4mpeg anyfile.mpg &\fP.PP\fB>cat stream.yuv \(br yuv2lav -o mjpeg_wo.avi\fP.PP\fB>mplayer -vo null -ao pcm -aofile anyfile.wav anyfile.mpg\fP.PPNow you have for example a mjpeg encoded AVI without sound. The sound will be in anyfile.wav. Now you can choose if you want to add the sound to the AVI with \fBlavaddwav\fP and edit the file and encode it..PPYou can also use instead of yuv2lav, mpeg2enc or any other tool from the mjpeg tools so your command might also look like that:.PP\fB> cat stream.yuv \(br yuvdenoise \(br yuvscaler -O SVCD \(br mpeg2enc -f 4 -o video_svcd.m2v\fP.PPAnd cat the wav file into \fBmp2enc\fP to encode it to MP2 audio. The \fB-vo yuv4mpeg\fP option works well with other input types mentioned inthe mplayer documentation. .SH Decoding MPEG2 streams with mpeg2dec
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?