lavrec.c

来自「Motion JPEG编解码器源代码」· C语言 代码 · 共 1,166 行 · 第 1/3 页

C
1,166
字号
/* * lavrec - Linux Audio Video RECord * * Copyright (C) 2000 Rainer Johanni <Rainer@Johanni.de> * Extended by:     Gernot Ziegler  <gz@lysator.liu.se> *               &  Wolfgang Scherr <scherr@net4you.net> *               &  Ronald Bultje   <rbultje@ronald.bitfreak.net> *               &  many others * * A library for recording MJPEG video from hardware MJPEG * video devices such as the Pinnacle/Miro DC10(+), Iomega * Buz, the Linux Media Labs LML33, the Matrox Marvel G200, * Matrox Marvel G400 and the Rainbow Runner G-series. * Can also be used for video-capture from BTTV-devices * * Usage: lavrec [options] filename [filename ...] * where options are as follows: * *   -f/--format [aAqm] --- Output file format: *      'a': AVI (default) *      'A': AVI with fields exchanged *      'j': JPEG image(s) *      'q': quicktime (if compiled with quicktime support) *      Hint: If your AVI video looks strange, try 'A' instead 'a' *      and vice versa. *		  *   -i/--input [pPnNsStTa] --- Input Source: *      'p': PAL       Composite Input or first Bt8x8 input *      'P': PAL       SVHS-Input or second Bt8x8 input *      't': PAL       TV tuner input or third Bt8x8 input *      'n': NTSC      Composite Input or first Bt8x8 input *      'N': NTSC      SVHS-Input or second Bt8x8 input *      'T': NTSC      TV tuner input or third Bt8x8 input *      's': SECAM     Composite Input or first Bt8x8 input *      'S': SECAM     SVHS-Input or second Bt8x8 input *      'f': SECAM     TV tuner input or third Bt8x8 input *      'a': (or every other letter) Autosense (default) * *   -d/--decimation num --- Frame recording decimation: *      must be either 1, 2 or 4 for identical decimation *      in horizontal and vertical direction (mostly used) or a *      two digit letter with the first digit specifying horizontal *      decimation and the second digit specifying vertical decimation *      (more exotic usages). Not supported for BTTV. * *   -g/--geometry WxH+X+Y --- An X-style geometry string (capturing area): *      Even if a decimation > 1 is used, these values are always *      coordinates in the undecimated frame.   *                For DC10: 768/640x{576 or 480}. *                For others: 720x{576 or 480}. *      Also, unlike in X-Window, negative values for X and Y *      really mean negative offsets (if this feature is enabled *      in the driver) which lets you fine tune the position of the *      image caught. *      The horizontal resolution of the DECIMATED frame must *      allways be a multiple of 16, the vertical resolution *      of the DECIMATED frame must be a multiple of 16 for decimation 1 *      and a multiple of 8 for decimations 2 and 4 * *      If not offset (X and Y values) is given, the capture area *      is centered in the frame. * *      For BTTV-capuring (--software-encoding), X and Y are omitted *      and W and H are the video-capture-size (so decimation is omitted) *      too). BTTV does not support subframe-capture. * *   -q/--quality num --- quality: *      must be between 0 and 100, default is 50 * *   -t/--time num -- capturing time: *      Time to capture in seconds, default is unlimited *      (use ^C to stop capture!) * *   -S/--single-frame --- enables single-frame capturing mode * *   -T/--time-lapse num --- time-lapse mode: *      Time lapse factor: Video will be played back <num> times *      faster, audio is switched off. *      This means that only every <num>th frame is recorded. *      If num==1 it is silently ignored. * *   -w/--wait --- Wait for user confirmation to start * *   -B/--batch --- Batch mode recording.  Minimal error logging, no *      interaction, works when output is redirected to files. *      Intended for use when doing unattended script-controlled *      recording. * *   --software-encoding --- encode frames in software-mode: *      Mainly intended to make it possible to use lavrec with BTTV *      cards too. Should work for V4L-capture with zoran cards too *      but that's only for testing - you really don't want to use *      this option for zoran-devices since they have hardware-encoding *      possibilities * *   --max-file-size --- The maximum size (in MB) per video file *      Intended for those that would like to record video in MJPEG *      format and need a specific filesize limit, for example to be *      able to burn the video files to CD (650 MB). * *   --max-file-frames --- The maximum number of frames per video file *      Intended for those that would like to record video in MJPEG *      format and need a specific number of frames per file, for *      example to be able to perform easy file and frame number *      arithmetics when cutting video manually. * *   --file-flush  --- How often (in frames) the current output  *       file (if any) should be flushed to disk.  (default:60). *       Set to 0 if your chosen file-system and system tuning *       ensures you don't get lengthy periods of disk activity *       during which lavrec writing is held up. * **** Audio settings *** * *   -a/--audio-bitsize num --- audio bitsize: *      Audio size in bits, must be 0 (no audio), 8 or 16 (default) * *   -r/--audio_bitrate num --- audio-bitrate: *      Audio rate (in Hz), must be a permitted sampling rate for *      your soundcard. Default is 22050. * *   -s/--stereo --- enable stereo (disabled by default) * *   -l/--audio-volume num --- audio recording level/volume: *      Audio level to use for recording, must be between 0 and 100 *      or -1 (for not touching the mixer settings at all), default *      is 100. * *   -m/--mute --- mute output during recording: *      Mute audio output during recording (default is to let it enabled). *      This is particularly usefull if you are recording with a *      microphone to avoid feedback. * *   -R/--audio-source [lmc] --- Audio recording source: *      'l': line-in *      'm': microphone *      'c': cdrom *      '1': line1 *      '2': line2 *      '3': line3 * **** Audio/Video synchronization *** * *   -c/--synchronization num --- Level of corrections for synchronization: *      0: Neither try to replicate lost frames nor any sync correction *      1: Replicate frames for lost frames, but no sync correction *      2. lost frames replication + sync correction * **** Special capture settings *** * *   -n/--mjpeg-buffers num --- Number of MJPEG capture buffers (default 64) * *   -b/--mjpeg-buffer-size num --- Size of MJPEG buffers in KB (default 256) * **** Environment variables *** * * Recognized environment variables: *    LAV_VIDEO_DEV: Name of video device (default: "/dev/video") *    LAV_AUDIO_DEV: Name of audio device (default: "/dev/dsp") *    LAV_MIXER_DEV: Name of mixer device (default: "/dev/mixer") * * To overcome the AVI (and linux-2.2 ext2fs) 2 GB filesize limit, you can: *   - give multiple filenames on the command-line *   - give one filename which contains a '%' sign. This name is then *     interpreted as the format argument to sprintf() to form multiple *     file names * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "liblavrec.h"#include "mjpeg_logging.h"#include <mpegtimecode.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <termios.h>#include <sys/fsuid.h>#include <signal.h>#include <fcntl.h>#include <errno.h>#include <sys/stat.h>#ifdef HAVE_GETOPT_H#include <getopt.h>#endif#include <string.h>#include <pthread.h>#include <semaphore.h>static lavrec_t *info;static int num_frames, num_lost, num_ins, num_del, num_aerr;static int show_stats = 0;static int state;static sem_t state_changed;static int verbose = 0;static int wait_for_start = 0;static int batch_mode = 0;static char input_source;static pthread_t signal_thread;static void Usage(char *progname){	fprintf(stderr, "lavtools version " VERSION ": lavrec\n");	fprintf(stderr, "Usage: %s [options] <filename> [<filename> ...]\n", progname);	fprintf(stderr, "where options are:\n");	fprintf(stderr, "  -f/--format [aAj"#ifdef HAVE_LIBQUICKTIME           "q"#else           ""#endif           "]         Format AVI/Quicktime\n");	fprintf(stderr, "  -i/--input [pPnNsStTfa]     Input Source\n");	fprintf(stderr, "  -d/--decimation num         Decimation (either 1,2,4 or two digit number)\n");	fprintf(stderr, "  -g/--geometry WxH+X+Y       X-style geometry string (part of 768/720x576/480)\n");	fprintf(stderr, "  -q/--quality num            Quality [%%]\n");	fprintf(stderr, "  -t/--time num               Capture time (default: unlimited - Ctrl-C to stop\n");	fprintf(stderr, "  -S/--single-frame           Single frame capture mode\n");	fprintf(stderr, "  -T/--time-lapse num         Time lapse, capture only every <num>th frame\n");	fprintf(stderr, "  -w/--wait                   Wait for user confirmation to start\n");	fprintf(stderr, "  -B/--batch                  Batch mode for recording non-interactively\n");	fprintf(stderr, "  -a/--audio-bitsize num      Audio size, 0 for no audio, 8 or 16\n");	fprintf(stderr, "  -r/--audio-bitrate num      Audio rate [Hz]\n");	fprintf(stderr, "  -s/--stereo                 Stereo (default: mono)\n");	fprintf(stderr, "  -l/--audio-volume num       Recording level [%%], -1 for mixers not touched\n");	fprintf(stderr, "  -m/--mute                   Mute audio output during recording\n");	fprintf(stderr, "  -R/--audio-source [lmc123]  Set recording source: (l)ine, (m)icro, (c)d,\n");	fprintf(stderr, "                              line(1), line(2), line(3\n");	fprintf(stderr, "  -c/--synchronization [012]  Level of corrections for synchronization\n");	fprintf(stderr, "  -n/--mjpeg-buffers num      Number of MJPEG buffers (default: 64)\n");	fprintf(stderr, "  -b/--mjpeg-buffer-size num  Size of MJPEG buffers [Kb] (default: 256)\n");	fprintf(stderr, "  -C/--channel LIST:CHAN      When using a TV tuner, channel list/number\n");	fprintf(stderr, "  -F/--frequency KHz          When using a TV tuner, frequency in KHz\n");	fprintf(stderr, "  -U/--use-read               Use read instead of mmap for recording\n");	fprintf(stderr, "  --software-encoding         Use software JPEG-encoding (for BTTV-capture)\n");	fprintf(stderr, "  --num-procs num             Number of encoding processes (default: 1)\n");	fprintf(stderr, "  --max-file-size num         Maximum size per file (in MB)\n");	fprintf(stderr, "  --max-file-frames num       Maximum number of frames per file\n");	fprintf(stderr, "  --file-flush num            Flush capture file to disk every num frames\n");	fprintf(stderr, "  -v/--verbose [012]          verbose level (default: 0)\n");	fprintf(stderr, "Environment variables recognized:\n");	fprintf(stderr, "   LAV_VIDEO_DEV, LAV_AUDIO_DEV, LAV_MIXER_DEV\n");	exit(1);}/* RJ: The following stuff thanks to Philipp Zabel: *//* pH5 - the following was stolen from glut (that stole the code from X):   *//*  * Bitmask returned by XParseGeometry().  Each bit tells if the corresponding * value (x, y, width, height) was found in the parsed string. */#define NoValue         0x0000#define XValue          0x0001#define YValue          0x0002#define WidthValue      0x0004#define HeightValue     0x0008#define AllValues       0x000F#define XNegative       0x0010#define YNegative       0x0020/* the following function was stolen from the X sources as indicated. *//* Copyright 	Massachusetts Institute of Technology  1985, 1986, 1987 *//* $XConsortium: XParseGeom.c,v 11.18 91/02/21 17:23:05 rws Exp $ *//*Permission to use, copy, modify, distribute, and sell this software and itsdocumentation for any purpose is hereby granted without fee, provided thatthe above copyright notice appear in all copies and that both thatcopyright notice and this permission notice appear in supportingdocumentation, and that the name of M.I.T. not be used in advertising orpublicity pertaining to distribution of the software without specific,written prior permission.  M.I.T. makes no representations about thesuitability of this software for any purpose.  It is provided "as is"without express or implied warranty.*//* *    XParseGeometry parses strings of the form *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where *   width, height, xoffset, and yoffset are unsigned integers. *   Example:  "=80x24+300-49" *   The equal sign is optional. *   It returns a bitmask that indicates which of the four values *   were actually found in the string.  For each value found, *   the corresponding argument is updated;  for each value *   not found, the corresponding argument is left unchanged.  */static intReadInteger(char *string, char **NextString){    register int Result = 0;    int Sign = 1;        if (*string == '+')		string++;    else if (*string == '-')    {		string++;		Sign = -1;    }    for (; (*string >= '0') && (*string <= '9'); string++)    {		Result = (Result * 10) + (*string - '0');    }    *NextString = string;    if (Sign >= 0)		return (Result);    else		return (-Result);}static int XParseGeometry(char *string, int *x, int *y, unsigned int *width, unsigned int *height){	int mask = NoValue;	register char *strind;	unsigned int tempWidth, tempHeight;	int tempX, tempY;	char *nextCharacter;	if ( (string == NULL) || (*string == '\0')) return(mask);	if (*string == '=')		string++;  /* ignore possible '=' at beg of geometry spec */	strind = (char *)string;	tempWidth = 0;	if (*strind != '+' && *strind != '-' && *strind != 'x') {		tempWidth = ReadInteger(strind, &nextCharacter);		if (strind == nextCharacter) 		    return (0);		strind = nextCharacter;		mask |= WidthValue;	}	tempHeight = 0;	if (*strind == 'x' || *strind == 'X') {			strind++;		tempHeight = ReadInteger(strind, &nextCharacter);		if (strind == nextCharacter)		    return (0);		strind = nextCharacter;		mask |= HeightValue;	}	tempX = tempY = 0;	if ((*strind == '+') || (*strind == '-')) {		if (*strind == '-') {  			strind++;			tempX = -ReadInteger(strind, &nextCharacter);			if (strind == nextCharacter)			    return (0);			strind = nextCharacter;			mask |= XNegative;		}		else		{	strind++;		tempX = ReadInteger(strind, &nextCharacter);		if (strind == nextCharacter)			return(0);		strind = nextCharacter;		}		mask |= XValue;		if ((*strind == '+') || (*strind == '-')) {			if (*strind == '-') {				strind++;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?