diff -r -c --new-file mpeg2_movie-1.3/mplexhi/multplex.c mpeg2_movie-1.3-avi/mplexhi/multplex.c *** mpeg2_movie-1.3/mplexhi/multplex.c Thu Dec 7 19:31:24 2000 --- mpeg2_movie-1.3-avi/mplexhi/multplex.c Fri Dec 15 06:43:31 2000 *************** *** 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.3/video/Makefile mpeg2_movie-1.3-avi/video/Makefile *** mpeg2_movie-1.3/video/Makefile Thu Dec 7 19:31:24 2000 --- mpeg2_movie-1.3-avi/video/Makefile Thu Dec 28 17:11:41 2000 *************** *** 31,40 **** include ../global_config CC = gcc ! CFLAGS += -I../libmpeg3 -I../quicktime -DHAVE_MMX # END OF USER CONFIGURATION OBJ = mpeg2enc.o \ conform.o \ putseq.o \ --- 31,46 ---- include ../global_config CC = gcc ! #CFLAGS += -I../libmpeg3 -I../quicktime -DHAVE_MMX ! CFLAGS += -I../libmpeg3 -I../quicktime -DHAVE_MMX -march=pentium # 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 --- 58,66 ---- 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 --- 71,74 ---- 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.3/video/aviplugin.C mpeg2_movie-1.3-avi/video/aviplugin.C *** mpeg2_movie-1.3/video/aviplugin.C Thu Jan 1 01:00:00 1970 --- mpeg2_movie-1.3-avi/video/aviplugin.C Thu Dec 28 16:38:52 2000 *************** *** 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.3/video/aviplugin.h mpeg2_movie-1.3-avi/video/aviplugin.h *** mpeg2_movie-1.3/video/aviplugin.h Thu Jan 1 01:00:00 1970 --- mpeg2_movie-1.3-avi/video/aviplugin.h Fri Dec 8 23:26:47 2000 *************** *** 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.3/video/global.h mpeg2_movie-1.3-avi/video/global.h *** mpeg2_movie-1.3/video/global.h Thu Dec 7 19:31:24 2000 --- mpeg2_movie-1.3-avi/video/global.h Thu Dec 28 20:50:13 2000 *************** *** 267,272 **** --- 267,280 ---- 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.3/video/mpeg2enc.c mpeg2_movie-1.3-avi/video/mpeg2enc.c *** mpeg2_movie-1.3/video/mpeg2enc.c Thu Dec 7 19:31:24 2000 --- mpeg2_movie-1.3-avi/video/mpeg2enc.c Wed Jan 24 03:22:55 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)); *************** *** 57,63 **** " -1 generate an MPEG-1 stream instead of MPEG-2\n" " -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\n" "Default settings:\n" " fixed 5000000 bits/sec\n" " interlaced\n" --- 58,67 ---- " -1 generate an MPEG-1 stream instead of MPEG-2\n" " -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" ! " -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" *************** *** 262,267 **** --- 266,272 ---- M = 1; /* M (I/P frame distance) */ processors = 1; frame_rate = -1; + num_encode = 0; /* Get processor count */ if(proc = fopen("/proc/cpuinfo", "r")) *************** *** 362,367 **** --- 367,414 ---- } } 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; *************** *** 415,422 **** qt_file = quicktime_open(tplorg, 1, 0); inputtype = T_QUICKTIME; } ! if(!qt_file && !mpeg_file) { fprintf(stderr, "File format not recognized.\n"); exit(1); --- 462,474 ---- 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); *************** *** 452,463 **** 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 */ --- 504,523 ---- 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 */ *************** *** 501,516 **** if(mpeg1) prog_seq = 1; ! if(frame_rate < 0) { ! if(qt_file) ! { ! frame_rate = quicktime_frame_rate(qt_file, 0); ! } ! else ! if(mpeg_file) ! frame_rate = mpeg3_frame_rate(mpeg_file, 0); } //processors = 1; //nframes = 16; --- 561,579 ---- if(mpeg1) prog_seq = 1; ! ! if(qt_file) { ! frame_rate = quicktime_frame_rate(qt_file, 0); } + else if(mpeg_file) { + if(frame_rate < 0) + { + frame_rate = mpeg3_frame_rate(mpeg_file, 0); + } + } else { + frame_rate = avi_frame_rate(); + } //processors = 1; //nframes = 16; diff -r -c --new-file mpeg2_movie-1.3/video/mpeg2enc.h mpeg2_movie-1.3-avi/video/mpeg2enc.h *** mpeg2_movie-1.3/video/mpeg2enc.h Thu Dec 7 19:31:24 2000 --- mpeg2_movie-1.3-avi/video/mpeg2enc.h Thu Dec 28 20:47:22 2000 *************** *** 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.3/video/readpic.c mpeg2_movie-1.3-avi/video/readpic.c *** mpeg2_movie-1.3/video/readpic.c Thu Dec 7 19:31:24 2000 --- mpeg2_movie-1.3-avi/video/readpic.c Wed Jan 24 04:20:41 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