diff -r -c --new-file mpeg2_movie-1.4/mplexhi/multplex.c mpeg2_movie-1.4-avi/mplexhi/multplex.c *** mpeg2_movie-1.4/mplexhi/multplex.c Mon Jan 22 22:26:14 2001 --- mpeg2_movie-1.4-avi/mplexhi/multplex.c Wed Jan 24 04:58:37 2001 *************** *** 142,148 **** printf("\nMerging elementary streams to MPEG/SYSTEMS multiplexed stream.\n"); printf("\n+------------------ MPEG/SYSTEMS INFORMATION -----------------+\n"); ! sector_size = 2048; packets_per_pack = 1; video_buffer_size = 46; audio_buffer_size = 4; --- 142,148 ---- printf("\nMerging elementary streams to MPEG/SYSTEMS multiplexed stream.\n"); printf("\n+------------------ MPEG/SYSTEMS INFORMATION -----------------+\n"); ! sector_size = 2324 ; packets_per_pack = 1; video_buffer_size = 46; audio_buffer_size = 4; diff -r -c --new-file mpeg2_movie-1.4/video/Makefile mpeg2_movie-1.4-avi/video/Makefile *** mpeg2_movie-1.4/video/Makefile Mon Jan 22 22:26:14 2001 --- mpeg2_movie-1.4-avi/video/Makefile Wed Jan 24 05:01:17 2001 *************** *** 35,40 **** --- 35,45 ---- # END OF USER CONFIGURATION + all: encode + + aviplugin.o: aviplugin.C aviplugin.h + $(CXX) $(CFLAGS) -I/usr/local/include/avifile aviplugin.C -c + OBJ = mpeg2enc.o \ conform.o \ putseq.o \ *************** *** 52,60 **** idct.o \ quantize.o \ ratectl.o \ stats.o - all: encode pc: mpeg2enc.exe --- 57,65 ---- idct.o \ quantize.o \ ratectl.o \ + aviplugin.o \ stats.o pc: mpeg2enc.exe *************** *** 65,68 **** coff2exe mpeg2enc encode: $(OBJ) ! $(CC) $(CFLAGS) -o encode $(OBJ) ../libmpeg3/libmpeg3.a ../quicktime/libquicktime.a -lpthread -lpng -lz -lm -lglib -ldl --- 70,73 ---- coff2exe mpeg2enc encode: $(OBJ) ! $(CXX) $(CFLAGS) -o encode $(OBJ) ../libmpeg3/libmpeg3.a -L/usr/local/lib -laviplay ../quicktime/libquicktime.a -lpthread -lpng -lz -lm -lglib -ldl diff -r -c --new-file mpeg2_movie-1.4/video/aviplugin.C mpeg2_movie-1.4-avi/video/aviplugin.C *** mpeg2_movie-1.4/video/aviplugin.C Thu Jan 1 01:00:00 1970 --- mpeg2_movie-1.4-avi/video/aviplugin.C Wed Jan 24 04:58:37 2001 *************** *** 0 **** --- 1,133 ---- + /******************************************** + * the avi hack for mpeg2movie by * + * * + * Roman Hochleitner amd Alexander Oelzant * + * * + * roman@mars.tuwien.ac.at * + * aoe@mars.tuwien.ac.at * + * * + * with a bit of c++ help from Josef Schmid * + * * + ******************************************** + * USE AT YOUR OWN RISK NO WARRANTY * + * (might crash your truck!) * + ******************************************** + * * + * parts borrowed from Eugene Smith * + * * + * * + * This Software is under GPL version 2 * + * * + * http://www.gnu.org/copyleft/gpl.html * + * ---------------------------------------- * + * Sat Dec 2 03:49:57 CET 2000 * + ********************************************/ + + #include "aviplugin.h" + #include + #include + #include + + namespace { + IAviReadFile *file=0; + IAviReadStream *stream; + int video_width; + int video_height; + } + + /* GetEndPos() == cnt_frames */ + + int avi_open(char *tplorg) + { + file=CreateIAviReadFile(tplorg); + stream=file->GetStream(0, AviStream::Video); + BITMAPINFOHEADER bh; + stream->StartStreaming(); + // wtf? stream->SetBitDepth(24); + stream->GetOutputFormat(&bh, sizeof bh); + + video_width = abs(bh.biWidth); + video_height = abs(bh.biHeight); + if ((video_height & 1) == 1) { + video_height--; + fprintf(stderr, "\nIncompatible video height, reducing height to %d\n", video_height); + } + + /* + fprintf(stderr, "videos width=%d height=%d \n", video_width, video_height); + */ + + return(0); + } + + int avi_close() + { + delete file; + return(0); + } + + int avi_video_width() + { + return(video_width); + } + + int avi_video_height() + { + return(video_height); + } + + double avi_frame_rate() + { + return(1.0/(stream->GetFrameTime())); + } + + + char *avi_get_frame(unsigned int number) + { + static CImage *img; + static int mostrecent = 0; + + if (((mostrecent) != (number)) || (mostrecent == 0)) { // gotta seek + // fprintf(stderr,"seeking to %i\n",number); + stream->SeekToKeyframe(number); + stream->ReadFrame(); // bug in avilib: cannot GetPos() before GetFrame() + if (img) + img->release(); // free some memory + img = stream->GetFrame(); + } + while ((mostrecent=stream->GetPos())<(number+1)) { + // fprintf(stderr,"reading frame %i\n",mostrecent); + stream->ReadFrame(); + if (img) + img->release(); // free some memory + img = stream->GetFrame(); + /* if (! img->get_fmt()->IsRGB()) img->ToRGB(); */ + /* img->ToYUV(); */ + } + + // fprintf(stderr,"read %i\n",stream->GetPos()-1); + return((char *)img->data()); + } + + // we don't really check sig, just the extension + + int avi_check_sig(char *fname) + { + int len; + + len=strlen(fname); + if (len < 4) + return(0); + if ((0 == strcmp(fname+len-4,".asf")) || (0 == strcmp(fname+len-4,".ASF")) + || (0 == strcmp(fname+len-4,".avi")) || (0 == strcmp(fname+len-4,".AVI"))) + return(1); + return(0); + } + + + int avi_end_of_video() + { + return (stream->Eof()); + } + + diff -r -c --new-file mpeg2_movie-1.4/video/aviplugin.h mpeg2_movie-1.4-avi/video/aviplugin.h *** mpeg2_movie-1.4/video/aviplugin.h Thu Jan 1 01:00:00 1970 --- mpeg2_movie-1.4-avi/video/aviplugin.h Wed Jan 24 04:58:37 2001 *************** *** 0 **** --- 1,20 ---- + + #ifdef __cplusplus + extern "C" { + #endif + + #include + + int avi_open(char *tplorg); + int avi_close(); + int avi_video_width(); + int avi_video_height(); + double avi_frame_rate(); + char *avi_get_frame(unsigned int number); + int avi_end_of_video(); + int avi_check_sig(char *fname); + + #ifdef __cplusplus + } + #endif + diff -r -c --new-file mpeg2_movie-1.4/video/global.h mpeg2_movie-1.4-avi/video/global.h *** mpeg2_movie-1.4/video/global.h Mon Jan 22 22:26:14 2001 --- mpeg2_movie-1.4-avi/video/global.h Wed Jan 24 04:58:37 2001 *************** *** 270,275 **** --- 270,283 ---- EXTERN_ int load_iquant, load_niquant; /* use non-default quant. matrices */ EXTERN_ int load_ciquant,load_cniquant; + /* start/num of frames to encode - aoe */ + + EXTERN_ unsigned int start_frame; /* frame to start at */ + EXTERN_ unsigned int num_encode; /* number of frames to encode */ + + /* timestamp type - aoe */ + + EXTERN_ unsigned int timestamptype; /* type of encoded timestamp if any */ /* sequence specific data (sequence extension) */ diff -r -c --new-file mpeg2_movie-1.4/video/global.h.orig mpeg2_movie-1.4-avi/video/global.h.orig *** mpeg2_movie-1.4/video/global.h.orig Thu Jan 1 01:00:00 1970 --- mpeg2_movie-1.4-avi/video/global.h.orig Mon Jan 22 22:26:14 2001 *************** *** 0 **** --- 1,422 ---- + /* global.h, global variables, function prototypes */ + + /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ + + /* + * Disclaimer of Warranty + * + * These software programs are available to the user without any license fee or + * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims + * any and all warranties, whether express, implied, or statuary, including any + * implied warranties or merchantability or of fitness for a particular + * purpose. In no event shall the copyright-holder be liable for any + * incidental, punitive, or consequential damages of any kind whatsoever + * arising from the use of these programs. + * + * This disclaimer of warranty extends to the user of these programs and user's + * customers, employees, agents, transferees, successors, and assigns. + * + * The MPEG Software Simulation Group does not represent or warrant that the + * programs furnished hereunder are free of infringement of any third-party + * patents. + * + * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, + * are subject to royalty fees to patent holders. Many of these patents are + * general enough such that they are unavoidable regardless of implementation + * design. + * + */ + + #include "libmpeg3.h" + #include "mpeg2enc.h" + #include "quicktime.h" + + #include + + /* choose between declaration (GLOBAL_ undefined) + * and definition (GLOBAL_ defined) + * GLOBAL_ is defined in exactly one file (mpeg2enc.c) + */ + + #ifndef GLOBAL_ + #define EXTERN_ extern + #else + #define EXTERN_ + #endif + + /* global variables */ + + + /* zig-zag scan */ + EXTERN_ unsigned char zig_zag_scan[64] + #ifdef GLOBAL_ + = + { + 0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5, + 12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28, + 35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51, + 58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63 + } + #endif + ; + + /* alternate scan */ + EXTERN_ unsigned char alternate_scan[64] + #ifdef GLOBAL_ + = + { + 0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49, + 41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43, + 51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45, + 53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63 + } + #endif + ; + + /* default intra quantization matrix */ + EXTERN_ unsigned char default_intra_quantizer_matrix[64] + #ifdef GLOBAL_ + = + { + 8, 16, 19, 22, 26, 27, 29, 34, + 16, 16, 22, 24, 27, 29, 34, 37, + 19, 22, 26, 27, 29, 34, 34, 38, + 22, 22, 26, 27, 29, 34, 37, 40, + 22, 26, 27, 29, 32, 35, 40, 48, + 26, 27, 29, 32, 35, 40, 48, 58, + 26, 27, 29, 34, 38, 46, 56, 69, + 27, 29, 35, 38, 46, 56, 69, 83 + } + #endif + ; + + /* non-linear quantization coefficient table */ + EXTERN_ unsigned char non_linear_mquant_table[32] + #ifdef GLOBAL_ + = + { + 0, 1, 2, 3, 4, 5, 6, 7, + 8,10,12,14,16,18,20,22, + 24,28,32,36,40,44,48,52, + 56,64,72,80,88,96,104,112 + } + #endif + ; + + /* non-linear mquant table for mapping from scale to code + * since reconstruction levels are not bijective with the index map, + * it is up to the designer to determine most of the quantization levels + */ + + EXTERN_ unsigned char map_non_linear_mquant[113] + #ifdef GLOBAL_ + = + { + 0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16, + 16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22, + 22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26, + 26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29, + 29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31 + } + #endif + ; + + typedef struct + { + int start_row, end_row; + pthread_mutex_t input_lock, output_lock; + pthread_t tid; /* ID of thread */ + int done; + + unsigned char *oldorg; + unsigned char *neworg; + unsigned char *oldref; + unsigned char *newref; + unsigned char *cur; + unsigned char *curref; + int sxf; + int syf; + int sxb; + int syb; + struct mbinfo *mbi; + int secondfield; + int ipflag; + } motion_engine_t; + + typedef struct + { + pthread_mutex_t ratectl_lock; + + double R, T, d; + double actsum; + int Np, Nb; + double S, Q; + int prev_mquant; + double bitcnt_EOP; + double next_ip_delay; /* due to frame reordering delay */ + double decoding_time; + int Xi, Xp, Xb, r, d0i, d0p, d0b; + double avg_act; + } ratectl_t; + + typedef struct + { + int start_row, end_row; + pthread_mutex_t input_lock, output_lock; + pthread_t tid; /* ID of thread */ + int done; + + unsigned char **pred; + unsigned char **cur; + struct mbinfo *mbi; + short (*blocks)[64]; + } transform_engine_t; + + typedef struct + { + int start_row, end_row; + pthread_mutex_t input_lock, output_lock; + pthread_t tid; /* ID of thread */ + int done; + + int prev_mquant; + + /* prediction values for DCT coefficient (0,0) */ + int dc_dct_pred[3]; + unsigned char *frame; + unsigned char *slice_buffer; + long slice_size; + long slice_allocated; + + unsigned char outbfr; + int outcnt; + } slice_engine_t; + + EXTERN_ pthread_mutex_t test_lock; + EXTERN_ motion_engine_t *motion_engines; + EXTERN_ transform_engine_t *transform_engines; + EXTERN_ transform_engine_t *itransform_engines; + EXTERN_ slice_engine_t *slice_engines; + EXTERN_ ratectl_t *ratectl; + EXTERN_ int quiet; /* suppress warnings */ + + + + + /* picture data arrays */ + + /* reconstructed frames */ + EXTERN_ unsigned char *newrefframe[3], *oldrefframe[3], *auxframe[3]; + /* original frames */ + EXTERN_ unsigned char *neworgframe[3], *oldorgframe[3], *auxorgframe[3]; + /* prediction of current frame */ + EXTERN_ unsigned char *predframe[3]; + /* 8*8 block data */ + EXTERN_ short (*blocks)[64]; + /* intra / non_intra quantization matrices */ + EXTERN_ unsigned char intra_q[64], inter_q[64]; + EXTERN_ unsigned char chrom_intra_q[64],chrom_inter_q[64]; + /* macroblock side information array */ + EXTERN_ struct mbinfo *mbinfo; + /* motion estimation parameters */ + EXTERN_ struct motion_data *motion_data; + /* clipping (=saturation) table */ + EXTERN_ unsigned char *clp; + + /* name strings */ + EXTERN_ char id_string[256], tplorg[256], tplref[256], out_path[256]; + EXTERN_ char iqname[256], niqname[256]; + EXTERN_ char statname[256]; + EXTERN_ char errortext[256]; + + EXTERN_ FILE *outfile; /* file descriptors */ + EXTERN_ FILE *statfile; /* file descriptors */ + EXTERN_ int inputtype; /* format of input frames */ + + /* Quicktime input handle and frame buffer */ + EXTERN_ quicktime_t *qt_file; + EXTERN_ mpeg3_t *mpeg_file; + EXTERN_ unsigned char *frame_buffer; + EXTERN_ unsigned char **row_pointers; + EXTERN_ int fixed_mquant; + /* Number of processors */ + EXTERN_ int processors; + + /* coding model parameters */ + + EXTERN_ int N; /* number of frames in Group of Pictures */ + EXTERN_ int M; /* distance between I/P frames */ + EXTERN_ int P; /* intra slice refresh interval */ + EXTERN_ int nframes; /* total number of frames to encode */ + EXTERN_ long frames_scaled; /* frame count normalized to output frame rate */ + EXTERN_ int frame0, tc0; /* number and timecode of first frame */ + EXTERN_ int mpeg1; /* ISO/IEC IS 11172-2 sequence */ + EXTERN_ int fieldpic; /* use field pictures */ + + /* sequence specific data (sequence header) */ + + EXTERN_ int horizontal_size, vertical_size; /* frame size (pels) */ + EXTERN_ int width, height; /* encoded frame size (pels) multiples of 16 or 32 */ + EXTERN_ int chrom_width, chrom_height, block_count; + EXTERN_ int mb_width, mb_height; /* frame size (macroblocks) */ + EXTERN_ int width2, height2, mb_height2, chrom_width2; /* picture size adjusted for interlacing */ + EXTERN_ int aspectratio; /* aspect ratio information (pel or display) */ + EXTERN_ int frame_rate_code; /* coded value of frame rate */ + EXTERN_ double frame_rate; /* frames per second */ + EXTERN_ double input_frame_rate; /* input frame rate */ + EXTERN_ double bit_rate; /* bits per second */ + EXTERN_ int vbv_buffer_size; /* size of VBV buffer (* 16 kbit) */ + EXTERN_ int constrparms; /* constrained parameters flag (MPEG-1 only) */ + EXTERN_ int load_iquant, load_niquant; /* use non-default quant. matrices */ + EXTERN_ int load_ciquant,load_cniquant; + + + /* sequence specific data (sequence extension) */ + + EXTERN_ int profile, level; /* syntax / parameter constraints */ + EXTERN_ int prog_seq; /* progressive sequence */ + EXTERN_ int chroma_format; + EXTERN_ int low_delay; /* no B pictures, skipped pictures */ + + + /* sequence specific data (sequence display extension) */ + + EXTERN_ int video_format; /* component, PAL, NTSC, SECAM or MAC */ + EXTERN_ int color_primaries; /* source primary chromaticity coordinates */ + EXTERN_ int transfer_characteristics; /* opto-electronic transfer char. (gamma) */ + EXTERN_ int matrix_coefficients; /* Eg,Eb,Er / Y,Cb,Cr matrix coefficients */ + EXTERN_ int display_horizontal_size, display_vertical_size; /* display size */ + + + /* picture specific data (picture header) */ + + EXTERN_ int temp_ref; /* temporal reference */ + EXTERN_ int pict_type; /* picture coding type (I, P or B) */ + EXTERN_ int vbv_delay; /* video buffering verifier delay (1/90000 seconds) */ + + + /* picture specific data (picture coding extension) */ + + EXTERN_ int forw_hor_f_code, forw_vert_f_code; + EXTERN_ int back_hor_f_code, back_vert_f_code; /* motion vector ranges */ + EXTERN_ int dc_prec; /* DC coefficient precision for intra coded blocks */ + EXTERN_ int pict_struct; /* picture structure (frame, top / bottom field) */ + EXTERN_ int topfirst; /* display top field first */ + /* use only frame prediction and frame DCT (I,P,B,current) */ + EXTERN_ int frame_pred_dct_tab[3], frame_pred_dct; + EXTERN_ int conceal_tab[3]; /* use concealment motion vectors (I,P,B) */ + EXTERN_ int qscale_tab[3], q_scale_type; /* linear/non-linear quantizaton table */ + EXTERN_ int intravlc_tab[3], intravlc; /* intra vlc format (I,P,B,current) */ + EXTERN_ int altscan_tab[3], altscan; /* alternate scan (I,P,B,current) */ + EXTERN_ int repeatfirst; /* repeat first field after second field */ + EXTERN_ int prog_frame; /* progressive frame */ + + /* prototypes of global functions */ + + /* conform.c */ + void range_checks _ANSI_ARGS_((void)); + void profile_and_level_checks _ANSI_ARGS_(()); + + /* fdctref.c */ + void init_fdct _ANSI_ARGS_((void)); + void fdct _ANSI_ARGS_((short *block)); + + /* idct.c */ + void idct _ANSI_ARGS_((short *block)); + void init_idct _ANSI_ARGS_((void)); + + /* motion.c */ + void motion_estimation _ANSI_ARGS_((unsigned char *oldorg, unsigned char *neworg, + unsigned char *oldref, unsigned char *newref, unsigned char *cur, + unsigned char *curref, int sxf, int syf, int sxb, int syb, + struct mbinfo *mbi, int secondfield, int ipflag)); + + /* mpeg2enc.c */ + void error _ANSI_ARGS_((char *text)); + + /* predict.c */ + void predict _ANSI_ARGS_((unsigned char *reff[], unsigned char *refb[], + unsigned char *cur[3], int secondfield, struct mbinfo *mbi)); + + /* putbits.c */ + void slice_initbits(slice_engine_t *engine); + void slice_putbits(slice_engine_t *engine, long val, int n); + void slice_alignbits(slice_engine_t *engine); + void slice_finishslice(slice_engine_t *engine); + + + void initbits _ANSI_ARGS_((void)); + void putbits _ANSI_ARGS_((int val, int n)); + void alignbits _ANSI_ARGS_((void)); + double bitcount _ANSI_ARGS_((void)); + + /* puthdr.c */ + void putseqhdr _ANSI_ARGS_((void)); + void putseqext _ANSI_ARGS_((void)); + void putseqdispext _ANSI_ARGS_((void)); + void putuserdata _ANSI_ARGS_((char *userdata)); + void putgophdr _ANSI_ARGS_((int frame, int closed_gop)); + void putpicthdr _ANSI_ARGS_((void)); + void putpictcodext _ANSI_ARGS_((void)); + void putseqend _ANSI_ARGS_((void)); + + /* putmpg.c */ + void putintrablk _ANSI_ARGS_((slice_engine_t *engine, short *blk, int cc)); + void putnonintrablk _ANSI_ARGS_((slice_engine_t *engine, short *blk)); + void putmv _ANSI_ARGS_((slice_engine_t *engine, int dmv, int f_code)); + + /* putpic.c */ + void putpict _ANSI_ARGS_((unsigned char *frame)); + + /* putseq.c */ + void putseq _ANSI_ARGS_((void)); + + /* putvlc.c */ + void putDClum _ANSI_ARGS_((slice_engine_t *engine, int val)); + void putDCchrom _ANSI_ARGS_((slice_engine_t *engine, int val)); + void putACfirst _ANSI_ARGS_((slice_engine_t *engine, int run, int val)); + void putAC _ANSI_ARGS_((slice_engine_t *engine, int run, int signed_level, int vlcformat)); + void putaddrinc _ANSI_ARGS_((slice_engine_t *engine, int addrinc)); + void putmbtype _ANSI_ARGS_((slice_engine_t *engine, int pict_type, int mb_type)); + void putmotioncode _ANSI_ARGS_((slice_engine_t *engine, int motion_code)); + void putdmv _ANSI_ARGS_((slice_engine_t *engine, int dmv)); + void putcbp _ANSI_ARGS_((slice_engine_t *engine, int cbp)); + + /* quantize.c */ + int quant_intra _ANSI_ARGS_((short *src, short *dst, int dc_prec, + unsigned char *quant_mat, int mquant)); + int quant_non_intra _ANSI_ARGS_((short *src, short *dst, + unsigned char *quant_mat, int mquant)); + void iquant_intra _ANSI_ARGS_((short *src, short *dst, int dc_prec, + unsigned char *quant_mat, int mquant)); + void iquant_non_intra _ANSI_ARGS_((short *src, short *dst, + unsigned char *quant_mat, int mquant)); + + /* ratectl.c */ + void ratectl_init_seq _ANSI_ARGS_((ratectl_t *ratectl)); + void ratectl_init_GOP _ANSI_ARGS_((ratectl_t *ratectl, int np, int nb)); + void ratectl_init_pict _ANSI_ARGS_((ratectl_t *ratectl, unsigned char *frame)); + void ratectl_update_pict _ANSI_ARGS_((ratectl_t *ratectl)); + int ratectl_start_mb _ANSI_ARGS_((ratectl_t *ratectl)); + int ratectl_calc_mquant _ANSI_ARGS_((ratectl_t *ratectl, int j)); + void vbv_end_of_picture _ANSI_ARGS_((void)); + void calc_vbv_delay _ANSI_ARGS_((void)); + + /* readpic.c */ + void readframe _ANSI_ARGS_((char *fname, unsigned char *frame[], long number)); + + /* stats.c */ + void calcSNR _ANSI_ARGS_((unsigned char *org[3], unsigned char *rec[3])); + void stats _ANSI_ARGS_((void)); + + /* transfrm.c */ + void transform _ANSI_ARGS_((unsigned char *pred[], unsigned char *cur[], + struct mbinfo *mbi, short blocks[][64])); + void itransform _ANSI_ARGS_((unsigned char *pred[], unsigned char *cur[], + struct mbinfo *mbi, short blocks[][64])); + void dct_type_estimation _ANSI_ARGS_((unsigned char *pred, unsigned char *cur, + struct mbinfo *mbi)); + + /* writepic.c */ + void writeframe _ANSI_ARGS_((char *fname, unsigned char *frame[])); + diff -r -c --new-file mpeg2_movie-1.4/video/mpeg2enc.c mpeg2_movie-1.4-avi/video/mpeg2enc.c *** mpeg2_movie-1.4/video/mpeg2enc.c Mon Jan 22 22:26:14 2001 --- mpeg2_movie-1.4-avi/video/mpeg2enc.c Wed Jan 24 05:12:19 2001 *************** *** 35,40 **** --- 35,41 ---- #define GLOBAL_ /* used by global.h */ #include "config.h" #include "global.h" + #include "aviplugin.h" /* private prototypes */ static void init _ANSI_ARGS_((void)); *************** *** 58,64 **** " -q quantization fix the quantization, vary the bitrate\n" " -n frames set number of frames between I frames\n" " -m frames set number of frames between P frames\n" ! " -u Use only 1 processor\n\n" "Default settings:\n" " fixed 5000000 bits/sec\n" " interlaced\n" --- 59,68 ---- " -q quantization fix the quantization, vary the bitrate\n" " -n frames set number of frames between I frames\n" " -m frames set number of frames between P frames\n" ! " -u Use only 1 processor\n" ! " -S frame# set start frame\n" ! " -N frames set number of frames to encode\n" ! " -T timestamptype set timestamptype (1=time,2=framenum)\n\n" "Default settings:\n" " fixed 5000000 bits/sec\n" " interlaced\n" *************** *** 303,308 **** --- 307,313 ---- M = 1; /* M (I/P frame distance) */ processors = calculate_smp(); frame_rate = -1; + num_encode = 0; sprintf(tplorg, ""); *************** *** 380,385 **** --- 385,432 ---- } } else + if(!strcmp(argv[i], "-S")) + { + i++; + if(i < argc) + { + start_frame = atof(argv[i]); + } + else + { + fprintf(stderr, "-S requires a start frame\n"); + exit(1); + } + } + else + if(!strcmp(argv[i], "-N")) + { + i++; + if(i < argc) + { + num_encode = atof(argv[i]); + } + else + { + fprintf(stderr, "-N requires a frame count\n"); + exit(1); + } + } + else + if(!strcmp(argv[i], "-T")) + { + i++; + if(i < argc) + { + timestamptype = atof(argv[i]); + } + else + { + fprintf(stderr, "-T requires a timestamp type\n"); + exit(1); + } + } + else if(!strcmp(argv[i], "-p")) { prog_seq = 1; *************** *** 438,445 **** qt_file = quicktime_open(tplorg, 1, 0); inputtype = T_QUICKTIME; } ! if(!qt_file && !mpeg_file) { fprintf(stderr, "File format not recognized.\n"); exit(1); --- 485,497 ---- qt_file = quicktime_open(tplorg, 1, 0); inputtype = T_QUICKTIME; } + if(avi_check_sig(tplorg)) + { + avi_open(tplorg); + inputtype = T_AVI; + } ! if(!qt_file && !mpeg_file && inputtype!=T_AVI) { fprintf(stderr, "File format not recognized.\n"); exit(1); *************** *** 475,486 **** horizontal_size = quicktime_video_width(qt_file, 0); vertical_size = quicktime_video_height(qt_file, 0); } ! else { nframes = 0x7fffffff; /* Use percentage instead */ horizontal_size = mpeg3_video_width(mpeg_file, 0); vertical_size = mpeg3_video_height(mpeg_file, 0); } frame0 = 0; /* number of first frame */ h = m = s = f = 0; /* timecode of first frame */ fieldpic = 0; /* 0:frame pictures, 1:field pictures */ --- 527,546 ---- horizontal_size = quicktime_video_width(qt_file, 0); vertical_size = quicktime_video_height(qt_file, 0); } ! else if(mpeg_file) { nframes = 0x7fffffff; /* Use percentage instead */ horizontal_size = mpeg3_video_width(mpeg_file, 0); vertical_size = mpeg3_video_height(mpeg_file, 0); } + else { + nframes = 0x7fffffff; + horizontal_size = avi_video_width(); + vertical_size = avi_video_height(); + } + + if (num_encode && (nframes > num_encode)) + nframes=num_encode; frame0 = 0; /* number of first frame */ h = m = s = f = 0; /* timecode of first frame */ fieldpic = 0; /* 0:frame pictures, 1:field pictures */ *************** *** 529,534 **** --- 589,597 ---- else if(mpeg_file) input_frame_rate = mpeg3_frame_rate(mpeg_file, 0); + else + if(inputtype == T_AVI) + input_frame_rate = avi_frame_rate(mpeg_file, 0); if(frame_rate < 0) { diff -r -c --new-file mpeg2_movie-1.4/video/mpeg2enc.h mpeg2_movie-1.4-avi/video/mpeg2enc.h *** mpeg2_movie-1.4/video/mpeg2enc.h Mon Jan 22 22:26:14 2001 --- mpeg2_movie-1.4-avi/video/mpeg2enc.h Wed Jan 24 04:58:37 2001 *************** *** 89,94 **** --- 89,100 ---- #define T_PPM 2 #define T_QUICKTIME 3 #define T_MPEG 4 + #define T_AVI 5 + + /* timestamp types */ + + #define TIMESTAMP 1 + #define FRAMENUMSTAMP 2 /* macroblock information */ struct mbinfo { diff -r -c --new-file mpeg2_movie-1.4/video/readpic.c mpeg2_movie-1.4-avi/video/readpic.c *** mpeg2_movie-1.4/video/readpic.c Mon Jan 22 22:26:14 2001 --- mpeg2_movie-1.4-avi/video/readpic.c Wed Jan 24 04:58:37 2001 *************** *** 32,37 **** --- 32,38 ---- #include "colormodels.h" #include "config.h" #include "global.h" + #include "aviplugin.h" /* private prototypes */ static void border_extend _ANSI_ARGS_((unsigned char *frame, int w1, int h1, *************** *** 232,237 **** --- 233,421 ---- } } + /* sids zeug */ + static int framenum = 0; + + char font[10][5][5] = { + { // 0 + { 0x00,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0x00,0xff,0xff,0x00,0x00 }, + }, + { // 1 + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0xff,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + }, + { // 2 + { 0x00,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0x00,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0x00,0x00 }, + { 0xff,0xff,0xff,0xff,0x00 }, + }, + { // 3 + { 0xff,0xff,0xff,0x00,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0xff,0x00,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0xff,0xff,0xff,0xff,0x00 }, + }, + { // 4 + { 0x00,0x00,0xff,0xff,0x00 }, + { 0x00,0xff,0x00,0xff,0x00 }, + { 0xff,0xff,0xff,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + }, + { // 5 + { 0xff,0xff,0xff,0xff,0x00 }, + { 0xff,0x00,0x00,0x00,0x00 }, + { 0xff,0xff,0xff,0x00,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0xff,0xff,0xff,0x00,0x00 }, + }, + { // 6 + { 0x00,0xff,0xff,0xff,0x00 }, + { 0xff,0x00,0x00,0x00,0x00 }, + { 0xff,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0x00,0xff,0xff,0x00,0x00 }, + }, + { // 7 + { 0x00,0xff,0xff,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0xff,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + }, + { // 8 + { 0x00,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0x00,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0x00,0xff,0xff,0xff,0x00 }, + }, + { // 9 + { 0x00,0xff,0xff,0x00,0x00 }, + { 0xff,0x00,0x00,0xff,0x00 }, + { 0x00,0xff,0xff,0xff,0x00 }, + { 0x00,0x00,0x00,0xff,0x00 }, + { 0xff,0xff,0xff,0x00,0x00 }, + } + }; + /* sids zeug end */ + + static void read_avi(frame, number) + unsigned char *frame[]; + unsigned int number; + { + int i, j; + int r, g, b; + double y, u, v; + double cr, cg, cb, cu, cv; + char name[128]; + unsigned char *p_rgb; + unsigned char *yp, *up, *vp; + static unsigned char *u444, *v444, *u422, *v422; + static double coef[7][3] = { + {0.2125,0.7154,0.0721}, /* ITU-R Rec. 709 (1990) */ + {0.299, 0.587, 0.114}, /* unspecified */ + {0.299, 0.587, 0.114}, /* reserved */ + {0.30, 0.59, 0.11}, /* FCC */ + {0.299, 0.587, 0.114}, /* ITU-R Rec. 624-4 System B, G */ + {0.299, 0.587, 0.114}, /* SMPTE 170M */ + {0.212, 0.701, 0.087}}; /* SMPTE 240M (1987) */ + char buf[32]; + static int mostrecentp = 0; + static int mostrecent = 0; + static size_t bufsize; + + i = matrix_coefficients; + if (i>8) + i = 3; + + cr = coef[i-1][0]; + cg = coef[i-1][1]; + cb = coef[i-1][2]; + cu = 0.5/(1.0-cb); + cv = 0.5/(1.0-cr); + + if (chroma_format==CHROMA444) + { + u444 = frame[1]; + v444 = frame[2]; + } + else + { + if (!u444) + { + if (!(u444 = (unsigned char *)malloc(width*height))) + error("malloc failed"); + if (!(v444 = (unsigned char *)malloc(width*height))) + error("malloc failed"); + if (chroma_format==CHROMA420) + { + if (!(u422 = (unsigned char *)malloc((width>>1)*height))) + error("malloc failed"); + if (!(v422 = (unsigned char *)malloc((width>>1)*height))) + error("malloc failed"); + } + } + } + + p_rgb = avi_get_frame(number); + + if(avi_end_of_video()) nframes = 0; /* Terminate encoding */ + + for (i=0; i 8) i = 3; --- 440,445 ---- *************** *** 312,329 **** need_tables = 0; } ! // Get the color model in order or preference ! real_number = (long)((double)quicktime_frame_rate(qt_file, 0) / ! frame_rate * ! number + ! 0.5); ! //printf("\n 1 %d\n", real_number); ! //printf("1 %f %f\n", quicktime_frame_rate(qt_file, 0), frame_rate); ! quicktime_set_video_position(qt_file, ! real_number, ! 0); ! ! //printf("2\n"); if(quicktime_reads_cmodel(qt_file, BC_YUV420P, 0)) colormodel = BC_YUV420P; else --- 495,502 ---- need_tables = 0; } ! // Read the frame ! quicktime_set_video_position(qt_file, number, 0); if(quicktime_reads_cmodel(qt_file, BC_YUV420P, 0)) colormodel = BC_YUV420P; else *************** *** 450,460 **** : vertical_size>>1; // Normalize frame_rate ! real_number = (long)((double)mpeg3_frame_rate(mpeg_file, 0) / ! frame_rate * ! number + ! 0.5); while(mpeg3_get_frame(mpeg_file, 0) <= real_number) mpeg3_read_yuvframe(mpeg_file, frame[0], --- 623,633 ---- : vertical_size>>1; // Normalize frame_rate ! real_number = (long)((double)mpeg3_frame_rate(mpeg_file, 0) / frame_rate * number + 0.5); + if (mpeg3_get_frame(mpeg_file, 0) <= real_number) + mpeg3_set_frame(mpeg_file, real_number, 0); + while(mpeg3_get_frame(mpeg_file, 0) <= real_number) mpeg3_read_yuvframe(mpeg_file, frame[0], *************** *** 478,508 **** } void readframe(fname,frame,number) char *fname; unsigned char *frame[]; long number; { ! switch (inputtype) ! { case T_Y_U_V: ! read_y_u_v(fname, frame); break; case T_YUV: ! read_yuv(fname, frame); break; case T_PPM: ! read_ppm(fname, frame); break; case T_QUICKTIME: ! read_quicktime(frame, number); break; case T_MPEG: ! read_mpeg(number, frame); break; default: break; ! } } static void border_extend(frame,w1,h1,w2,h2) --- 651,782 ---- } + void timestamp (void **yuv,char *stamp) + { + /* sid macht framenummern als graphix hinein */ + int xpos,ypos,f,tmp; + unsigned char *dst = NULL; + int chrom_hsize = (chroma_format == CHROMA444) ? horizontal_size*2 + : horizontal_size/*>>1*/; + + + for ( f = 0; f < strlen( stamp ); f++ ) { + + if (stamp[f]>=0x30 && stamp[f]<0x3a ) { // only numbers in the font yet + for ( ypos = 0; ypos < 5; ypos++ ) { + + for ( xpos = 0; xpos < 5; xpos++ ) { + tmp = font[stamp[f]-48][ypos][xpos]; + dst = yuv[0] + ypos*2*chrom_hsize/* *3 */ + 2*5 /* *3 */ *f+xpos*2; + *dst++ = tmp; + *dst++ = tmp; + dst = yuv[1] + ypos*2*chrom_hsize/2 + 5 /* *3 */ *f+xpos; + *dst++ = 0x7f; + dst = yuv[2] + ypos*2*chrom_hsize/2 + 5 /* *3 */ *f+xpos; + *dst++ = 0x7f; + } + + for ( xpos = 0; xpos < 5; xpos++ ) { + tmp = font[stamp[f]-48][ypos][xpos]; + dst = yuv[0] + (ypos*2+1)*chrom_hsize/* *3 */ + 2*5 /* *3 */ *f+xpos*2; + *dst++ = tmp; + *dst++ = tmp; + dst = yuv[1] + (ypos*2+1)*chrom_hsize/2 + 5 /* *3 */ *f+xpos; + *dst++ = 0x7f; + dst = yuv[2] + (ypos*2+1)*chrom_hsize/2 + 5 /* *3 */ *f+xpos; + *dst++ = 0x7f; + } + + } + } + } + /* sid end */ + } + + + #define MAX_READAHEAD 3 void readframe(fname,frame,number) char *fname; unsigned char *frame[]; long number; { ! static int mostrecent = -1; ! static int mostrecentp = -1; ! static size_t bufsize; ! static unsigned char *yuv[MAX_READAHEAD][3]; ! int i,j; ! static char *stamp[32]; ! ! number += start_frame; // grmbl, avi does it ! ! if (mostrecent == -1) { // first frame to encode, number may be != 0 ! bufsize = horizontal_size*vertical_size; ! #ifdef DEBUG ! fprintf(stderr,"reserving %i*3 buffers of size %i\n",MAX_READAHEAD,bufsize); ! #endif ! for (i=0;i