/* * matteblend - reads three frame-interlaced YUV4MPEG streams from stdin * and blends the second over the first using the third's * luminance channel as a matte * * Copyright (C) 2001, pHilipp Zabel * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include "yuv4mpeg.h" static void usage (progname) { fprintf (stderr, "usage: %s -o [-f ]\n",progname); } int main (int argc, char *argv[]){ int in_fd = 0; /* stdin */ int out_fd = 1; /* stdout */ unsigned char *yuv[3]; /* output */ y4m_stream_info_t streaminfo; y4m_frame_info_t frameinfo; int i; int w, h; int framenum; int offset=225; int totframes=0; if (argc < 3) { usage (argv[0]); exit (1); } else if (strcmp(argv[1],"-o")==0){ offset=atoi(argv[2]); } if ((argc==5) && (strcmp(argv[3],"-f")==0)) { totframes=atoi(argv[4]); } y4m_init_stream_info (&streaminfo); y4m_init_frame_info (&frameinfo); i = y4m_read_stream_header (in_fd, &streaminfo); if (i != Y4M_OK) { fprintf (stderr, "%s: input stream error - %s\n", argv[0], y4m_strerr(i)); exit (1); } w = y4m_si_get_width(&streaminfo); h = y4m_si_get_height(&streaminfo); yuv[0] = malloc (w * h); yuv[1] = malloc (w * h / 4); yuv[2] = malloc (w * h / 4); y4m_write_stream_header (out_fd, &streaminfo); framenum=0; while (1) { i = y4m_read_frame(in_fd, &streaminfo, &frameinfo, yuv); if ((i == Y4M_ERR_EOF)||(framenum-offset>=totframes &&(totframes>0))) { exit (0); } else if (i != Y4M_OK) exit (1); if(framenum>=offset) y4m_write_frame (out_fd, &streaminfo, &frameinfo, yuv); framenum++; } }