lavrec.c
来自「Motion JPEG编解码器源代码」· C语言 代码 · 共 1,166 行 · 第 1/3 页
C
1,166 行
tempY = -ReadInteger(strind, &nextCharacter); if (strind == nextCharacter) return(0); strind = nextCharacter; mask |= YNegative; } else { strind++; tempY = ReadInteger(strind, &nextCharacter); if (strind == nextCharacter) return(0); strind = nextCharacter; } mask |= YValue; } } /* If strind isn't at the end of the string the it's an invalid geometry specification. */ if (*strind != '\0') return (0); if (mask & XValue) *x = tempX; if (mask & YValue) *y = tempY; if (mask & WidthValue) *width = tempWidth; if (mask & HeightValue) *height = tempHeight; return (mask);}/* =========================================================================== Parse the X-style geometry string*/static int parse_geometry (char *geom, int *x, int *y, unsigned int *width, unsigned int *height){ return XParseGeometry (geom, x, y, width, height);}static void input(int type, char *message){ switch (type) { case LAVREC_MSG_ERROR: mjpeg_error("%s", message); break; case LAVREC_MSG_WARNING: mjpeg_warn("%s", message); break; case LAVREC_MSG_INFO: mjpeg_info("%s", message); break; case LAVREC_MSG_DEBUG: mjpeg_debug("%s", message); break; }}static void *user_input_thread (void * arg){ fd_set rfds; struct timeval timeout; char input_buffer[256]; if (state == LAVREC_STATE_PAUSED) { printf("Press enter to start recording>"); fflush(stdout); } while (state != LAVREC_STATE_STOP) { pthread_testcancel(); /* wait for input */ FD_ZERO(&rfds); FD_SET(0, &rfds); timeout.tv_sec = 0; timeout.tv_usec = 500000; if (select(1, &rfds, 0, 0, &timeout) == 0) continue; /* input timeout */ read(0, input_buffer, sizeof(input_buffer)); switch (state) { case LAVREC_STATE_PAUSED: lavrec_start(info); printf("Press enter to pause recording\n"); break; case LAVREC_STATE_RECORDING: lavrec_pause(info); printf("Press enter to start recording>"); fflush(stdout); break; } } return 0;}static void statechanged(int new){ show_stats = (new == LAVREC_STATE_RECORDING); state = new; sem_post(&state_changed);}#if 0static void batch_stats(video_capture_stats *stats){ MPEG_timecode_t tc; static int first_stats = 1; static video_capture_stats prev_stats; return; if( first_stats ) { first_stats = 0; prev_stats = *stats; return; } if( stats->num_lost == prev_stats.num_lost && stats->num_ins == prev_stats.num_ins && stats->num_del == prev_stats.num_del && stats->num_aerr == prev_stats.num_aerr ) { return; } prev_stats = *stats; mpeg_timecode(&tc, stats->num_frames, ((info->video_norm!=1)? 3: 4), ((info->video_norm!=1)? 25.: 30000./1001.)); fprintf(stdout, "%2d.%2.2d.%2.2d:%2.2d int: %05ld lst:%4d ins:%3d del:%3d " "ae:%3d td1=%.3f td2=%.3f\n", tc.h, tc.m, tc.s, tc.f, (stats->cur_sync.tv_usec - stats->prev_sync.tv_usec)/1000, stats->num_lost, stats->num_ins, stats->num_del, stats->num_aerr, stats->tdiff1, stats->tdiff2); fflush(stdout);}#endifstatic void output_stats(video_capture_stats *stats){ num_frames = stats->num_frames; num_lost = stats->num_lost; num_ins = stats->num_ins; num_del = stats->num_del; num_aerr = stats->num_aerr; if (show_stats > 0 && !batch_mode) { MPEG_timecode_t tc; mpeg_timecode(&tc, stats->num_frames, ((info->video_norm!=1)? 3: 4), ((info->video_norm!=1)? 25.: 30000./1001.)); if( stats->prev_sync.tv_usec > stats->cur_sync.tv_usec ) stats->prev_sync.tv_usec -= 1000000; if (info->single_frame) printf("%06d frames captured, press enter for more>", stats->num_frames); else { printf( "%d.%2.2d.%2.2d:%2.2d int:%03ld lst:%3d ins:%3d del:%3d " "ae:%3d td1=%.3f td2=%.3f\r", tc.h, tc.m, tc.s, tc.f, (stats->cur_sync.tv_usec - stats->prev_sync.tv_usec)/1000, stats->num_lost, stats->num_ins, stats->num_del, stats->num_aerr, stats->tdiff1, stats->tdiff2); if(verbose) printf("\n"); // Keep lines from overlapping } fflush(stdout); }}static int set_option(const char *name, char *value){ /* return 1 means error, return 0 means okay */ int nerr = 0; if (strcmp(name, "format")==0 || strcmp(name, "f")==0) { info->video_format = value[0]; if(value[0]!='a' && value[0]!='A' && value[0]!='j'#ifdef HAVE_LIBQUICKTIME && value[0]!='q'#endif ) {#ifdef HAVE_LIBQUICKTIME mjpeg_error("Format (-f/--format) must be j, a, A or q");#else mjpeg_error("Format (-f/--format) must be j, a or A");#endif nerr++; } } else if (strcmp(name, "input")==0 || strcmp(name, "i")==0) { switch(value[0]) { case 'p': info->video_norm = 0 /* PAL */; info->video_src = 0 /* composite */; break; case 'P': info->video_norm = 0 /* PAL */; info->video_src = 1 /* S-Video */; break; case 'n': info->video_norm = 1 /* NTSC */; info->video_src = 0 /* composite */; break; case 'N': info->video_norm = 1 /* NTSC */; info->video_src = 1 /* S-Video */; break; case 's': info->video_norm = 2 /* SECAM */; info->video_src = 0 /* composite */; break; case 'S': info->video_norm = 2 /* SECAM */; info->video_src = 1 /* S-Video */; break; case 't': info->video_norm = 0 /* PAL */; info->video_src = 2 /* TV-tuner */; break; case 'T': info->video_norm = 1 /* NTSC */; info->video_src = 2 /* TV-tuner */; break; case 'f': info->video_norm = 2 /* SECAM */; info->video_src = 2 /* TV-tuner */; break; default: info->video_norm = 3 /* auto */; info->video_src = 3 /* auto */; break; } input_source = value[0]; } else if (strcmp(name, "decimation")==0 || strcmp(name, "d")==0) { int i = atoi(value); if(i<10) { info->horizontal_decimation = info->vertical_decimation = i; } else { info->horizontal_decimation = i/10; info->vertical_decimation = i%10; } if( (info->horizontal_decimation != 1 && info->horizontal_decimation != 2 && info->horizontal_decimation != 4) || (info->vertical_decimation != 1 && info->vertical_decimation != 2 && info->vertical_decimation != 4) ) { mjpeg_error("decimation (-d/--decimation) = %d invalid",i); mjpeg_error(" must be one of 1,2,4,11,12,14,21,22,24,41,42,44"); nerr++; } } else if (strcmp(name, "verbose")==0 || strcmp(name, "v")==0) { verbose = atoi(value); } else if (strcmp(name, "quality")==0 || strcmp(name, "q")==0) { info->quality = atoi(value); if(info->quality<0 || info->quality>100) { mjpeg_error("quality (-q/--quality) = %d invalid (must be 0 ... 100)",info->quality); nerr++; } } else if (strcmp(name, "geometry")==0 || strcmp(name, "g")==0) { parse_geometry (value, &info->geometry->x, &info->geometry->y, &info->geometry->w, &info->geometry->h); } else if (strcmp(name, "time")==0 || strcmp(name, "t")==0) { info->record_time = atoi(value); if(info->record_time<=0) { mjpeg_error("record_time (-t/--time) = %d invalid",info->record_time); nerr++; } } else if (strcmp(name, "batch")==0 || strcmp(name, "B")==0) { batch_mode = 1; } else if (strcmp(name, "single-frame")==0 || strcmp(name, "S")==0) { info->single_frame = 1; } else if (strcmp(name, "use-read")==0 || strcmp(name, "U")==0) { info->use_read = 1; } else if (strcmp(name, "time-lapse")==0 || strcmp(name, "T")==0) { info->time_lapse = atoi(value); if(info->time_lapse<=1) info->time_lapse = 1; } else if (strcmp(name, "wait")==0 || strcmp(name, "w")==0) { wait_for_start = 1; } else if (strcmp(name, "audio-bitsize")==0 || strcmp(name, "a")==0) { info->audio_size = atoi(value); if(info->audio_size != 0 && info->audio_size != 8 && info->audio_size != 16) { mjpeg_error("audio_size (-a/--audio-bitsize) =" " %d invalid (must be 0, 8 or 16)", info->audio_size); nerr++; } } else if (strcmp(name, "audio-bitrate")==0 || strcmp(name, "r")==0) { info->audio_rate = atoi(value); if(info->audio_rate<=0) { mjpeg_error("audio_rate (-r/--audio-bitrate) = %d invalid",info->audio_rate); nerr++; } } else if (strcmp(name, "stereo")==0 || strcmp(name, "s")==0) { info->stereo = 1; } else if (strcmp(name, "audio-volume")==0 || strcmp(name, "l")==0) { info->audio_level = atoi(value); if(info->audio_level<-1 || info->audio_level>100) { mjpeg_error("recording level (-l/--audio-volume)" " = %d invalid (must be 0 ... 100 or -1)", info->audio_level); nerr++; } } else if (strcmp(name, "mute")==0 || strcmp(name, "m")==0) { info->mute = 1; } else if (strcmp(name, "audio-source")==0 || strcmp(name, "R")==0) { info->audio_src = value[0]; if(info->audio_src!='l' && info->audio_src!='m' && info->audio_src!='c' && info->audio_src!='1'&& info->audio_src!='2'&& info->audio_src!='3') { mjpeg_error("Recording source (-R/--audio-source)" " must be l,m,c,1,2, or 3\n"); nerr++; } } else if (strcmp(name, "synchronization")==0 || strcmp(name, "c")==0) { info->sync_correction = atoi(value); if(info->sync_correction<0 || info->sync_correction>2) { mjpeg_error("Synchronization (-c/--synchronization) =" " %d invalid (must be 0, 1 or 2)", info->sync_correction); nerr++; } } else if (strcmp(name, "mjpeg-buffers")==0 || strcmp(name, "n")==0) { info->MJPG_numbufs = atoi(value); } else if (strcmp(name, "mjpeg-buffer-size")==0 || strcmp(name, "b")==0) { info->MJPG_bufsize = atoi(value); } else if (strcmp(name, "frequency")==0 || strcmp(name,"F")==0) { info->tuner_frequency = atoi(value); } else if (strcmp(name, "channel")==0 || strcmp(name,"C")==0) { int colin=0; int chlist=0; int chan=0; /* First look for the colon mark */ while ( value[colin] && value[colin]!=':') colin++; if (value[colin]==0) /* didn't find the colin */ { mjpeg_error("malformed channel parameter (-C/--channel) - example: -C europe-west:SE20"); nerr++; } if (nerr==0) /* Now search for the given channel list in frequencies.c */ while (strncmp(chanlists[chlist].name,value,colin)!=0) { chlist++; /* madmac debug: printf("Searching for channel list: chlist = %d, value=%s\n", chlist, value); */ if (chanlists[chlist].name==NULL) { mjpeg_error("bad frequency map"); nerr++; break; /* bail out */ } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?