?? avi2mpg1.c
字號:
//
// avi2mpg1 -
// 產生編碼器的命令行窗口,即是avi2mpg1的主函數
//
#include <stdio.h>
#include <math.h>
#include "avi2mpg1.h"
#define GLOBAL
#include "global.h"
#include "video.h"
//函數聲明
void usage(void);
int ValidBitrate(unsigned int, unsigned int);
void StripExtension(char *, char *);
void StripPath(char *, char *);
int mplex(char *, char *, char *);
void videocd();
unsigned int pixsz;
int main(int argc, char **argv)
{
int i=0,j=0, err=0;
char avifilenames[MAX_AVI_FILES][_MAX_PATH], basefilename[_MAX_FNAME] = "", mpegfilename[_MAX_PATH] = "";
char VideoTempFile[_MAX_FNAME] = "", AudioTempFile[_MAX_FNAME] = "", basepathname[_MAX_PATH];
char testfilename[_MAX_PATH] = "", intfilename[_MAX_FNAME];
AVIFILEINFO thisPfi;
float fps;
int sys_bit_specd = 0, sys_byte_specd = 0;
PAVISTREAM pVideoStream;
time_t current_time, el_time;
bad_frame_count = 0;
bad_audio_count = 0;
numAviFiles = 0;
vbv_size = 20;
m_search_size = 0;
crop_size = 0;
forced_frame_rate = 0;
cpu_MMX = 0;
cpu_3DNow = 0;
if(argc < 2)
{
usage();
}
TestCPU();
system_byterate_parm = 150;
audio_bitrate_parm = 128;
audio_layer_parm = 2;
joint_stereo_parm = 0;
vcd_parm = 0;
fake_bad_frames = 0;
video_only = 0;
use_image_noise_reduction = 0;
fastQuantization = 0;
fastMotionCompensationLevel = 0;
if (cpu_MMX)
doublePrecision = 0;
else
doublePrecision = 1;
while((++i < argc)&&(err == 0))
{
char c, *token, *arg, *nextArg, *nextArg2;
int argUsed;
token = argv[i];
if(*token++ == '-')
{
if(i+1 < argc)
nextArg = argv[i+1];
else
nextArg = "";
argUsed = 0;
while(c = *token++)
{
if(*token /* NumericQ(token) */)
arg = token;
else
arg = nextArg;
switch(tolower(c))
{
case 'l':
audio_layer_parm = atoi(arg);
argUsed = 1;
if((audio_layer_parm < 1)||(audio_layer_parm > 2))
{
fprintf(stderr,"\n-l layer must be 1 or 2, not %s\n", arg);
err = 1;
}
break;
case 'b':
argUsed = 1;
system_byterate_parm = atoi(arg);
sys_byte_specd = 1;
if(sys_bit_specd)
{
fprintf(stderr, "\n can not specify both -b and -s!\n");
err = 1;
}
if((system_byterate_parm < 10)||(system_byterate_parm > 5000))
{
fprintf(stderr,
"\n-b system byterate (K bytes/s) must be from 10 to 5000, not %s\n", arg);
err = 1;
}
break;
case 's':
argUsed = 1;
system_byterate_parm = atoi(arg)/8;
sys_bit_specd = 1;
if(sys_byte_specd)
{
fprintf(stderr, "\n can not specify both -b and -s!\n");
err = 1;
}
if((system_byterate_parm < 10)||(atoi(arg) > 40000))
{
fprintf(stderr, "\n-s system bitrate (K bits/s) must be from 80 to 40000, not %s\n", arg);
err = 1;
}
break;
case 'a':
argUsed = 1;
audio_bitrate_parm = atoi(arg);
break;
case 'r':
use_image_noise_reduction = 1;
break;
case 'j':
joint_stereo_parm = 1;
break;
case 'v':
//vcd_parm = 1;
videocd();
break;
case 'p':
argUsed = 1;
strcpy(video_param_filename, arg);
use_v_param_file = 1;
break;
case 'e':
fake_bad_frames = 1;
break;
case 'n':
video_only = 1;
break;
case 'y':
argUsed = 1;
vbv_size = atoi(arg);
if(vbv_size < 1)
{
fprintf(stderr, "\n vbv_buffer_size must be in range 1 <-> 1023.\n");
err = 1;
}
break;
case 'm':
argUsed = 1;
m_search_size = atoi(arg);
if((m_search_size < 0 )||(m_search_size > 4))
{
fprintf(stderr, "\n -m search option must be from 0 to 4!\n");
err = 1;
}
break;
case 'c':
if(i+2 < argc)
{
nextArg2 = argv[i+2];
i++;
}
else
nextArg2 = "";
crop_size = 1;
argUsed =1;
crop_horz = atoi(arg);
if((crop_horz < 16)||(crop_horz>4095))
{
fprintf(stderr, "\n -c horizontal size must be from 16 to 4095!\n");
err = 1;
}
crop_vert = atoi(nextArg2);
if((crop_vert < 16)||(crop_vert>4095))
{
fprintf(stderr, "\n -c vertical size must be from 16 to 4095!\n");
err=1;
}
break;
case 'f':
argUsed = 1;
forced_frame_rate = atoi(arg);
if((forced_frame_rate < 1)||(forced_frame_rate > 5))
{
fprintf(stderr, "\n -f frame rate code must be from 1 to 5!\n");
err=1;
}
break;
case 'x':
cpu_MMX = 0;
cpu_3DNow = 0;
doublePrecision = 1;
break;
case 'd':
doublePrecision = 1;
break;
case 'q':
fastQuantization = 1;
break;
case 't':
argUsed = 1;
fastMotionCompensationLevel = atoi(arg);
if(fastMotionCompensationLevel < 0 || fastMotionCompensationLevel > 3)
{
fprintf(stderr, "\n -t level must be from 0 to 3!\n");
err = 1;
}
break;
case 'h':
argUsed = 1;
wr_seqh2gop = atoi(arg);
break;
default:
fprintf(stderr,"\nunrecognized option %c\n", c);
err = 1;
break;
}
if(argUsed)
{
if(arg == token)
token = "";
else
++i;
arg = ""; argUsed = 0;
}
}
}
else
{
if((i != argc-1) || (numAviFiles==0))
{
if (numAviFiles < MAX_AVI_FILES)
strcpy(avifilenames[numAviFiles++], argv[i]);
else
usage();
}
else
strcpy(mpegfilename, argv[i]);
}
}
if (cpu_MMX)
printf("MMX capable CPU detected, using MMX extensions.\n");
if (cpu_3DNow)
printf("3DNow! capable CPU detected, using 3DNow! extensions.\n");
if(vcd_parm)
{
system_byterate_parm = 1158000/8/1024;
audio_bitrate_parm = 224;
audio_layer_parm = 2;
joint_stereo_parm = 0;
}
if(!ValidBitrate(audio_layer_parm, audio_bitrate_parm))
{
fprintf(stderr, "\n-a bitrate %i not legal for layer %i",
audio_bitrate_parm, audio_layer_parm);
err = 1;
}
if(vcd_parm&&video_only)
{
fprintf(stderr, "\n can not specify both -v and -n!\n");
err = 1;
}
if(vcd_parm&&forced_frame_rate)
{
fprintf(stderr, "\n can not specify both -v and -f!\n");
err = 1;
}
if(forced_frame_rate)
video_only = 1;
if(err)
{
fprintf(stderr, "\n type avi2mpg1 <enter> for usage.\n");
exit(6);
}
if(numAviFiles == 0)
usage();
AVIFileInit();
for(j=0;j<numAviFiles;j++)
{
StripExtension(basepathname, avifilenames[j]);
if(strlen(avifilenames[j]) == strlen(basepathname))
strcat(avifilenames[j], ".avi");
hResult = AVIFileOpen(&pfile, avifilenames[j], OF_READ, 0L);
if(hResult)
{
fprintf(stderr, "\ncould not open filename %s!\n",
avifilenames[j]);
exit(7);
}
hResult = AVIFileInfo(pfile, &thisPfi, sizeof(AVIFILEINFO));
if(hResult)
{
fprintf(stderr, "\n%s does not appear to be an AVI file!\n",
avifilenames[j]);
exit(8);
}
if (j==0)
masterPfi=thisPfi;
hResult = AVIFileGetStream(pfile, &pVideoStream, streamtypeVIDEO, 0);
if(hResult)
{
fprintf(stderr, "\ncould not retrieve video stream from %s!\n",
avifilenames[j]);
exit(31);
}
pget[j] = AVIStreamGetFrameOpen(pVideoStream, NULL);
fps = (float)thisPfi.dwRate/(float)thisPfi.dwScale;
fprintf(stderr, "%s file details:\nWidth = %u, Height = %u, FPS = %4.2f",
avifilenames[j], thisPfi.dwWidth, thisPfi.dwHeight, fps);
lpbi = AVIStreamGetFrame(pget[j], 0);
if(!lpbi)
{
fprintf(stderr, "\ncould not retrieve video details for %s!",avifilenames[j]);
fprintf(stderr, "\nyou probably do not have a codec for this compression scheme!");
fprintf(stderr, "\nor avi file may be corrupt!\n");
exit(9);
}
last_good_video_frame = 0;
pixsz = lpbi->biBitCount;
if((pixsz!=8)&&(pixsz!=16)&&(pixsz!=24)&&(pixsz!=32))
{
fprintf(stderr, "\ncan only handle 8 bit palletized, 16, 24, or 32 bit RGB video!,");
fprintf(stderr, "\nthis file is %i bits!\n", pixsz);
exit(10);
}
fprintf(stderr, ", Bits per pixel = %u", pixsz);
if (j==0)
{
if(thisPfi.dwWidth>4095)
{
fprintf(stderr, "\nHorizontal width must < 4096!");
err = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -