#include #include #include #include #include #include "gmencoder.h" void DetectarCrop () { char Origen[256]; char Orden[256]; char Tmp[256]; char linea[512]; int Titulo; float Aspecto; FILE *pipe; int pid; int mask; int fd; struct timeval time_out; int ret; char crop[256]; int num_veces[256]; int i; int j; int Tiempo = 500; char crops[256][256]; int mayor = 0; if (GeneraOrigen (Origen, &Titulo, &Aspecto)) { return; } strPrincipal.cmbValoresCropping_items = g_list_append (strPrincipal.cmbValoresCropping_items, (gpointer) ""); gtk_combo_set_popdown_strings (GTK_COMBO (strPrincipal.cmbValoresCropping), strPrincipal.cmbValoresCropping_items); g_list_free(strPrincipal.cmbValoresCropping_items); strPrincipal.cmbValoresCropping_items = NULL; while (gtk_events_pending()) { gtk_main_iteration (); } sprintf (Tmp, _("Looking for cropping values")); gtk_widget_show (strOperacion.winOperacionEnCurso); while (1) { sprintf (Orden, "mplayer %s -vop cropdetect -vo null -ss %d -frames 250 -nosound -benchmark", Origen, Tiempo); #ifdef DEBUG fprintf (stderr, _("I run... [%s]\n"), Orden); #endif memset (crops, 0, 256*256); memset (num_veces, 0, 256*sizeof(int)); if (NULL == (pipe = mypopen (CfgGen.Path_mp, Orden, "r", &pid, "/"))) { MsgError ("Error executing: [%s]", Orden); } else { fd = fileno(pipe); mask = (((int)1) << fd); fprintf (stderr, _("pid: %d\n"), pid); gtk_label_set_text (GTK_LABEL(strOperacion.lblOperacionEnCurso), Tmp); while (!feof (pipe)) { while (gtk_events_pending()) { gtk_main_iteration (); } time_out.tv_sec = 4; time_out.tv_usec = 500000; ret = select (fd + 1, (fd_set *)&mask, NULL, NULL, &time_out); if (ret == 0) { #ifdef DEBUG fprintf (stderr, _("\nExiting because timeout... [%d]\n"), pid); #endif kill (pid, SIGTERM); break; } while (gtk_events_pending()) { gtk_main_iteration (); } LeeLinea (linea, 512, pipe); if (NULL != AnalizaLinea (&linea[j], crop, CROP, INI_CROP, FIN_CROP, SALTA_CROP)) { #ifdef DEBUG fprintf (stderr, _("Found CROP [%s].\n"), crop); #endif for (i = 0; i < 256; i ++) { if (!strcmp (crops[i], crop)) { break; } if (!crops[i][0]) { break; } } if (crops[i][0]) /* Se encontro */ { num_veces[i] ++; } else if (i == 256) /* Hay que buscar un hueco */ { for (i = 0; i < 256; i ++) { if (num_veces[i] < 10) { strcpy (crops[i], crop); break; } } } else /* Hay hueco */ { strcpy (crops[i], crop); num_veces[i] = 1; } } } while (gtk_events_pending()) { gtk_main_iteration (); } mypclose (pipe); } for (i = 0; crops[i][0] && i < 256; i ++) { if (mayor < num_veces[i]) { mayor = num_veces[i]; } } for (;mayor != 0; mayor --) { for (i = 0; crops[i][0] && i < 256; i ++) { if (num_veces[i] == mayor) { #ifdef DEBUG fprintf (stderr, _("CROP --> [%s] --> [%d].\n"), crops[i], num_veces[i]); #endif strPrincipal.cmbValoresCropping_items = g_list_append (strPrincipal.cmbValoresCropping_items, (gpointer) crops[i]); } } } if (i != 0) { gtk_combo_set_popdown_strings (GTK_COMBO (strPrincipal.cmbValoresCropping), strPrincipal.cmbValoresCropping_items); g_list_free(strPrincipal.cmbValoresCropping_items); strPrincipal.cmbValoresCropping_items = NULL; break; } if (Tiempo == 0) { strPrincipal.cmbValoresCropping_items = g_list_append (strPrincipal.cmbValoresCropping_items, (gpointer) ""); gtk_combo_set_popdown_strings (GTK_COMBO (strPrincipal.cmbValoresCropping), strPrincipal.cmbValoresCropping_items); g_list_free(strPrincipal.cmbValoresCropping_items); strPrincipal.cmbValoresCropping_items = NULL; break; } Tiempo /= 2; } gtk_widget_hide (strOperacion.winOperacionEnCurso); return; }