⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpeg2yuv.c

📁 Motion JPEG编解码器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*jpeg2yuv========  Converts a collection of JPEG images to a YUV4MPEG stream.  (see jpeg2yuv -h for help (or have a look at the function "usage"))    Copyright (C) 1999 Gernot Ziegler (gz@lysator.liu.se)  Copyright (C) 2001 Matthew Marjanovic (maddog@mir.com)  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.*/#include <config.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <errno.h>#include <jpeglib.h>#include "jpegutils.h"#include "lav_io.h"#include <sys/types.h>#include "mjpeg_logging.h"#include "mjpeg_types.h"#include "yuv4mpeg.h"#include "mpegconsts.h"#define MAXPIXELS (1280*1024)  /* Maximum size of final image */typedef struct _parameters {  char *jpegformatstr;  uint32_t begin;       /* the video frame start */  int32_t numframes;   /* -1 means: take all frames */  y4m_ratio_t framerate;  y4m_ratio_t aspect_ratio;  int interlace;   /* will the YUV4MPEG stream be interlaced? */  int interleave;  /* are the JPEG frames field-interleaved? */  int verbose; /* the verbosity of the program (see mjpeg_logging.h) */  int width;  int height;  int colorspace;  int loop;  int rescale_YUV;} parameters_t;static struct jpeg_decompress_struct dinfo;static struct jpeg_error_mgr jerr;/* * The User Interface parts  *//* usage * Prints a short description of the program, including default values  * in: prog: The name of the program  */static void usage(char *prog){  char *h;    if (NULL != (h = (char *)strrchr(prog,'/')))    prog = h+1;    fprintf(stderr, 	  "usage: %s [ options ]\n"	  "\n"	  "where options are ([] shows the defaults):\n"	  "  -l num        loop -1=forever, n >= 1 n-times       \n"	  "  -v num        verbosity (0,1,2)                  [1]\n"	  "  -b framenum   starting frame number              [0]\n"	  "  -f framerate  framerate for output stream (fps)     \n"          "  -A sar        output sample aspect ratio         [1:1]\n" 	  "  -n numframes  number of frames to process        [-1 = all]\n"	  "  -j {1}%%{2}d{3} Read JPEG frames with the name components as follows:\n"	  "               {1} JPEG filename prefix (e g rendered_ )\n"	  "               {2} Counting placeholder (like in C, printf, eg 06 ))\n"	  "  -I x  interlacing mode:  p = none/progressive\n"	  "                           t = top-field-first\n"	  "                           b = bottom-field-first\n"	  "  -L x  interleaving mode:  0 = non-interleaved (two successive\n"	  "                                 fields per JPEG file)\n"	  "                            1 = interleaved fields\n"	  "  -R 1/0 ... 1: rescale YUV color values from 0-255 to 16-235 (default: 1)\n"	  "\n"	  "%s pipes a sequence of JPEG files to stdout,\n"	  "making the direct encoding of MPEG files possible under mpeg2enc.\n"	  "Any JPEG format supported by libjpeg can be read.\n"	  "stdout will be filled with the YUV4MPEG movie data stream,\n"	  "so be prepared to pipe it on to mpeg2enc or to write it into a file.\n"	  "\n"	  "\n"	  "examples:\n"	  "  %s -j in_%%06d.jpeg -b 100000 > result.yuv\n"	  "  | combines all the available JPEGs that match \n"	  "    in_??????.jpeg, starting with 100000 (in_100000.jpeg, \n"	  "    in_100001.jpeg, etc...) into the uncompressed YUV4MPEG videofile result.yuv\n"	  "  %s -It -L0 -j abc_%%04d.jpeg | mpeg2enc -f3 -o out.m2v\n"	  "  | combines all the available JPEGs that match \n"	  "    abc_??????.jpeg, starting with 0000 (abc_0000.jpeg, \n"	  "    abc_0001.jpeg, etc...) and pipes it to mpeg2enc which encodes\n"	  "    an MPEG2-file called out.m2v out of it\n"	  "\n",	  prog, prog, prog, prog);}/* parse_commandline * Parses the commandline for the supplied parameters. * in: argc, argv: the classic commandline parameters */static void parse_commandline(int argc, char ** argv, parameters_t *param){  int c, sts;    param->jpegformatstr = NULL;  param->begin = 0;  param->numframes = -1;  param->framerate = y4m_fps_UNKNOWN;  param->interlace = Y4M_UNKNOWN;  param->aspect_ratio = y4m_sar_SQUARE;  param->interleave = -1;  param->verbose = 1;  param->loop = 1;  param->rescale_YUV = 1;  /* parse options */  for (;;) {    if (-1 == (c = getopt(argc, argv, "I:hv:L:b:j:n:f:l:R:A:")))      break;    switch (c) {    case 'A':      sts = y4m_parse_ratio(&param->aspect_ratio, optarg);      if (sts != Y4M_OK)         mjpeg_error_exit1("Invalid aspect ratio: %s", optarg);      break;    case 'j':      param->jpegformatstr = strdup(optarg);      break;    case 'b':      param->begin = atol(optarg);      break;    case 'n':      param->numframes = atol(optarg);      break;    case 'R':      param->rescale_YUV = atoi(optarg);      break;    case 'f':      param->framerate = mpeg_conform_framerate(atof(optarg));      break;    case 'I':      switch (optarg[0]) 	{	case 'p':	  param->interlace = Y4M_ILACE_NONE;	  break;	case 't':	  param->interlace = Y4M_ILACE_TOP_FIRST;	  break;	case 'b':	  param->interlace = Y4M_ILACE_BOTTOM_FIRST;	  break;	default:	  mjpeg_error_exit1 ("-I option requires arg p, t, or b");	}      break;    case 'L':      param->interleave = atoi(optarg);      if ((param->interleave != 0) &&	  (param->interleave != 1)) 	mjpeg_error_exit1 ("-L option requires arg 0 or 1");      break;    case 'v':      param->verbose = atoi(optarg);      if (param->verbose < 0 || param->verbose > 2) 	mjpeg_error_exit1( "-v option requires arg 0, 1, or 2");          break;         case 'l':      param->loop = atoi(optarg);      if  (param->loop == 0 || param->loop < -1 ) 	mjpeg_error_exit1( "-l option requires a number greater than 0 or -1 to loop forever ");          break;         case 'h':    default:      mjpeg_info("Wp x, char %c\n", c);      usage(argv[0]);      exit(1);    }  }  if (param->jpegformatstr == NULL) {     mjpeg_error("%s:  input format string not specified. (Use -j option.)",		argv[0]);     usage(argv[0]);     exit(1);  }  if (Y4M_RATIO_EQL(param->framerate, y4m_fps_UNKNOWN)) {    mjpeg_error("%s:  framerate not specified.  (Use -f option)",		argv[0]);     usage(argv[0]);     exit(1);  }}/* * The file handling parts  *//** init_parse_files * Verifies the JPEG input files and prepares YUV4MPEG header information. * @returns 0 on success */static int init_parse_files(parameters_t *param){   char jpegname[255];  FILE *jpegfile;    snprintf(jpegname, sizeof(jpegname), 	   param->jpegformatstr, param->begin);  mjpeg_debug("Analyzing %s to get the right pic params", jpegname);  jpegfile = fopen(jpegname, "rb");    if (jpegfile == NULL)    mjpeg_error_exit1("System error while opening: \"%s\": %s",		      jpegname, strerror(errno));  /* Now open this JPEG file, and examine its header to retrieve the      YUV4MPEG info that shall be written */  dinfo.err = jpeg_std_error(&jerr);  /* ?????????? */  jpeg_create_decompress(&dinfo);  jpeg_stdio_src(&dinfo, jpegfile);

⌨️ 快捷键说明

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