vf_zrmjpeg.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,069 行 · 第 1/3 页
C
1,069 行
if (priv->vdec == 2) { priv->fields = 1; } else if (priv->vdec == 4) { priv->fields = 1; stretchy = 2; } if (priv->hdec > maxstretchx) { if (priv->fd) { WARNING("horizontal decimation too high, " "changing to %d (use fd to keep" " hdec=%d)\n", maxstretchx, priv->hdec); priv->hdec = maxstretchx; } } stretchx = priv->hdec; } else if (d_width > priv->maxwidth/4 || height > priv->maxheight/4 || maxstretchx == 2) { stretchx = 2; stretchy = 1; priv->fields = 1; if (priv->vdec == 2) { stretchy = 2; } else if (priv->vdec == 4) { if (!priv->fd) { WARNING("vertical decimation too high, " "changing to 2 (use fd to keep " "vdec=4)\n"); priv->vdec = 2; } stretchy = 2; } if (priv->hdec == 2) { stretchx = 4; } else if (priv->hdec == 4) { if (priv->fd) { WARNING("horizontal decimation too high, " "changing to 2 (use fd to keep " "hdec=4)\n"); priv->hdec = 2; } stretchx = 4; } } else { /* output image is maximally stretched */ stretchx = 4; stretchy = 2; priv->fields = 1; if (priv->vdec != 1 && !priv->fd) { WARNING("vertical decimation too high, changing to 1 " "(use fd to keep vdec=%d)\n", priv->vdec); priv->vdec = 1; } if (priv->hdec != 1 && !priv->fd) { WARNING("horizontal decimation too high, changing to 1 (use fd to keep hdec=%d)\n", priv->hdec); priv->hdec = 1; } } VERBOSE("generated JPEG's %dx%s%d%s, stretched to %dx%d\n", width/priv->hdec, (priv->fields == 2) ? "(" : "", height/(priv->vdec*priv->fields), (priv->fields == 2) ? "x2)" : "", (width/priv->hdec)*stretchx, (height/(priv->vdec*priv->fields))* stretchy*priv->fields); if ((width/priv->hdec)*stretchx > priv->maxwidth || (height/(priv->vdec*priv->fields))* stretchy*priv->fields > priv->maxheight) { ERROR("output dimensions too large (%dx%d), max (%dx%d) " "insert crop to fix\n", (width/priv->hdec)*stretchx, (height/(priv->vdec*priv->fields))* stretchy*priv->fields, priv->maxwidth, priv->maxheight); err = 1; } if (width%(16*priv->hdec) != 0) { ERROR("width must be a multiple of 16*hdec (%d), use expand\n", priv->hdec*16); err = 1; } if (height%(8*priv->fields*priv->vdec) != 0) { ERROR("height must be a multiple of 8*fields*vdec (%d)," " use expand\n", priv->vdec*priv->fields*8); err = 1; } if (err) return 0; priv->y_stride = width; priv->c_stride = width/2; priv->j = jpeg_enc_init(width, height/priv->fields, priv->fields*priv->y_stride, priv->fields*priv->c_stride, priv->fields*priv->c_stride, 1, priv->quality, priv->bw); if (!priv->j) return 0; return vf_next_config(vf, width, height, d_width, d_height, flags, (priv->fields == 2) ? IMGFMT_ZRMJPEGIT : IMGFMT_ZRMJPEGNI);}/// put_image entrypoint for the ZRMJPEG vf filter/*** * \param vf pointer to vf_instance * \param mpi pointer to mp_image_t structure * \param pts */static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ struct vf_priv_s *priv = vf->priv; int size = 0; int i; mp_image_t* dmpi; for (i = 0; i < priv->fields; i++) size += jpeg_enc_frame(priv->j, mpi->planes[0] + i*priv->y_stride, mpi->planes[1] + i*priv->c_stride, mpi->planes[2] + i*priv->c_stride, priv->buf + size); dmpi = vf_get_image(vf->next, IMGFMT_ZRMJPEGNI, MP_IMGTYPE_EXPORT, 0, mpi->w, mpi->h); dmpi->planes[0] = (uint8_t*)priv->buf; dmpi->planes[1] = (uint8_t*)size; return vf_next_put_image(vf,dmpi, pts);}/// query_format entrypoint for the ZRMJPEG vf filter/*** * \param vf pointer to vf_instance * \param fmt image format to query for * * \returns 0 if image format in fmt is not supported * * Given the image format specified by \a fmt, this routine is called * to ask if the format is supported or not. */static int query_format(struct vf_instance_s* vf, unsigned int fmt){ VERBOSE("query_format() called\n"); switch (fmt) { case IMGFMT_YV12: case IMGFMT_YUY2: /* strictly speaking the output format of * this filter will be known after config(), * but everything that supports IMGFMT_ZRMJPEGNI * should also support all other IMGFMT_ZRMJPEG* */ return vf_next_query_format(vf, IMGFMT_ZRMJPEGNI); } return 0;}/// vf UNINIT entry point for the ZRMJPEG filter/** * \param vf pointer to the vf instance structure */static void uninit(vf_instance_t *vf) { struct vf_priv_s *priv = vf->priv; VERBOSE("uninit() called\n"); if (priv->j) jpeg_enc_uninit(priv->j); free(priv);}/// vf OPEN entry point for the ZRMJPEG filter/** * \param vf pointer to the vf instance structure * \param args the argument list string for the -vf zrmjpeg command * * \returns 0 for error, 1 for success * * This routine will do some basic initialization of local structures etc., * and then parse the command line arguments specific for the ZRMJPEG filter. */static int open(vf_instance_t *vf, char* args){ struct vf_priv_s *priv; VERBOSE("open() called: args=\"%s\"\n", args); vf->config = config; vf->put_image = put_image; vf->query_format = query_format; vf->uninit = uninit; priv = vf->priv = calloc(sizeof(*priv), 1); if (!vf->priv) { ERROR("out of memory error\n"); return 0; } /* maximum displayable size by zoran card, these defaults * are for my own zoran card in PAL mode, these can be changed * by filter options. But... in an ideal world these values would * be queried from the vo device itself... */ priv->maxwidth = 768; priv->maxheight = 576; priv->quality = 2; priv->hdec = 1; priv->vdec = 1; /* if libavcodec is already initialized, we must not initialize it * again, but if it is not initialized then we mustinitialize it now. */ if (!avcodec_inited) { /* we need to initialize libavcodec */ avcodec_init(); avcodec_register_all(); avcodec_inited=1; } if (args) { char *arg, *tmp, *ptr, junk; int last = 0, input; /* save arguments, to be able to safely modify them */ arg = strdup(args); if (!arg) { ERROR("out of memory, this is bad\n"); return 0; } tmp = ptr = arg; do { while (*tmp != ':' && *tmp) tmp++; if (*tmp == ':') *tmp++ = '\0'; else last = 1; VERBOSE("processing filter option \"%s\"\n", ptr); /* These options deal with the maximum output * resolution of the zoran card. These should * be queried from the vo device, but it is currently * too difficult, so the user should tell the filter */ if (!strncmp("maxheight=", ptr, 10)) { if (sscanf(ptr+10, "%d%c", &input, &junk) != 1) ERROR( "error parsing parameter to \"maxheight=\", \"%s\", ignoring\n" , ptr + 10); else { priv->maxheight = input; VERBOSE("setting maxheight to %d\n", priv->maxheight); } } else if (!strncmp("quality=", ptr, 8)) { if (sscanf(ptr+8, "%d%c", &input, &junk) != 1) ERROR( "error parsing parameter to \"quality=\", \"%s\", ignoring\n" , ptr + 8); else if (input < 1 || input > 20) ERROR( "parameter to \"quality=\" out of range (1..20), %d\n", input); else { priv->quality = input; VERBOSE("setting JPEG quality to %d\n", priv->quality); } } else if (!strncmp("maxwidth=", ptr, 9)) { if (sscanf(ptr+9, "%d%c", &input, &junk) != 1) ERROR( "error parsing parameter to \"maxwidth=\", \"%s\", ignoring\n" , ptr + 9); else { priv->maxwidth = input; VERBOSE("setting maxwidth to %d\n", priv->maxwidth); } } else if (!strncmp("hdec=", ptr, 5)) { if (sscanf(ptr+5, "%d%c", &input, &junk) != 1) ERROR( "error parsing parameter to \"hdec=\", \"%s\", ignoring\n" , ptr + 9); else if (input != 1 && input != 2 && input != 4) ERROR( "illegal parameter to \"hdec=\", %d, should be 1, 2 or 4", input); else { priv->hdec = input; VERBOSE( "setting horizontal decimation to %d\n", priv->maxwidth); } } else if (!strncmp("vdec=", ptr, 5)) { if (sscanf(ptr+5, "%d%c", &input, &junk) != 1) ERROR( "error parsing parameter to \"vdec=\", \"%s\", ignoring\n" , ptr + 9); else if (input != 1 && input != 2 && input != 4) ERROR( "illegal parameter to \"vdec=\", %d, should be 1, 2 or 4", input); else { priv->vdec = input; VERBOSE( "setting vertical decimation to %d\n", priv->maxwidth); } } else if (!strcasecmp("dc10+-PAL", ptr) || !strcasecmp("dc10-PAL", ptr)) { priv->maxwidth = 768; priv->maxheight = 576; VERBOSE("setting DC10(+) PAL profile\n"); } else if (!strcasecmp("fd", ptr)) { priv->fd = 1; VERBOSE("forcing decimation\n"); } else if (!strcasecmp("nofd", ptr)) { priv->fd = 0; VERBOSE("decimate only if beautiful\n"); } else if (!strcasecmp("bw", ptr)) { priv->bw = 1; VERBOSE("setting black and white encoding\n"); } else if (!strcasecmp("color", ptr)) { priv->bw = 0; VERBOSE("setting color encoding\n"); } else if (!strcasecmp("dc10+-NTSC", ptr) || !strcasecmp("dc10-NTSC", ptr)) { priv->maxwidth = 640; priv->maxheight = 480; VERBOSE("setting DC10(+) NTSC profile\n"); } else if (!strcasecmp("buz-PAL", ptr) || !strcasecmp("lml33-PAL", ptr)) { priv->maxwidth = 720; priv->maxheight = 576; VERBOSE("setting buz/lml33 PAL profile\n"); } else if (!strcasecmp("buz-NTSC", ptr) || !strcasecmp("lml33-NTSC", ptr)) { priv->maxwidth = 720; priv->maxheight = 480; VERBOSE("setting buz/lml33 NTSC profile\n"); } else { WARNING("ignoring unknown filter option " "\"%s\", or missing argument\n", ptr); } ptr = tmp; } while (!last); free(arg); } return 1;}vf_info_t vf_info_zrmjpeg = { "realtime zoran MJPEG encoding", "zrmjpeg", "Rik Snel", "", open, NULL};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?