/* * yuvpulldowndetect.c * produces a 2d graph showing time vs frame difference. * the idea is that 3:2 pulldown has a distinct frame duplication pattern * . * modified from yuvfps.c by * Copyright (C) 2002 Alfonso Garcia-Patiņo Barbolani * * * 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 #include #include #include #include #include "yuv4mpeg.h" #include "mpegconsts.h" #define YUVFPS_VERSION "0.1" static void print_usage() { fprintf (stderr, "usage: yuvaddetect [-v -h -Ip|b|p]\n" "yuvaddetect produces a 2d graph showing time vs frame difference\n" "\n" "\t -v Verbosity degree : 0=quiet, 1=normal, 2=verbose/debug\n" "\t -I Force interlace mode\n" "\t -h print this help\n" ); } static void detect( int fdIn , y4m_stream_info_t *inStrInfo,int interlacing) { y4m_frame_info_t in_frame ; uint8_t *yuv_data[3] ; uint8_t *yuv_odata[3] ; uint8_t *yuv_tdata ; int frame_data_size ; int read_error_code ; int write_error_code ; int src_frame_counter ; int w,h,x; int bri=0, bro=0,l=0; // Allocate memory for the YUV channels h = y4m_si_get_height(inStrInfo); w = y4m_si_get_width(inStrInfo); frame_data_size = h*w; yuv_data[0] = (uint8_t *)malloc( frame_data_size ); yuv_data[1] = (uint8_t *)malloc( frame_data_size >> 2); yuv_data[2] = (uint8_t *)malloc( frame_data_size >> 2); yuv_odata[0] = (uint8_t *)malloc( frame_data_size ); yuv_odata[1] = (uint8_t *)malloc( frame_data_size >> 2); yuv_odata[2] = (uint8_t *)malloc( frame_data_size >> 2); if( !yuv_data[0] || !yuv_data[1] || !yuv_data[2] || !yuv_odata[0] || !yuv_odata[1] || !yuv_odata[2] ) mjpeg_error_exit1 ("Could'nt allocate memory for the YUV4MPEG data!"); write_error_code = Y4M_OK ; src_frame_counter = 0 ; y4m_init_frame_info( &in_frame ); read_error_code = y4m_read_frame(fdIn,inStrInfo,&in_frame,yuv_odata ); ++src_frame_counter ; while( Y4M_ERR_EOF != read_error_code && write_error_code == Y4M_OK ) { read_error_code = y4m_read_frame(fdIn, inStrInfo,&in_frame,yuv_data ); // check for read error // perform frame difference. // only comparing Luma, less noise, more resolution... blah blah bri = 0; bro=0; for (l=0; l< frame_data_size; l+=w<<1) { for (x=0; x>2); memcpy(yuv_odata[2], yuv_data[2], frame_data_size>>2); */ y4m_fini_frame_info( &in_frame ); y4m_init_frame_info( &in_frame ); } // Clean-up regardless an error happened or not y4m_fini_frame_info( &in_frame ); free( yuv_data[0] ); free( yuv_data[1] ); free( yuv_data[2] ); if( read_error_code != Y4M_ERR_EOF ) mjpeg_error_exit1 ("Error reading from input stream!"); if( write_error_code != Y4M_OK ) mjpeg_error_exit1 ("Error writing output stream!"); } static int parse_interlacing(char *str) { if (str[0] != '\0' && str[1] == '\0') { switch (str[0]) { case 'p': return Y4M_ILACE_NONE; case 't': return Y4M_ILACE_TOP_FIRST; case 'b': return Y4M_ILACE_BOTTOM_FIRST; } } mjpeg_error_exit1("Valid interlacing modes are: p - progressive, t - top-field first, b - bottom-field first"); return Y4M_UNKNOWN; /* to avoid compiler warnings */ } // ************************************************************************************* // MAIN // ************************************************************************************* int main (int argc, char *argv[]) { int verbose = 4; // LOG_ERROR ; int fdIn = 0 ; y4m_stream_info_t in_streaminfo; int src_interlacing = Y4M_UNKNOWN; const static char *legal_flags = "I:v:h"; int c ; while ((c = getopt (argc, argv, legal_flags)) != -1) { switch (c) { case 'v': verbose = atoi (optarg); if (verbose < 0 || verbose > 2) mjpeg_error_exit1 ("Verbose level must be [0..2]"); break; case 'I': src_interlacing = parse_interlacing(optarg); break; case 'h': case '?': print_usage (argv); return 0 ; break; } } // mjpeg tools global initialisations mjpeg_default_handler_verbosity (verbose); // Initialize input streams y4m_init_stream_info (&in_streaminfo); // *************************************************************** // Get video stream informations (size, framerate, interlacing, aspect ratio). // The streaminfo structure is filled in // *************************************************************** // INPUT comes from stdin, we check for a correct file header if (y4m_read_stream_header (fdIn, &in_streaminfo) != Y4M_OK) mjpeg_error_exit1 ("Could'nt read YUV4MPEG header!"); // Information output mjpeg_info ("yuvdiff (version " YUVFPS_VERSION ") is a frame/field doubling detector for yuv streams"); mjpeg_info ("yuvaddetect -h for help, or man yuvaddetect"); if (src_interlacing == Y4M_UNKNOWN) src_interlacing = y4m_si_get_interlace(&in_streaminfo); /* in that function we do all the important work */ detect( fdIn,&in_streaminfo,src_interlacing); y4m_fini_stream_info (&in_streaminfo); return 0; } /* * Local variables: * tab-width: 8 * indent-tabs-mode: nil * End: */