void chroma_usage(void) { int mode = 0; const char *keyword; fprintf(stderr, "%s -x usage: Only the 3 plane formats are actually supported\n", __progname); for (mode = 0; (keyword = y4m_chroma_keyword(mode)) != NULL; mode++) fprintf(stderr, "\t%s - %s\n", keyword, y4m_chroma_description(mode)); exit(1); }
void y4m_log_stream_info(log_level_t level, const char *prefix, const y4m_stream_info_t *i) { char s[256]; snprintf(s, sizeof(s), " frame size: "); if (i->width == Y4M_UNKNOWN) snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?)x"); else snprintf(s+strlen(s), sizeof(s)-strlen(s), "%dx", i->width); if (i->height == Y4M_UNKNOWN) snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?) pixels "); else snprintf(s+strlen(s), sizeof(s)-strlen(s), "%d pixels ", i->height); { int framelength = y4m_si_get_framelength(i); if (framelength == Y4M_UNKNOWN) snprintf(s+strlen(s), sizeof(s)-strlen(s), "(? bytes)"); else snprintf(s+strlen(s), sizeof(s)-strlen(s), "(%d bytes)", framelength); mjpeg_log(level, "%s%s", prefix, s); } { const char *desc = y4m_chroma_description(i->chroma); if (desc == NULL) desc = "unknown!"; mjpeg_log(level, "%s chroma: %s", prefix, desc); } if ((i->framerate.n == 0) && (i->framerate.d == 0)) mjpeg_log(level, "%s frame rate: ??? fps", prefix); else mjpeg_log(level, "%s frame rate: %d/%d fps (~%f)", prefix, i->framerate.n, i->framerate.d, (double) i->framerate.n / (double) i->framerate.d); mjpeg_log(level, "%s interlace: %s", prefix, (i->interlace == Y4M_ILACE_NONE) ? "none/progressive" : (i->interlace == Y4M_ILACE_TOP_FIRST) ? "top-field-first" : (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "bottom-field-first" : (i->interlace == Y4M_ILACE_MIXED) ? "mixed-mode" : "anyone's guess"); if ((i->sampleaspect.n == 0) && (i->sampleaspect.d == 0)) mjpeg_log(level, "%ssample aspect ratio: ?:?", prefix); else mjpeg_log(level, "%ssample aspect ratio: %d:%d", prefix, i->sampleaspect.n, i->sampleaspect.d); }
static void usage(const char *progname) { fprintf(stderr, "\n"); fprintf(stderr, "usage: %s [options] [ppm-file]\n", progname); fprintf(stderr, "\n"); fprintf(stderr, "Reads RAW PPM image(s), and produces YUV4MPEG2 stream on stdout.\n"); fprintf(stderr, "Converts computer graphics R'G'B' colorspace to digital video Y'CbCr,\n"); fprintf(stderr, " and performs chroma subsampling.\n"); fprintf(stderr, "\n"); fprintf(stderr, "If 'ppm-file' is not specified, reads from stdin.\n"); fprintf(stderr, "\n"); fprintf(stderr, " options: (defaults specified in [])\n"); fprintf(stderr, "\n"); fprintf(stderr, " -o n frame offset (skip n input frames) [0]\n"); fprintf(stderr, " -n n frame count (output n frames; 0 == all of them) [0]\n"); fprintf(stderr, " -F n:d framerate [30000:1001 = NTSC]\n"); fprintf(stderr, " -A w:h pixel aspect ratio [1:1]\n"); fprintf(stderr, " -I x interlacing [p]\n"); fprintf(stderr, " p = none/progressive\n"); fprintf(stderr, " t = top-field-first\n"); fprintf(stderr, " b = bottom-field-first\n"); fprintf(stderr, " -L treat PPM images as 2-field interleaved\n"); fprintf(stderr, " -r repeat last input frame\n"); { int m; const char *keyword; fprintf(stderr, " -S mode chroma subsampling mode [%s]\n", y4m_chroma_keyword(DEFAULT_CHROMA_MODE)); for (m = 0; (keyword = y4m_chroma_keyword(m)) != NULL; m++) if (chroma_sub_implemented(m)) fprintf(stderr, " '%s' -> %s\n", keyword, y4m_chroma_description(m)); } /* fprintf(stderr, " -R type subsampling filter type\n");*/ fprintf(stderr, " -v n verbosity (0,1,2) [1]\n"); fprintf(stderr, " -B PPM image is packed with BGR pixels [RGB]\n"); }
static void parse_args(cl_info_t *cl, int argc, char **argv) { int c; cl->offset = 0; cl->framecount = 0; cl->aspect = y4m_sar_SQUARE; cl->interlace = Y4M_ILACE_NONE; cl->framerate = y4m_fps_NTSC; cl->interleave = 0; cl->repeatlast = 0; cl->ss_mode = DEFAULT_CHROMA_MODE; cl->verbosity = 1; cl->bgr = 0; cl->fdin = fileno(stdin); /* default to stdin */ while ((c = getopt(argc, argv, "BA:F:I:Lo:n:rS:v:h")) != -1) { switch (c) { case 'A': if (y4m_parse_ratio(&(cl->aspect), optarg) != Y4M_OK) { mjpeg_error("Could not parse ratio: '%s'", optarg); goto ERROR_EXIT; } break; case 'F': if (y4m_parse_ratio(&(cl->framerate), optarg) != Y4M_OK) { mjpeg_error("Could not parse ratio: '%s'", optarg); goto ERROR_EXIT; } break; case 'I': switch (optarg[0]) { case 'p': cl->interlace = Y4M_ILACE_NONE; break; case 't': cl->interlace = Y4M_ILACE_TOP_FIRST; break; case 'b': cl->interlace = Y4M_ILACE_BOTTOM_FIRST; break; default: mjpeg_error("Unknown value for interlace: '%c'", optarg[0]); goto ERROR_EXIT; break; } break; case 'L': cl->interleave = 1; break; case 'B': cl->bgr = 1; break; case 'o': if ((cl->offset = atoi(optarg)) < 0) mjpeg_error_exit1("Offset must be >= 0: '%s'", optarg); break; case 'n': if ((cl->framecount = atoi(optarg)) < 0) mjpeg_error_exit1("Frame count must be >= 0: '%s'", optarg); break; case 'r': cl->repeatlast = 1; break; case 'S': cl->ss_mode = y4m_chroma_parse_keyword(optarg); if (cl->ss_mode == Y4M_UNKNOWN) { mjpeg_error("Unknown subsampling mode option: %s", optarg); goto ERROR_EXIT; } else if (!chroma_sub_implemented(cl->ss_mode)) { mjpeg_error("Unsupported subsampling mode option: %s", optarg); goto ERROR_EXIT; } break; case 'v': cl->verbosity = atoi(optarg); if ((cl->verbosity < 0) || (cl->verbosity > 2)) mjpeg_error("Verbosity must be 0, 1, or 2: '%s'", optarg); break; case 'h': usage(argv[0]); exit(0); break; case '?': default: goto ERROR_EXIT; break; } } /* optional remaining argument is a filename */ if (optind == (argc - 1)) { if ((cl->fdin = open(argv[optind], O_RDONLY | O_BINARY)) == -1) mjpeg_error_exit1("Failed to open '%s': %s", argv[optind], strerror(errno)); } else if (optind != argc) goto ERROR_EXIT; mjpeg_default_handler_verbosity(cl->verbosity); mjpeg_info("Command-line Parameters:"); mjpeg_info(" framerate: %d:%d", cl->framerate.n, cl->framerate.d); mjpeg_info(" pixel aspect ratio: %d:%d", cl->aspect.n, cl->aspect.d); mjpeg_info(" pixel packing: %s", cl->bgr?"BGR":"RGB"); mjpeg_info(" interlace: %s%s", mpeg_interlace_code_definition(cl->interlace), (cl->interlace == Y4M_ILACE_NONE) ? "" : (cl->interleave) ? " (interleaved PPM input)" : " (field-sequential PPM input)"); mjpeg_info(" starting frame: %d", cl->offset); if (cl->framecount == 0) mjpeg_info(" # of frames: all%s", (cl->repeatlast) ? ", repeat last frame forever" : ", until input exhausted"); else mjpeg_info(" # of frames: %d%s", cl->framecount, (cl->repeatlast) ? ", repeat last frame until done" : ", or until input exhausted"); mjpeg_info(" chroma subsampling: %s", y4m_chroma_description(cl->ss_mode)); /* DONE! */ return; ERROR_EXIT: mjpeg_error("For usage hints, use option '-h'. Please take a hint."); exit(1); }
static int yw_open_video(YWPrivateData *pd, vob_t *vob) { int errnum = Y4M_OK; int ch_mode = 0; /* initialize stream-information */ y4m_accept_extensions(1); y4m_init_stream_info(&pd->streaminfo); y4m_init_frame_info(&pd->frameinfo); if (vob->im_v_codec == TC_CODEC_YUV420P) { pd->dstfmt = IMG_YUV_DEFAULT; } else if (vob->im_v_codec == TC_CODEC_RGB24) { pd->dstfmt = IMG_RGB_DEFAULT; } else { tc_log_error(MOD_NAME, "unsupported video format %d", vob->im_v_codec); return(TC_EXPORT_ERROR); } /* we trust autoprobing */ pd->width = vob->im_v_width; pd->height = vob->im_v_height; pd->fd_vid = open(vob->video_in_file, O_RDONLY); if (pd->fd_vid == -1) { tc_log_error(MOD_NAME, "can't open video source '%s'" " (reason: %s)", vob->video_in_file, strerror(errno)); } else { if (verbose >= TC_DEBUG) { tc_log_info(MOD_NAME, "using video source: %s", vob->video_in_file); } } pd->tcvhandle = tcv_init(); if (!pd->tcvhandle) { tc_log_error(MOD_NAME, "image conversion init failed"); return(TC_EXPORT_ERROR); } errnum = y4m_read_stream_header(pd->fd_vid, &pd->streaminfo); if (errnum != Y4M_OK) { tc_log_error(MOD_NAME, "Couldn't read YUV4MPEG header: %s!", y4m_strerr(errnum)); tcv_free(pd->tcvhandle); close(pd->fd_vid); return(TC_IMPORT_ERROR); } if (y4m_si_get_plane_count(&pd->streaminfo) != 3) { tc_log_error(MOD_NAME, "Only 3-plane formats supported"); close(pd->fd_vid); return(TC_IMPORT_ERROR); } ch_mode = y4m_si_get_chroma(&pd->streaminfo); if (ch_mode != Y4M_CHROMA_420JPEG && ch_mode != Y4M_CHROMA_420MPEG2 && ch_mode != Y4M_CHROMA_420PALDV) { tc_log_error(MOD_NAME, "sorry, chroma mode `%s' (%i) not supported", y4m_chroma_description(ch_mode), ch_mode); tcv_free(pd->tcvhandle); close(pd->fd_vid); return(TC_IMPORT_ERROR); } if (verbose) { tc_log_info(MOD_NAME, "chroma mode: %s", y4m_chroma_description(ch_mode)); } return(TC_IMPORT_OK); }