Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added cpplint.py and a tools/ directory

Cleans up various parts of shotdetect:

1. File naming
2. Intentation and style
3. Added an "UI" directory
  • Loading branch information...
commit 113ebf86637081969d63e6109e5cc25f9a892983 1 parent 53d58be
@johmathe authored
Showing with 5,426 additions and 2,668 deletions.
  1. +9 −9 CMakeLists.txt
  2. +0 −23 include/config.h
  3. +0 −235 include/film.h
  4. +0 −1  include/stamp-h
  5. +0 −15 src/Makefile.am
  6. +0 −452 src/Makefile.in
  7. +51 −58 src/{bdd.cpp → bdd.cc}
  8. +5 −7 {include → src}/bdd.h
  9. +162 −0 src/commandline.cc
  10. +0 −167 src/commandline.cpp
  11. +47 −64 src/{conf.cpp → conf.cc}
  12. +4 −4 {include → src}/conf.h
  13. +656 −0 src/film.cc
  14. +0 −697 src/film.cpp
  15. +276 −0 src/film.h
  16. +123 −144 src/{graph.cpp → graph.cc}
  17. +16 −19 {include → src}/graph.h
  18. +174 −0 src/image.cc
  19. +0 −186 src/image.cpp
  20. +2 −2 {include → src}/image.h
  21. +234 −0 src/main.cc
  22. +0 −249 src/main.cpp
  23. +4 −5 src/{shot.cpp → shot.cc}
  24. +3 −3 {include → src}/shot.h
  25. +7 −5 src/{DialogHelp.cpp → ui/dialog_help.cc}
  26. +4 −4 include/DialogHelp.h → src/ui/dialog_help.h
  27. +105 −113 src/{DialogShotDetect_c.cpp → ui/dialog_shotdetect.cc}
  28. +14 −18 include/DialogShotDetect_c.h → src/ui/dialog_shotdetect.h
  29. +16 −17 src/{wxProcessVideoThread.cpp → ui/process_video_thread.cc}
  30. +11 −13 include/wxProcessVideoThread.h → src/ui/process_video_thread.h
  31. +137 −155 src/{xml.cpp → xml.cc}
  32. +5 −3 {include → src}/xml.h
  33. +3,361 −0 tools/cpplint.py
View
18 CMakeLists.txt
@@ -146,15 +146,15 @@ ENDIF()
# shotdetect
SET(TARGET_NAME "shotdetect")
-INCLUDE_DIRECTORIES(. include)
+INCLUDE_DIRECTORIES(.)
# shotdetect library
-SET(${TARGET_NAME}_LIBRARY_SRCS src/film.cpp src/graph.cpp src/image.cpp src/shot.cpp src/xml.cpp)
-SET(${TARGET_NAME}_LIBRARY_HDRS include/film.h include/graph.h include/image.h include/shot.h include/xml.h)
+SET(${TARGET_NAME}_LIBRARY_SRCS src/film.cc src/graph.cc src/image.cc src/shot.cc src/xml.cc)
+SET(${TARGET_NAME}_LIBRARY_HDRS src/film.h src/graph.h src/image.h src/shot.h src/xml.h)
IF(USE_POSTGRESQL)
- SET(${TARGET_NAME}_LIBRARY_SRCS ${${TARGET_NAME}_LIBRARY_SRCS} src/bdd.cpp)
- SET(${TARGET_NAME}_LIBRARY_HDRS ${${TARGET_NAME}_LIBRARY_HDRS} include/bdd.h)
+ SET(${TARGET_NAME}_LIBRARY_SRCS ${${TARGET_NAME}_LIBRARY_SRCS} src/bdd.cc)
+ SET(${TARGET_NAME}_LIBRARY_HDRS ${${TARGET_NAME}_LIBRARY_HDRS} src/bdd.h)
ENDIF()
ADD_LIBRARY(${TARGET_NAME} ${${TARGET_NAME}_LIBRARY_SRCS} ${${TARGET_NAME}_LIBRARY_HDRS})
TARGET_LINK_LIBRARIES(${TARGET_NAME} ${FFMPEG_LIBRARIES} ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${GD_LIBRARIES})
@@ -174,12 +174,12 @@ ELSEIF(WIN32)
ENDIF()
IF(USE_WXWIDGETS AND wxWidgets_FOUND)
- SET(${TARGET_NAME}_GUI_SRCS src/main.cpp src/DialogHelp.cpp src/DialogShotDetect_c.cpp src/wxProcessVideoThread.cpp)
- SET(${TARGET_NAME}_GUI_HDRS include/DialogHelp.h include/DialogShotDetect_c.h include/wxProcessVideoThread.h)
+ SET(${TARGET_NAME}_GUI_SRCS src/main.cc src/ui/dialog_help.cc src/ui/dialog_shotdetect.cc src/ui/process_video_thread.cc)
+ SET(${TARGET_NAME}_GUI_HDRS src/ui/dialog_help.h src/ui/dialog_shotdetect.h src/ui/process_video_thread.h)
ADD_EXECUTABLE(${TARGET_NAME}-gui ${APP_TYPE} ${${TARGET_NAME}_GUI_SRCS} ${${TARGET_NAME}_GUI_HDRS})
TARGET_LINK_LIBRARIES(${TARGET_NAME}-gui ${TARGET_NAME})
ELSE()
- SET(${TARGET_NAME}_COMMANDLINE_SRCS src/commandline.cpp)
+ SET(${TARGET_NAME}_COMMANDLINE_SRCS src/commandline.cc)
ADD_EXECUTABLE(${TARGET_NAME}-cmd ${${TARGET_NAME}_COMMANDLINE_SRCS})
TARGET_LINK_LIBRARIES(${TARGET_NAME}-cmd ${TARGET_NAME})
-ENDIF()
+ENDIF()
View
23 include/config.h
@@ -1,23 +0,0 @@
-/* config.h. Generated from config.h.in by configure. */
-/* config.h.in. Generated from configure.in by autoheader. */
-/* $Id */
-/* Name of package */
-#define PACKAGE "shotdetect"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "johan.mathe@tremplin-utc.fr"
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "film.cpp"
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "film.cpp 1.0"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "film-cpp"
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.0"
-
-/* Version number of package */
-#define VERSION "1.0.1"
View
235 include/film.h
@@ -1,235 +0,0 @@
-/*
- * $Id: film.h 193 2010-09-30 23:02:58Z peterb $
- * $Date: 2010-10-01 01:02:58 +0200 (Fri, 01 Oct 2010) $
- */
-#ifndef __FILM_H__
-#define __FILM_H__
-
-#ifndef INT64_C
-#define INT64_C(c) (c ## LL)
-#define UINT64_C(c) (c ## ULL)
-#endif
-
-#define THUMB_HEIGHT 84
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <list>
-
-extern "C" {
-
-#include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
-
-}
-
-#ifdef BDD
-#include <postgresql/libpq-fe.h>
-#endif
-#ifdef WXWIDGETS
-#include <wx/wx.h>
-#endif
-
-#include "image.h"
-#include "shot.h"
-#include "xml.h"
-#include "graph.h"
-
-#include <string>
-#include <iostream>
-
-#define MAX_STR 254
-#define MAX_CUTS 200
-#define abs(x) ((x) < 0 ? - (x) : (x))
-#define HAVE_THREADS
-#define MAX_QUERY 400
-
-#define DEFAULT_BDD_PORT 5432
-#define DEFAULT_THUMB_HEIGHT 85
-#define DEFAULT_THRESHOLD 60
-
-#define RATIO 327
-#define MIN_INT -32768
-#define MAX_INT 32767
-
-
-
-using namespace std;
-
-class image;
-class conf;
-class shot;
-class xml;
-class DialogShotDetect_c;
-class graph;
-class film
-{
-
- private:
- /* Variables d'état */
- bool first_img_set;
- bool last_img_set;
- bool audio_set;
- bool video_set;
-
-
- unsigned int ech;
- signed short int minright;
- signed short int maxright;
- signed short int minleft;
- signed short int maxleft;
-
-
- /* Various data for ffmpeg */
- AVFormatContext *pFormatCtx;
- AVCodecContext *pCodecCtx;
- AVCodecContext *pCodecCtxAudio;
- AVCodec *pCodec;
- AVCodec *pCodecAudio;
- AVFrame *pFrame;
- AVFrame *pFrameRGB;
- AVFrame *pFrameRGBprev;
- AVPacket packet;
-
- FILE *fd_xml_audio;
-
- int samples;
- int data_size;
- uint8_t *ptr;
-
- int len1;
- int len;
- int samplerate;
- int checknumber;
-
- /* Mem allocation */
- short *audio_buf;
- signed short int sample_right;
- signed short int sample_left;
- int ret;
- int audioStream;
- int videoStream;
-
- int samplearg;
-
- void do_stats (int frame);
- void CompareFrame (AVFrame * pFrame, AVFrame * pFramePrev);
- graph *g;
-
- void update_metadata();
- void init_xml (string filename);
- int close_xml ();
-
- public:
- bool thumb_set ;
- bool shot_set ;
-
-
- DialogShotDetect_c * dialogParent;
- struct
- {
- int id;
- string name;
- string surname;
- } author;
-
- struct
- {
- string video;
- string audio;
- } codec;
-
- struct
- {
- int hours;
- int mins;
- int secs;
- int us;
- double mstotal;
- } duration;
-
- int myid;
- static int idfilm;
-
- int progress_state_prev;
- /* Name of the movie */
- string film_name;
- /* Title of the movie */
- string title;
- /* Abstract of the movie */
- string abstract;
- /* Path to the film */
- string input_path;
- /* Film height */
- int height;
- /* Film width */
- int width;
- /* Film fps */
- double fps;
- /* Number of audio chanels */
- int nchannel;
- /* Year of the movie */
- int year;
- /* Shots */
- list < shot > shots;
- /* Prev Score in compare_frame */
- int prev_score;
- /* ID BDD Film */
- int id;
- /* id du plan en cours de traitement */
- int id_plan;
- /* Language code */
- string code_lang;
- /* Processing threshold */
- int threshold;
- /* Alphanumeric ID */
- string alphaid;
- /* Absolute path */
- string global_path;
- /* Percent accomplished */
- double percent;
- /* Showing state started */
- bool show_started;
- xml *x;
- bool display;
-
- int process ();
- void process_audio ();
- void shotlog(string message);
- void create_main_dir(void);
-
- /* Constructor */
- film ();
- #ifdef WXWIDGETS
- film (DialogShotDetect_c *);
- #endif
-
- /* Accessors */
- inline void set_first_img(bool val) {this->first_img_set = val; };
- inline void set_last_img(bool val) {this->last_img_set = val; };
- inline void set_audio(bool val) {this->audio_set = val; };
- inline void set_video(bool val) {this->video_set = val; };
- inline void set_thumb(bool val) {this->thumb_set = val; };
- inline void set_shot(bool val) {this->shot_set = val; };
- inline void set_input_file(string input_file) { this->input_path = input_file; };
- inline void set_threshold(int threshold) { this->threshold=threshold; };
- inline void set_ipath(string path) { this->input_path = path; };
- inline void set_opath(string path) { this->global_path = path; };
- inline void set_year(int year) { this->year=year; };
- inline void set_alphaid(string alphaid) { this->alphaid = alphaid; };
- inline void set_title(string title) { this->title = title; };
-
- inline bool get_first_img(void) { return this->first_img_set ; };
- inline bool get_last_img(void) { return this->last_img_set ; };
- inline bool get_audio(void) { return this->audio_set ; };
- inline bool get_video(void) { return this->video_set ; };
- inline bool get_thumb(void) { return this->thumb_set ; };
- inline bool get_shot(void) { return this->shot_set ; };
- inline string get_ipath(void) { return this->input_path ; };
- inline string get_opath(void) { return this->global_path ; };
- inline double get_fps(void) { return this->fps ; };
-
-};
-
-
-#endif /* !__FILM_H__ */
View
1  include/stamp-h
@@ -1 +0,0 @@
-timestamp
View
15 src/Makefile.am
@@ -1,15 +0,0 @@
-# Fichier pour automake
-INCLUDES= -I../include -I../resources/ `wx-config --cflags` `xslt-config --cflags`
-bin_PROGRAMS = shotdetect
-shotdetect_LDADD = -lgd -lz -lavformat -lavcodec -lavutil
-shotdetect_LDFLAGS = `wx-config --libs` `xslt-config --libs`
-shotdetect_SOURCES = \
-graph.cpp \
-film.cpp \
-image.cpp \
-shot.cpp \
-xml.cpp \
-wxProcessVideoThread.cpp \
-DialogShotDetect_c.cpp \
-DialogHelp.cpp \
-main.cpp
View
452 src/Makefile.in
@@ -1,452 +0,0 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
-# @configure_input@
-
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-@SET_MAKE@
-
-VPATH = @srcdir@
-pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-install_sh_DATA = $(install_sh) -c -m 644
-install_sh_PROGRAM = $(install_sh) -c
-install_sh_SCRIPT = $(install_sh) -c
-INSTALL_HEADER = $(INSTALL_DATA)
-transform = $(program_transform_name)
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-bin_PROGRAMS = shotdetect$(EXEEXT)
-subdir = src
-DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
- $(top_srcdir)/configure.in
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
- $(ACLOCAL_M4)
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES =
-am__installdirs = "$(DESTDIR)$(bindir)"
-binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
-PROGRAMS = $(bin_PROGRAMS)
-am_shotdetect_OBJECTS = graph.$(OBJEXT) film.$(OBJEXT) image.$(OBJEXT) \
- shot.$(OBJEXT) xml.$(OBJEXT) wxProcessVideoThread.$(OBJEXT) \
- DialogShotDetect_c.$(OBJEXT) DialogHelp.$(OBJEXT) \
- main.$(OBJEXT)
-shotdetect_OBJECTS = $(am_shotdetect_OBJECTS)
-shotdetect_DEPENDENCIES =
-shotdetect_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
- $(shotdetect_LDFLAGS) $(LDFLAGS) -o $@
-DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/depcomp
-am__depfiles_maybe = depfiles
-CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
-CXXLD = $(CXX)
-CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
- -o $@
-SOURCES = $(shotdetect_SOURCES)
-DIST_SOURCES = $(shotdetect_SOURCES)
-ETAGS = etags
-CTAGS = ctags
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = @ACLOCAL@
-AMTAR = @AMTAR@
-AUTOCONF = @AUTOCONF@
-AUTOHEADER = @AUTOHEADER@
-AUTOMAKE = @AUTOMAKE@
-AWK = @AWK@
-CC = @CC@
-CCDEPMODE = @CCDEPMODE@
-CFLAGS = @CFLAGS@
-CPP = @CPP@
-CPPFLAGS = @CPPFLAGS@
-CXX = @CXX@
-CXXDEPMODE = @CXXDEPMODE@
-CXXFLAGS = @CXXFLAGS@
-CYGPATH_W = @CYGPATH_W@
-DEFS = @DEFS@
-DEPDIR = @DEPDIR@
-ECHO_C = @ECHO_C@
-ECHO_N = @ECHO_N@
-ECHO_T = @ECHO_T@
-EGREP = @EGREP@
-EXEEXT = @EXEEXT@
-GREP = @GREP@
-INSTALL = @INSTALL@
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LDFLAGS = @LDFLAGS@
-LIBOBJS = @LIBOBJS@
-LIBS = @LIBS@
-LIBXML_REQUIRED_VERSION = @LIBXML_REQUIRED_VERSION@
-LIBXML_SRC = @LIBXML_SRC@
-LTLIBOBJS = @LTLIBOBJS@
-MAKEINFO = @MAKEINFO@
-MKDIR_P = @MKDIR_P@
-OBJEXT = @OBJEXT@
-PACKAGE = @PACKAGE@
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
-PACKAGE_NAME = @PACKAGE_NAME@
-PACKAGE_STRING = @PACKAGE_STRING@
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
-PACKAGE_VERSION = @PACKAGE_VERSION@
-PATH_SEPARATOR = @PATH_SEPARATOR@
-SET_MAKE = @SET_MAKE@
-SHELL = @SHELL@
-STRIP = @STRIP@
-VERSION = @VERSION@
-WX_CFLAGS = @WX_CFLAGS@
-WX_CFLAGS_ONLY = @WX_CFLAGS_ONLY@
-WX_CONFIG_PATH = @WX_CONFIG_PATH@
-WX_CPPFLAGS = @WX_CPPFLAGS@
-WX_CXXFLAGS = @WX_CXXFLAGS@
-WX_CXXFLAGS_ONLY = @WX_CXXFLAGS_ONLY@
-WX_LIBS = @WX_LIBS@
-WX_LIBS_STATIC = @WX_LIBS_STATIC@
-WX_RESCOMP = @WX_RESCOMP@
-WX_VERSION = @WX_VERSION@
-abs_builddir = @abs_builddir@
-abs_srcdir = @abs_srcdir@
-abs_top_builddir = @abs_top_builddir@
-abs_top_srcdir = @abs_top_srcdir@
-ac_ct_CC = @ac_ct_CC@
-ac_ct_CXX = @ac_ct_CXX@
-am__include = @am__include@
-am__leading_dot = @am__leading_dot@
-am__quote = @am__quote@
-am__tar = @am__tar@
-am__untar = @am__untar@
-bindir = @bindir@
-build_alias = @build_alias@
-builddir = @builddir@
-datadir = @datadir@
-datarootdir = @datarootdir@
-docdir = @docdir@
-dvidir = @dvidir@
-exec_prefix = @exec_prefix@
-host_alias = @host_alias@
-htmldir = @htmldir@
-includedir = @includedir@
-infodir = @infodir@
-install_sh = @install_sh@
-libdir = @libdir@
-libexecdir = @libexecdir@
-localedir = @localedir@
-localstatedir = @localstatedir@
-mandir = @mandir@
-mkdir_p = @mkdir_p@
-oldincludedir = @oldincludedir@
-pdfdir = @pdfdir@
-prefix = @prefix@
-program_transform_name = @program_transform_name@
-psdir = @psdir@
-sbindir = @sbindir@
-sharedstatedir = @sharedstatedir@
-srcdir = @srcdir@
-sysconfdir = @sysconfdir@
-target_alias = @target_alias@
-top_builddir = @top_builddir@
-top_srcdir = @top_srcdir@
-
-# Fichier pour automake
-INCLUDES = -I../include -I../resources/ `wx-config --cflags` `xslt-config --cflags`
-shotdetect_LDADD = -lgd -lz -lavformat -lavcodec -lavutil
-shotdetect_LDFLAGS = `wx-config --libs` `xslt-config --libs`
-shotdetect_SOURCES = \
-graph.cpp \
-film.cpp \
-image.cpp \
-shot.cpp \
-xml.cpp \
-wxProcessVideoThread.cpp \
-DialogShotDetect_c.cpp \
-DialogHelp.cpp \
-main.cpp
-
-all: all-am
-
-.SUFFIXES:
-.SUFFIXES: .cpp .o .obj
-$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
- @for dep in $?; do \
- case '$(am__configure_deps)' in \
- *$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
- exit 1;; \
- esac; \
- done; \
- echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
- cd $(top_srcdir) && \
- $(AUTOMAKE) --gnu src/Makefile
-.PRECIOUS: Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- @case '$?' in \
- *config.status*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
- *) \
- echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
- cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
- esac;
-
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-
-$(top_srcdir)/configure: $(am__configure_deps)
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(ACLOCAL_M4): $(am__aclocal_m4_deps)
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-install-binPROGRAMS: $(bin_PROGRAMS)
- @$(NORMAL_INSTALL)
- test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
- @list='$(bin_PROGRAMS)'; for p in $$list; do \
- p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
- if test -f $$p \
- ; then \
- f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
- echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
- $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
- else :; fi; \
- done
-
-uninstall-binPROGRAMS:
- @$(NORMAL_UNINSTALL)
- @list='$(bin_PROGRAMS)'; for p in $$list; do \
- f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
- echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
- rm -f "$(DESTDIR)$(bindir)/$$f"; \
- done
-
-clean-binPROGRAMS:
- -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
-shotdetect$(EXEEXT): $(shotdetect_OBJECTS) $(shotdetect_DEPENDENCIES)
- @rm -f shotdetect$(EXEEXT)
- $(shotdetect_LINK) $(shotdetect_OBJECTS) $(shotdetect_LDADD) $(LIBS)
-
-mostlyclean-compile:
- -rm -f *.$(OBJEXT)
-
-distclean-compile:
- -rm -f *.tab.c
-
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DialogHelp.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DialogShotDetect_c.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/film.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/graph.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/image.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shot.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wxProcessVideoThread.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xml.Po@am__quote@
-
-.cpp.o:
-@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
-
-.cpp.obj:
-@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
-
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- tags=; \
- here=`pwd`; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
- test -n "$$unique" || unique=$$empty_fix; \
- $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
- $$tags $$unique; \
- fi
-ctags: CTAGS
-CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- tags=; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- test -z "$(CTAGS_ARGS)$$tags$$unique" \
- || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
- $$tags $$unique
-
-GTAGS:
- here=`$(am__cd) $(top_builddir) && pwd` \
- && cd $(top_srcdir) \
- && gtags -i $(GTAGS_ARGS) $$here
-
-distclean-tags:
- -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-
-distdir: $(DISTFILES)
- @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
- topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
- list='$(DISTFILES)'; \
- dist_files=`for file in $$list; do echo $$file; done | \
- sed -e "s|^$$srcdirstrip/||;t" \
- -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
- case $$dist_files in \
- */*) $(MKDIR_P) `echo "$$dist_files" | \
- sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
- sort -u` ;; \
- esac; \
- for file in $$dist_files; do \
- if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
- if test -d $$d/$$file; then \
- dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
- if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
- cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
- fi; \
- cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
- else \
- test -f $(distdir)/$$file \
- || cp -p $$d/$$file $(distdir)/$$file \
- || exit 1; \
- fi; \
- done
-check-am: all-am
-check: check-am
-all-am: Makefile $(PROGRAMS)
-installdirs:
- for dir in "$(DESTDIR)$(bindir)"; do \
- test -z "$$dir" || $(MKDIR_P) "$$dir"; \
- done
-install: install-am
-install-exec: install-exec-am
-install-data: install-data-am
-uninstall: uninstall-am
-
-install-am: all-am
- @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-
-installcheck: installcheck-am
-install-strip:
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- `test -z '$(STRIP)' || \
- echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
-mostlyclean-generic:
-
-clean-generic:
-
-distclean-generic:
- -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-
-maintainer-clean-generic:
- @echo "This command is intended for maintainers to use"
- @echo "it deletes files that may require special tools to rebuild."
-clean: clean-am
-
-clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
-
-distclean: distclean-am
- -rm -rf ./$(DEPDIR)
- -rm -f Makefile
-distclean-am: clean-am distclean-compile distclean-generic \
- distclean-tags
-
-dvi: dvi-am
-
-dvi-am:
-
-html: html-am
-
-info: info-am
-
-info-am:
-
-install-data-am:
-
-install-dvi: install-dvi-am
-
-install-exec-am: install-binPROGRAMS
-
-install-html: install-html-am
-
-install-info: install-info-am
-
-install-man:
-
-install-pdf: install-pdf-am
-
-install-ps: install-ps-am
-
-installcheck-am:
-
-maintainer-clean: maintainer-clean-am
- -rm -rf ./$(DEPDIR)
- -rm -f Makefile
-maintainer-clean-am: distclean-am maintainer-clean-generic
-
-mostlyclean: mostlyclean-am
-
-mostlyclean-am: mostlyclean-compile mostlyclean-generic
-
-pdf: pdf-am
-
-pdf-am:
-
-ps: ps-am
-
-ps-am:
-
-uninstall-am: uninstall-binPROGRAMS
-
-.MAKE: install-am install-strip
-
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
- clean-generic ctags distclean distclean-compile \
- distclean-generic distclean-tags distdir dvi dvi-am html \
- html-am info info-am install install-am install-binPROGRAMS \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-man install-pdf \
- install-pdf-am install-ps install-ps-am install-strip \
- installcheck installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-compile \
- mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
- uninstall-am uninstall-binPROGRAMS
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
View
109 src/bdd.cpp → src/bdd.cc
@@ -1,24 +1,24 @@
/*
* Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
* Pompidou - IRI
- *
- * This library is free software; you can redistribute it and/or modify it
+ *
+ * This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This library 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
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
- *
+ *
* * $Id: bdd.cpp 143 2007-04-03 14:43:56Z johmathe $ $Date: 2007-02-21
- * 10:58:30 +0100 (mer, 21 fév 2007) $
+ * 10:58:30 +0100 (mer, 21 fév 2007) $
*/
@@ -28,11 +28,10 @@
// http://casteyde.christian.free.fr/cpp/cours/online/c5501.html#AEN5702
// http://docs.postgresqlfr.org/8.1/libpq-exec.html
// http://www.postgresql.org/docs/8.1/interactive/libpq.html#LIBPQ-CONNECT
-//
+//
using namespace std;
-bdd::bdd (const string host, const string login, const string pwd, int port, const string base)
-{
+bdd::bdd (const string host, const string login, const string pwd, int port, const string base) {
string str_cx;
string query;
str_cx = "host=" + host;
@@ -46,11 +45,10 @@ bdd::bdd (const string host, const string login, const string pwd, int port, con
str_cx += base;
conn = PQconnectdb (str_cx.c_str ());
- if (PQntuples (result) != 1)
- {
- fprintf (stderr, "query to find oid of geometry didnt return 1 row!");
- exit (1);
- }
+ if (PQntuples (result) != 1) {
+ fprintf (stderr, "query to find oid of geometry didnt return 1 row!");
+ exit (1);
+ }
query = "SELECT MAX(id) FROM plan;";
result = PQexec (conn, query.c_str ());
f->id_plan = atoi (PQgetvalue (result, 0, 0));
@@ -60,40 +58,37 @@ bdd::bdd (const string host, const string login, const string pwd, int port, con
result = PQexec (conn, query.c_str ());
/*
- * insertion auteur
+ * insertion auteur
*/
- if (PQntuples (result))
- {
- fprintf (stderr, "L'auteur existe dans la base de données : récupération de l'id\n");
- f->author.id = atoi (PQgetvalue (result, 0, 0));
- fprintf (stderr, "ID auteur \t\t: %d\n", f->author.id);
-
- }
- else
- {
- fprintf (stderr, "L'auteur n'existe pas dans la base de données : insertion\n");
- query = "INSERT INTO auteur (prenom,nom) VALUES ('"; // %s','%s');
- // SELECT
- // MAX(id)
- // FROM
- // auteur;",
- // f->author.prenom, f->author.nom);
- result = PQexec (conn, query.c_str ());
- f->author.id = atoi (PQgetvalue (result, 0, 0));
- fprintf (stderr, "ID auteur \t\t: %d\n", f->author.id);
- }
+ if (PQntuples (result)) {
+ fprintf (stderr, "L'auteur existe dans la base de données : récupération de l'id\n");
+ f->author.id = atoi (PQgetvalue (result, 0, 0));
+ fprintf (stderr, "ID auteur \t\t: %d\n", f->author.id);
+
+ } else {
+ fprintf (stderr, "L'auteur n'existe pas dans la base de données : insertion\n");
+ query = "INSERT INTO auteur (prenom,nom) VALUES ('"; // %s','%s');
+ // SELECT
+ // MAX(id)
+ // FROM
+ // auteur;",
+ // f->author.prenom, f->author.nom);
+ result = PQexec (conn, query.c_str ());
+ f->author.id = atoi (PQgetvalue (result, 0, 0));
+ fprintf (stderr, "ID auteur \t\t: %d\n", f->author.id);
+ }
/*
- * relations nn
+ * relations nn
*/
query = "INSERT INTO nn_auteur_film (id_local,id_foreign,priority) VALUES "; // (%d,%d,0);",
// f->author.id, f->id);
result = PQexec (conn, query.c_str ());
/*
- * Titre du film
+ * Titre du film
*/
query = "INSERT INTO film_traduction (id,nom_lang,nom) VALUES ("; // %d,'%s','%s');",
@@ -104,35 +99,33 @@ bdd::bdd (const string host, const string login, const string pwd, int port, con
}
void
-bdd::updatebdd ()
-{
+bdd::updatebdd () {
int i;
char query[MAX_QUERY];
int min, sec, hr;
int mind, secd, hrd;
/*
- * Les transaction sont atomiques
+ * Les transaction sont atomiques
*/
list < shot >::iterator il;
- for (il = f->shots.begin (); il != f->shots.end (); il++)
- {
- sec = (int) (il->msbegin / 1000);
- min = sec / 60;
- hr = min / 60;
- min %= 60;
- sec %= 60;
-
- secd = (int) (il->msduration / 1000);
- mind = secd / 60;
- hrd = mind / 60;
- mind %= 60;
- secd %= 60;
- snprintf (query, MAX_QUERY, "INSERT INTO plan (id, id_film, timecode, duree, path_image) VALUES (%d,%d,'%d:%d:%d','%d:%d:%d','%d.jpg');INSERT INTO plan_traduction (id,id_film,nom_lang,titre) VALUES (%d,%d,'%s','plan %d');", i, f->id, hr, min, sec, hrd, mind, secd, i, i, f->id, f->code_lang.c_str (), i);
- result = PQexec (conn, query);
- free (result);
- i++;
- }
+ for (il = f->shots.begin (); il != f->shots.end (); il++) {
+ sec = (int) (il->msbegin / 1000);
+ min = sec / 60;
+ hr = min / 60;
+ min %= 60;
+ sec %= 60;
+
+ secd = (int) (il->msduration / 1000);
+ mind = secd / 60;
+ hrd = mind / 60;
+ mind %= 60;
+ secd %= 60;
+ snprintf (query, MAX_QUERY, "INSERT INTO plan (id, id_film, timecode, duree, path_image) VALUES (%d,%d,'%d:%d:%d','%d:%d:%d','%d.jpg');INSERT INTO plan_traduction (id,id_film,nom_lang,titre) VALUES (%d,%d,'%s','plan %d');", i, f->id, hr, min, sec, hrd, mind, secd, i, i, f->id, f->code_lang.c_str (), i);
+ result = PQexec (conn, query);
+ free (result);
+ i++;
+ }
}
bdd::~bdd ()
View
12 include/bdd.h → src/bdd.h
@@ -1,4 +1,4 @@
-/*
+/*
* $Id: bdd.h 100 2007-01-29 11:10:37Z johmathe $
* $Date: 2007-01-29 12:10:37 +0100 (Mon, 29 Jan 2007) $
*/
@@ -21,9 +21,7 @@ using namespace std;
class film;
-class bdd
-{
-
+class bdd {
private:
film * f;
@@ -35,9 +33,9 @@ class bdd
int port;
public:
- bdd (const string host, const string login, const string pwd, int port,
- const string base);
- ~bdd ();
+ bdd (const string host, const string login, const string pwd, int port,
+ const string base);
+ ~bdd ();
void init_bdd_values ();
void updatebdd ();
};
View
162 src/commandline.cc
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
+ * Pompidou - IRI This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either version
+ * 2.1 of the License, or (at your option) any later version. This
+ * library 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 Lesser General Public
+ * License for more details. You should have received a copy of the GNU
+ * Lesser General Public License along with this library; if not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA $Id: main.cpp 164 2007-10-13 23:53:21Z johmathe $
+ */
+#include <stdlib.h>
+
+#include "src/film.h"
+#include "src/xml.h"
+
+class xml;
+class film;
+
+//Example
+//Put the file you want to analyse in the same directory of shotdetect (it not mandatory but itÕs easier with the command line)
+
+//shotdetect -i myvideo.avi -o output_dir -s 60 -w -v -f -l -m -r
+
+//Options details
+//-s : set threshold
+//The threshold is the level for shot detection. High will not detect a lot, low will detect a lot of false shots. A good choice is about 60.
+
+//-w : generates audio xml informations
+//See the generated file for more details
+
+//-v : generates video xml informations
+//See the generated file for more details
+
+//-f : generates the first image of shots
+//-l : generates the last image of shots
+//-m : generates the thumbnails images
+//-r : generates the real size images
+
+void
+show_help (char **argv)
+{
+ printf ("usage: %s \n"
+ "Shotdetect (IRI - johmathe - $Id: main.cpp 164 2007-10-13 23:53:21Z johmathe $)\n"
+ "-h : show this help\n"
+ "-i file : input file path\n"
+ "-o path : output path\n"
+ "-s threshold : threshold\n"
+ "-w : generate xml of waveform\n"
+ "-v : generate xml of video infos\n"
+ "-f : generate first img for each shot\n"
+ "-l : generate last img for each shot\n"
+ "-m : generate the thumb img\n"
+ "-r : generate the real img\n", argv[0]);
+}
+
+
+
+int
+main (int argc, char **argv)
+{
+ extern char *optarg;
+ extern int optind, opterr, optopt;
+
+
+ film f = film ();
+
+ // Initialize threshold to a sensible default value
+ f.threshold=60;
+
+ for (;;) {
+ int c = getopt (argc, argv, "?ht:i:o:s:flwvmr");
+
+ if (c < 0) {
+ break;
+ }
+
+ switch (c) {
+ case '?':
+ case 'h':
+ show_help (argv);
+ exit (EXIT_SUCCESS);
+ break;
+
+ /* choix des thumbs */
+ case 'f':
+ f.set_first_img(true);
+ break;
+
+ case 'l':
+ f.set_last_img(true);
+ break;
+
+ /* generer l'image en resolution native */
+ case 'r':
+ f.set_shot(true);
+ break;
+
+ /* generer l'image en miniature */
+ case 'm':
+ f.set_thumb(true);
+ break;
+
+ /* generer le xml pour les donnees video */
+ case 'v':
+ f.set_video(true);
+ break;
+
+ /* generer le xml pour les donnees audio */
+ case 'w':
+ f.set_audio(true) ;
+ break;
+
+ /* Seuil */
+ case 's':
+ f.set_threshold(atoi (optarg));
+ break;
+
+ case 'i':
+ f.set_ipath(optarg);
+ break;
+
+ case 'o':
+ f.set_opath(optarg);
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ /* Traitement des erreurs */
+ if (f.get_ipath().empty()) {
+ cerr << "Please specify an input file" << endl;
+ show_help (argv);
+ exit(EXIT_FAILURE);
+ }
+ if (f.get_opath().empty()) {
+ cerr << "Please specify an output path" << endl;
+ show_help (argv);
+ exit(EXIT_FAILURE);
+ }
+
+ xml *x = new xml (&f);
+ f.x = x;
+
+ f.shotlog("Processing movie.");
+ f.process ();
+ string xml_path = f.global_path;
+ xml_path += "/result.xml";
+ f.x->write_data (xml_path);
+ /*string finished_path = f.global_path;
+ finished_path += "/finished";
+ FILE *fd_finished = fopen(finished_path.c_str(),"w");
+ fprintf(fd_finished, "0\n");
+ fclose(fd_finished);*/
+ exit (0);
+}
View
167 src/commandline.cpp
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
- * Pompidou - IRI This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either version
- * 2.1 of the License, or (at your option) any later version. This
- * library 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 Lesser General Public
- * License for more details. You should have received a copy of the GNU
- * Lesser General Public License along with this library; if not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA $Id: main.cpp 164 2007-10-13 23:53:21Z johmathe $
- */
-
-#include <film.h>
-#include <stdlib.h>
-#include <xml.h>
-
-class xml;
-class film;
-
-//Example
-//Put the file you want to analyse in the same directory of shotdetect (it not mandatory but itÕs easier with the command line)
-
-//shotdetect -i myvideo.avi -o output_dir -s 60 -w -v -f -l -m -r
-
-//Options details
-//-s : set threshold
-//The threshold is the level for shot detection. High will not detect a lot, low will detect a lot of false shots. A good choice is about 60.
-
-//-w : generates audio xml informations
-//See the generated file for more details
-
-//-v : generates video xml informations
-//See the generated file for more details
-
-//-f : generates the first image of shots
-//-l : generates the last image of shots
-//-m : generates the thumbnails images
-//-r : generates the real size images
-
- void
-show_help (char **argv)
-{
- printf ("usage: %s \n"
- "Shotdetect (IRI - johmathe - $Id: main.cpp 164 2007-10-13 23:53:21Z johmathe $)\n"
- "-h : show this help\n"
- "-i file : input file path\n"
- "-o path : output path\n"
- "-s threshold : threshold\n"
- "-w : generate xml of waveform\n"
- "-v : generate xml of video infos\n"
- "-f : generate first img for each shot\n"
- "-l : generate last img for each shot\n"
- "-m : generate the thumb img\n"
- "-r : generate the real img\n", argv[0]);
-}
-
-
-
-int
-main (int argc, char **argv)
-{
- extern char *optarg;
- extern int optind, opterr, optopt;
-
-
- film f = film ();
-
- // Initialize threshold to a sensible default value
- f.threshold=60;
-
- for (;;)
- {
- int c = getopt (argc, argv, "?ht:i:o:s:flwvmr");
-
- if (c < 0)
- {
- break;
- }
-
- switch (c)
- {
- case '?':
- case 'h':
- show_help (argv);
- exit (EXIT_SUCCESS);
- break;
-
- /* choix des thumbs */
- case 'f':
- f.set_first_img(true);
- break;
-
- case 'l':
- f.set_last_img(true);
- break;
-
- /* generer l'image en resolution native */
- case 'r':
- f.set_shot(true);
- break;
-
- /* generer l'image en miniature */
- case 'm':
- f.set_thumb(true);
- break;
-
- /* generer le xml pour les donnees video */
- case 'v':
- f.set_video(true);
- break;
-
- /* generer le xml pour les donnees audio */
- case 'w':
- f.set_audio(true) ;
- break;
-
- /* Seuil */
- case 's':
- f.set_threshold(atoi (optarg));
- break;
-
- case 'i':
- f.set_ipath(optarg);
- break;
-
- case 'o':
- f.set_opath(optarg);
- break;
-
- default:
- break;
- }
-
- }
-
- /* Traitement des erreurs */
- if (f.get_ipath().empty())
- {
- cerr << "Please specify an input file" << endl;
- show_help (argv);
- exit(EXIT_FAILURE);
- }
- if (f.get_opath().empty())
- {
- cerr << "Please specify an output path" << endl;
- show_help (argv);
- exit(EXIT_FAILURE);
- }
-
- xml *x = new xml (&f);
- f.x = x;
-
- f.shotlog("Processing movie.");
- f.process ();
- string xml_path = f.global_path;
- xml_path += "/result.xml";
- f.x->write_data (xml_path);
- /*string finished_path = f.global_path;
- finished_path += "/finished";
- FILE *fd_finished = fopen(finished_path.c_str(),"w");
- fprintf(fd_finished, "0\n");
- fclose(fd_finished);*/
- exit (0);
-}
View
111 src/conf.cpp → src/conf.cc
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
- * Pompidou - IRI This library is free software; you can redistribute it
+ * Pompidou - IRI This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version. This
@@ -8,10 +8,10 @@
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details. You should have received a copy of the GNU
- * Lesser General Public License along with this library; if not, write to
+ * Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA $Id: conf.cpp 114 2007-02-21 09:58:30Z
- * johmathe $ $Date: 2007-04-03 16:43:56 +0200 (Tue, 03 Apr 2007) $
+ * johmathe $ $Date: 2007-04-03 16:43:56 +0200 (Tue, 03 Apr 2007) $
*/
#include "conf.h"
@@ -21,7 +21,7 @@ extern char *conf_file;
conf_data conf;
/*
- * the single conf used while parsing
+ * the single conf used while parsing
*/
string_key_value_pair possible_values[] = {
{"DB_PORT", &conf.portc, 7},
@@ -45,71 +45,54 @@ conf::conf ()
char line[1024];
printf ("conf file \t\t: %s\n", conf_file);
fd = fopen (conf_file, "r");
- if (!fd)
- {
- perror ("open file ");
- }
+ if (!fd) {
+ perror ("open file ");
+ }
- if (fd != NULL)
- {
- while (fgets ((char *) line, sizeof (line), fd) != NULL)
- {
- size = strspn (line, " \t\n\v");
- if (line[size] == '#')
- {
- }
- else
- {
- for (sk = (struct string_key_value_pair *) possible_values; sk->sk_key != NULL; sk++)
- {
- /*
- * Compariaison et récupération de la clé
- */
- if (strncmp (line + size, sk->sk_key, sk->size) == 0)
- {
- valuesize = strcspn (line + size + sk->size + 1, " \n\t");
- /*
- * Allocation mémoire, bien sur, on fait ca
- * proprement, On checke s'il n'existe pas de
- * valeur par défaut
- */
+ if (fd != NULL) {
+ while (fgets ((char *) line, sizeof (line), fd) != NULL) {
+ size = strspn (line, " \t\n\v");
+ if (line[size] == '#') {
+ } else {
+ for (sk = (struct string_key_value_pair *) possible_values; sk->sk_key != NULL; sk++) {
+ /*
+ * Compariaison et récupération de la clé
+ */
+ if (strncmp (line + size, sk->sk_key, sk->size) == 0) {
+ valuesize = strcspn (line + size + sk->size + 1, " \n\t");
+ /*
+ * Allocation mémoire, bien sur, on fait ca
+ * proprement, On checke s'il n'existe pas de
+ * valeur par défaut
+ */
- if (*(sk->sk_value) != NULL)
- {
- realloc (*(sk->sk_value), valuesize * sizeof (char) + 1);
- }
- else
- {
- *(sk->sk_value) = (char *) malloc (valuesize * sizeof (char) + 1);
- }
+ if (*(sk->sk_value) != NULL) {
+ realloc (*(sk->sk_value), valuesize * sizeof (char) + 1);
+ } else {
+ *(sk->sk_value) = (char *) malloc (valuesize * sizeof (char) + 1);
+ }
- /*
- * Mise en place de la valeur
- */
+ /*
+ * Mise en place de la valeur
+ */
- strncpy (*(sk->sk_value), line + size + sk->size + 1, valuesize);
- (*(sk->sk_value))[valuesize] = 0;
- }
- }
- }
- }
- }
- if (conf.portc != NULL)
- {
- conf.port = atoi (conf.portc);
- }
- else
- {
- conf.port = DEFAULT_BDD_PORT;
- }
- if (conf.thumb_heightc != NULL)
- {
- conf.thumb_height = atoi (conf.thumb_heightc);
- }
- else
- {
- conf.thumb_height = DEFAULT_THUMB_HEIGHT;
+ strncpy (*(sk->sk_value), line + size + sk->size + 1, valuesize);
+ (*(sk->sk_value))[valuesize] = 0;
+ }
+ }
+ }
}
+ }
+ if (conf.portc != NULL) {
+ conf.port = atoi (conf.portc);
+ } else {
+ conf.port = DEFAULT_BDD_PORT;
+ }
+ if (conf.thumb_heightc != NULL) {
+ conf.thumb_height = atoi (conf.thumb_heightc);
+ } else {
+ conf.thumb_height = DEFAULT_THUMB_HEIGHT;
+ }
fprintf (stderr, "thumb size \t\t: %d\n", conf.thumb_height);
fprintf (stderr, "bdd host :\t\t: %s\nport \t\t\t: %d\n", conf.host, conf.port);
fprintf (stderr, "parsing Conf file \t: OK.\n");
View
8 include/conf.h → src/conf.h
@@ -1,4 +1,4 @@
-/*
+/*
* $Id: conf.h 100 2007-01-29 11:10:37Z johmathe $
* $Date: 2007-01-29 12:10:37 +0100 (Mon, 29 Jan 2007) $
*/
@@ -13,7 +13,7 @@ class conf
{
public:
-/* Config struct */
+ /* Config struct */
string portc;
string host;
string login;
@@ -27,8 +27,8 @@ class conf
int port;
- conf ();
- ~conf ();
+ conf ();
+ ~conf ();
};
View
656 src/film.cc
@@ -0,0 +1,656 @@
+/*
+ * Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
+ * Pompfidou - IRI This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either version
+ * 2.1 of the License, or (at your option) any later version. This
+ * library 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 Lesser General Public
+ * License for more details. You should have received a copy of the GNU
+ * Lesser General Public License along with this library; if not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA $Id: film.cpp 141 2007-04-02 16:10:53Z
+ * johmathe $ $Date: 2010-10-01 01:35:11 +0200 (Fri, 01 Oct 2010) $
+ */
+
+#ifdef WXWIDGETS
+#include <wx/msgdlg.h>
+#include <wx/thread.h>
+#include "src/ui/dialog_shotdetect.h"
+#endif
+
+#include <sys/time.h>
+#include <time.h>
+extern "C" {
+#include <libswscale/swscale.h>
+}
+#include "src/film.h"
+#include "src/graph.h"
+
+#define DEBUG
+
+int film::idfilm = 0;
+
+void film::do_stats (int frame_number)
+{
+ double perctmp = percent;
+ struct timeval time_now;
+ struct timezone timezone;
+ gettimeofday (&time_now, &timezone);
+
+#ifdef WXWIDGETS
+ int time_elapsed = time_now.tv_sec - dialogParent->time_start.tv_sec;
+
+ if (dialogParent->get_time_elapsed () != time_elapsed) {
+ wxMutexGuiEnter ();
+ dialogParent->set_time_elapsed (time_elapsed);
+ wxMutexGuiLeave ();
+ }
+
+ percent = ((frame_number) / (fps * (duration.mstotal / 100000)));
+
+ if (int (percent) != int (perctmp) || !show_started) {
+ double val_global = percent / idfilm + double (progress_state_prev);
+ wxMutexGuiEnter ();
+ dialogParent->set_progress_local (percent);
+ dialogParent->set_progress_global (val_global);
+ wxMutexGuiLeave ();
+ }
+#endif
+ show_started = 1;
+}
+
+void film::create_main_dir ()
+{
+ ostringstream str;
+ struct stat *buf;
+ str.str ("");
+ str << this->global_path << "/" << this->alphaid;
+
+ buf = (struct stat *) malloc (sizeof (struct stat));
+ if (stat (str.str ().c_str (), buf) == -1) {
+#if defined(__WINDOWS__ ) || defined(__MINGW32__)
+ mkdir (str.str ().c_str ());
+#else
+ mkdir (str.str ().c_str (), 0777);
+#endif
+ }
+}
+
+void film::CompareFrame (AVFrame * pFrame, AVFrame * pFramePrev)
+{
+ int y;
+ int x;
+ int diff;
+ int frame_number = pCodecCtx->frame_number;
+ char c1, c2, c3;
+ int c1tot, c2tot, c3tot;
+ c1tot = 0;
+ c2tot = 0;
+ c3tot = 0;
+ char c1prev, c2prev, c3prev;
+ int score;
+ score = 0;
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+
+ c1 = (char) *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3);
+ c2 = (char) *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3 + 1);
+ c3 = (char) *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3 + 2);
+
+ c1prev = (char) *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3);
+ c2prev = (char) *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3 + 1);
+ c3prev = (char) *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3 + 2);
+ c1tot += int (c1 + 127);
+ c2tot += int (c2 + 127);
+ c3tot += int (c3 + 127);
+ score += abs ((c1 - c1prev));
+ score += abs ((c2 - c2prev));
+ score += abs ((c3 - c3prev));
+ }
+ }
+ int nbpx = (height * width);
+
+ /*
+ * On se ramene à la moyenne
+ */
+ score /= nbpx;
+ c1tot /= nbpx;
+ c2tot /= nbpx;
+ c3tot /= nbpx;
+
+ /*
+ * Derivee numerique
+ */
+ diff = abs (score - prev_score);
+ prev_score = score;
+
+ g->push_data (score, c1tot, c2tot, c3tot);
+
+ if (diff > this->threshold && score > this->threshold) {
+ shot s;
+ s.fbegin = frame_number;
+ s.msbegin = int ((frame_number * 1000) / fps);
+ s.myid = shots.back ().myid + 1;
+
+#ifdef DEBUG
+ cerr << "Shot log :: " << s.msbegin << endl;
+#endif
+
+ /*
+ * Convert to ms
+ */
+ shots.back ().fduration = frame_number - shots.back ().fbegin;
+ shots.back ().msduration = int (((shots.back ().fduration) * 1000) / fps);
+
+ /*
+ * Create images if necessary
+ */
+#ifdef WXWIDGETS
+ if (this->first_img_set || (display && dialogParent->checkbox_1->GetValue ()))
+#else
+ if (this->first_img_set)
+#endif
+ {
+ image *im_begin = new image (this, width, height, s.myid, BEGIN, this->thumb_set, this->shot_set);
+ im_begin->SaveFrame (pFrame, frame_number);
+ s.img_begin = im_begin;
+ }
+
+#ifdef WXWIDGETS
+ if (this->last_img_set || (display && dialogParent->checkbox_2->GetValue ()))
+#else
+ if (this->last_img_set)
+#endif
+ {
+ image *im_end = new image (this, width, height, s.myid - 1, END, this->thumb_set, this->shot_set);
+ im_end->SaveFrame (pFramePrev, frame_number);
+ shots.back ().img_end = im_end;
+
+ }
+ shots.push_back (s);
+
+ /*
+ * updating display
+ */
+#ifdef WXWIDGETS
+ wxString nbshots;
+ nbshots << shots.size ();
+ if (display) {
+ wxMutexGuiEnter ();
+ dialogParent->list_films->SetItem (0, 1, nbshots);
+ wxMutexGuiLeave ();
+ }
+#endif
+ }
+}
+
+void film::update_metadata ()
+{
+ char buf[256];
+ /* Video metadata */
+ if (videoStream != -1) {
+ this->height = int (pFormatCtx->streams[videoStream]->codec->height);
+ this->width = int (pFormatCtx->streams[videoStream]->codec->width);
+ this->fps = av_q2d (pFormatCtx->streams[videoStream]->r_frame_rate);
+ avcodec_string (buf, sizeof (buf), pFormatCtx->streams[videoStream]->codec, 0);
+ this->codec.video = buf;
+
+ } else {
+ this->codec.video = "null";
+ this->height = 0;
+ this->width = 0;
+ this->fps = 0;
+ }
+
+ /* Audio metadata */
+ if (audioStream != -1) {
+ avcodec_string (buf, sizeof (buf), pCodecCtxAudio, 0);
+ this->codec.audio = buf;
+ this->nchannel = pCodecCtxAudio->channels;
+ this->samplerate = pCodecCtxAudio->sample_rate;
+ } else {
+ this->codec.audio = "null";
+ this->nchannel = 0;
+ this->samplerate = 0;
+ }
+
+ duration.secs = pFormatCtx->duration / AV_TIME_BASE;
+ duration.us = pFormatCtx->duration % AV_TIME_BASE;
+ duration.mstotal = int (duration.secs * 1000 + duration.us / 1000);
+ duration.mins = duration.secs / 60;
+ duration.secs %= 60;
+ duration.hours = duration.mins / 60;
+ duration.mins %= 60;
+
+}
+
+void film::shotlog (string message)
+{
+#ifdef WXWIDGETS
+ if (display) {
+ wxString mess;
+ mess = wxString (wxString::FromAscii (message.c_str ()));
+ wxMutexGuiEnter ();
+ wxMessageDialog MsgDlg (dialogParent, mess);
+ MsgDlg.ShowModal ();
+ wxMutexGuiLeave ();
+ } else
+#endif
+ {
+ cerr << "Shot log :: " << message << endl;
+ }
+}
+
+int film::process ()
+{
+ int audioSize;
+ uint8_t *buffer;
+ uint8_t *buffer2;
+ int frameFinished;
+ int numBytes;
+ shot s;
+ static struct SwsContext *img_convert_ctx = NULL;
+ int frame_number;
+
+ create_main_dir ();
+
+ string graphpath = this->global_path + "/" + this->alphaid;
+ g = new graph (600, 400, graphpath, threshold, this);
+ g->set_title ("Quantité de mouvement en fonction de la frame");
+
+ /*
+ * Register all formats and codecs
+ */
+ av_register_all ();
+
+ if (av_open_input_file (&pFormatCtx, input_path.c_str (), NULL, 0, NULL) != 0) {
+ string error_msg = "Could not open file ";
+ error_msg += input_path;
+ shotlog (error_msg);
+ return -1; // Couldn't open file
+ }
+
+ /*
+ * Retrieve stream information
+ */
+ if (av_find_stream_info (pFormatCtx) < 0)
+ return -1; // Couldn't find stream information
+
+
+ // dump_format (pFormatCtx, 0, input_path.c_str (), false);
+ videoStream = -1;
+ audioStream = -1;
+
+
+ /*
+ * Detect streams types
+ */
+ for (int j = 0; j < pFormatCtx->nb_streams; j++) {
+ switch (pFormatCtx->streams[j]->codec->codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ videoStream = j;
+ break;
+
+ case AVMEDIA_TYPE_AUDIO:
+ audioStream = j;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+
+
+ /*
+ * Get a pointer to the codec context for the video stream
+ */
+ if (audioStream != -1) {
+ if (audio_set) {
+ string xml_audio = graphpath + "/" + alphaid + "_audio.xml";
+ init_xml (xml_audio);
+ }
+
+ pCodecCtxAudio = pFormatCtx->streams[audioStream]->codec;
+ pCodecAudio = avcodec_find_decoder (pCodecCtxAudio->codec_id);
+
+ if (pCodecAudio == NULL)
+ return -1; // Codec not found
+ if (avcodec_open (pCodecCtxAudio, pCodecAudio) < 0)
+ return -1; // Could not open codec
+
+ }
+ update_metadata ();
+ /*
+ * Find the decoder for the video stream
+ */
+ if (videoStream != -1) {
+ pCodecCtx = pFormatCtx->streams[videoStream]->codec;
+ pCodec = avcodec_find_decoder (pCodecCtx->codec_id);
+
+ if (pCodec == NULL)
+ return -1; // Codec not found
+ if (avcodec_open (pCodecCtx, pCodec) < 0)
+ return -1; // Could not open codec
+
+ /*
+ * Allocate video frame
+ */
+ pFrame = avcodec_alloc_frame ();
+ pFrameRGB = avcodec_alloc_frame ();
+ pFrameRGBprev = avcodec_alloc_frame ();
+
+ /*
+ * Determine required buffer size and allocate buffer
+ */
+ numBytes = avpicture_get_size (PIX_FMT_RGB24, width, height);
+
+ buffer = (uint8_t *) malloc (sizeof (uint8_t) * numBytes);
+ buffer2 = (uint8_t *) malloc (sizeof (uint8_t) * numBytes);
+
+ /*
+ * Assign appropriate parts of buffer to image planes in pFrameRGB
+ */
+ avpicture_fill ((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGB24, width, height);
+
+ avpicture_fill ((AVPicture *) pFrameRGBprev, buffer2, PIX_FMT_RGB24, width, height);
+
+
+ /*
+ * Mise en place du premier plan
+ */
+ s.fbegin = 0;
+ s.msbegin = 0;
+ s.myid = 0;
+ shots.push_back (s);
+
+
+
+ }
+
+#ifdef WXWIDGETS
+ wxString fduration;
+ fduration << duration.hours << wxT (":") << duration.mins << wxT (":") << duration.secs << wxT (":") << duration.us;
+
+ if (display) {
+ wxMutexGuiEnter ();
+ dialogParent->list_films->SetItem (0, 2, fduration);
+ wxMutexGuiLeave ();
+ }
+#endif
+
+ checknumber = (samplerate * samplearg) / 1000;
+
+ /*
+ * Main loop to control the movie processing flow
+ */
+ while (av_read_frame (pFormatCtx, &packet) >= 0) {
+ if (packet.stream_index == videoStream) {
+ // DEPRECATED: avcodec_decode_video (pCodecCtx, pFrame, &frameFinished, packet.data, packet.size);
+ avcodec_decode_video2 (pCodecCtx, pFrame, &frameFinished, &packet);
+
+ if (frameFinished) {
+ frame_number = pCodecCtx->frame_number; // Current frame number
+
+ // Convert the image into RGB24
+ if (! img_convert_ctx) {
+ img_convert_ctx = sws_getContext(width, height, pCodecCtx->pix_fmt,
+ width, height, PIX_FMT_RGB24, SWS_BICUBIC,
+ NULL, NULL, NULL);
+ if (! img_convert_ctx) {
+ fprintf(stderr, "Cannot initialize the conversion context!\n");
+ exit(1);
+ }
+ }
+
+ /* API: int sws_scale(SwsContext *c, uint8_t *src, int srcStride[], int srcSliceY, int srcSliceH, uint8_t dst[], int dstStride[] )
+ */
+ sws_scale(img_convert_ctx, pFrame->data,
+ pFrame->linesize, 0,
+ pCodecCtx->height,
+ pFrameRGB->data, pFrameRGB->linesize);
+
+ /*
+ Old API doc (cf http://www.dranger.com/ffmpeg/functions.html )
+ int img_convert(AVPicture *dst, int dst_pix_fmt,
+ const AVPicture *src, int src_pix_fmt,
+ int src_width, int src_height)
+ */
+ /*
+ img_convert ((AVPicture *) pFrameRGB, PIX_FMT_RGB24, (AVPicture *) pFrame, pCodecCtx->pix_fmt, width, height);
+ */
+
+ /* If it's not the first image */
+ if ( frame_number != 1) {
+ CompareFrame (pFrameRGB, pFrameRGBprev);
+ } else {
+ /*
+ * Cas ou c'est la premiere image, on cree la premiere image dans tous les cas
+ */
+ image *begin_i = new image (this, width, height, s.myid, BEGIN, this->thumb_set, this->shot_set);
+ begin_i->create_img_dir ();
+
+#ifdef WXWIDGETS
+ if (this->first_img_set || (display && dialogParent->checkbox_1->GetValue ()))
+#else
+ if (this->first_img_set)
+#endif
+ {
+ begin_i->SaveFrame (pFrameRGB, frame_number);
+ shots.back ().img_begin = begin_i;
+ }
+ }
+ memcpy (buffer2, buffer, numBytes);
+ if (display)
+ do_stats (pCodecCtx->frame_number);
+ }
+ }
+ if (audio_set && (packet.stream_index == audioStream)) {
+ process_audio ();
+ }
+ /*
+ * Free the packet that was allocated by av_read_frame
+ */
+ if (packet.data != NULL)
+ av_free_packet (&packet);
+ }
+
+ if (videoStream != -1) {
+ /* Mise en place de la dernière image */
+ shots.back ().fduration = pFrame->coded_picture_number - shots.back ().fbegin;
+ shots.back ().msduration = int (((shots.back ().fduration) * 1000) / fps);
+ duration.mstotal = int (shots.back ().msduration + shots.back ().msbegin);
+#ifdef WXWIDGETS
+ if (this->last_img_set || (display && dialogParent->checkbox_2->GetValue ()))
+#else
+ if (this->last_img_set)
+#endif
+ {
+ image *end_i = new image (this, width, height, shots.back ().myid, END,
+ this->thumb_set, this->shot_set);
+ end_i->SaveFrame (pFrameRGB, frame_number);
+ shots.back ().img_end = end_i;
+ }
+
+ /*
+ * Graph 'quantity of movement'
+ */
+ g->init_gd ();
+ g->draw_all_canvas ();
+ g->draw_color_datas ();
+ g->draw_datas ();
+ if (video_set) {
+ string xml_color = graphpath + "/" + alphaid + "_video.xml";
+ g->write_xml (xml_color);
+ }
+ g->save ();
+
+ /*
+ * Free the RGB images
+ */
+ free (buffer);
+ free (buffer2);
+ av_free (pFrameRGB);
+ av_free (pFrame);
+ av_free (pFrameRGBprev);
+ avcodec_close (pCodecCtx);
+ }
+ /*
+ * Close the codec
+ */
+ if (audioStream != -1) {
+ /* Close the XML file */
+ if (audio_set) close_xml ();
+ avcodec_close (pCodecCtxAudio);
+ }
+
+ /*
+ * Close the video file
+ */
+ av_close_input_file (pFormatCtx);
+
+
+}
+
+void film::init_xml (string filename)
+{
+ fd_xml_audio = fopen (filename.c_str (), "w");
+ // FIXME: This may produce an uncaught segmentation fault if the output path doesn't exist:
+ fprintf (fd_xml_audio, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<iri>\n<sound sampling=\"%d\" nchannels=\"%d\">", samplearg, nchannel);
+}
+
+int film::close_xml ()
+{
+ fprintf (fd_xml_audio, "</sound>\n</iri>");
+ return (fclose (fd_xml_audio));
+}
+
+
+void film::process_audio ()
+{
+ int len1;
+ int len;
+ int data_size;
+ static unsigned int samples_size = 0;
+ int i;
+ uint8_t *ptr;
+
+ ptr = packet.data;
+ len = packet.size;
+
+ while (len > 0) {
+ this->audio_buf = (short *) av_fast_realloc (this->audio_buf, &samples_size, FFMAX (packet.size, AVCODEC_MAX_AUDIO_FRAME_SIZE));
+ data_size = samples_size;
+ // DEPRECATED: len1 = avcodec_decode_audio (pCodecCtxAudio, audio_buf, &data_size, ptr, len);
+ len1 = avcodec_decode_audio3 (pCodecCtxAudio, audio_buf, &data_size, &packet);
+
+
+ if (len1 < 0) {
+ /*
+ * Error, breaking the frame
+ */
+ len = 0;
+ break;
+ }
+
+ len -= len1;
+ ptr += len1;
+
+ if (data_size > 0) {
+
+ samples += data_size / (pCodecCtxAudio->channels * 2);
+ for (i = 0; i < data_size; i += 2 * pCodecCtxAudio->channels) {
+ sample_right = *((signed short int *) (audio_buf + i));
+ /*
+ * If it's only one channel: right sample = left sample
+ */
+ if (pCodecCtxAudio->channels >= 1)
+ sample_left = *((signed short int *) (audio_buf + i + 2));
+ else
+ sample_left = sample_right;
+
+ /*
+ * Update minimum/maximum values:
+ */
+ if (minright > sample_right)
+ minright = sample_right;
+ if (maxright < sample_right)
+ maxright = sample_right;
+ if (minleft > sample_left)
+ minleft = sample_left;
+ if (maxleft < sample_left)
+ maxleft = sample_left;
+
+ /*
+ * Get sample
+ */
+ if (ech++ == checknumber) {
+ if (minright > minleft)
+ minright = minleft;
+ if (maxright > maxleft)
+ maxright = maxleft;
+ fprintf (fd_xml_audio, "<v c1d =\"%d\" c1u=\"%d\" />\n", minright / RATIO, maxright / RATIO);
+ minright = MAX_INT;
+ maxright = MIN_INT;
+ minleft = MAX_INT;
+ maxleft = MIN_INT;
+
+ /*
+ * Reset sample number
+ */
+ ech = 0;
+ }
+ }
+ }
+ }
+}
+
+#ifdef WXWIDGETS
+film::film (DialogShotDetect * d)
+{
+ // Initialization of values for the GUI
+ myid = idfilm;
+ idfilm++;
+ dialogParent = d;
+ progress_state_prev = dialogParent->GetGlobalProgress ();
+ show_started = true;
+ percent = 0;
+
+ display = 1;
+ threshold = DEFAULT_THRESHOLD;
+ samplearg = 1000;
+ samples = 0;
+ minright = MAX_INT;
+ maxright = MIN_INT;
+ minleft = MAX_INT;
+ maxleft = MIN_INT;
+ ech = 0;
+ nchannel = 1;
+ audio_buf = NULL;
+}
+#endif
+
+film::film()
+{
+ // Initialization of default values (non GUI)
+ display = 0;
+ threshold = DEFAULT_THRESHOLD;
+ samplearg = 1000;
+ samples = 0;
+ minright = MAX_INT;
+ maxright = MIN_INT;
+ minleft = MAX_INT;
+ maxleft = MIN_INT;
+ ech = 0;
+ nchannel = 1;
+ audio_buf = NULL;
+
+ this->first_img_set = false;
+ this->last_img_set = false;
+ this->audio_set = false;
+ this->video_set = false;
+ this->thumb_set = false;
+ this->shot_set = false;
+}
View
697 src/film.cpp
@@ -1,697 +0,0 @@
-/*
- * Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
- * Pompfidou - IRI This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either version
- * 2.1 of the License, or (at your option) any later version. This
- * library 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 Lesser General Public
- * License for more details. You should have received a copy of the GNU
- * Lesser General Public License along with this library; if not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA $Id: film.cpp 141 2007-04-02 16:10:53Z
- * johmathe $ $Date: 2010-10-01 01:35:11 +0200 (Fri, 01 Oct 2010) $
- */
-#include <sys/time.h>
-#include <time.h>
-#include "film.h"
-#include "graph.h"
-extern "C" {
-#include <libswscale/swscale.h>
-}
-
-#ifdef WXWIDGETS
-#include "DialogShotDetect_c.h"
-#include <wx/thread.h>
-#include <wx/msgdlg.h>
-#endif
-
-#define DEBUG
-
-int film::idfilm = 0;
-
-void film::do_stats (int frame_number)
-{
- double perctmp = percent;
- struct timeval time_now;
- struct timezone timezone;
- gettimeofday (&time_now, &timezone);
-
- #ifdef WXWIDGETS
- int time_elapsed = time_now.tv_sec - dialogParent->time_start.tv_sec;
-
- if (dialogParent->get_time_elapsed () != time_elapsed)
- {
- wxMutexGuiEnter ();
- dialogParent->set_time_elapsed (time_elapsed);
- wxMutexGuiLeave ();
- }
-
- percent = ((frame_number) / (fps * (duration.mstotal / 100000)));
-
- if (int (percent) != int (perctmp) || !show_started)
- {
- double val_global = percent / idfilm + double (progress_state_prev);
- wxMutexGuiEnter ();
- dialogParent->set_progress_local (percent);
- dialogParent->set_progress_global (val_global);
- wxMutexGuiLeave ();
- }
- #endif
- show_started = 1;
-}
-
-void film::create_main_dir ()
-{
- ostringstream str;
- struct stat *buf;
- str.str ("");
- str << this->global_path << "/" << this->alphaid;
-
- buf = (struct stat *) malloc (sizeof (struct stat));
- if (stat (str.str ().c_str (), buf) == -1)
- {
-#if defined(__WINDOWS__ ) || defined(__MINGW32__)
- mkdir (str.str ().c_str ());
-#else
- mkdir (str.str ().c_str (), 0777);
-#endif
-
- }
-
-
-}
-
-void film::CompareFrame (AVFrame * pFrame, AVFrame * pFramePrev)
-{
- int y;
- int x;
- int diff;
- int frame_number = pCodecCtx->frame_number;
- char c1, c2, c3;
- int c1tot, c2tot, c3tot;
- c1tot = 0;
- c2tot = 0;
- c3tot = 0;
- char c1prev, c2prev, c3prev;
- int score;
- score = 0;
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- {
-
- c1 = (char) *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3);
- c2 = (char) *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3 + 1);
- c3 = (char) *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3 + 2);
-
- c1prev = (char) *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3);
- c2prev = (char) *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3 + 1);
- c3prev = (char) *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3 + 2);
- c1tot += int (c1 + 127);
- c2tot += int (c2 + 127);
- c3tot += int (c3 + 127);
- score += abs ((c1 - c1prev));
- score += abs ((c2 - c2prev));
- score += abs ((c3 - c3prev));
- }
- }
- int nbpx = (height * width);
-
- /*
- * On se ramene à la moyenne
- */
- score /= nbpx;
- c1tot /= nbpx;
- c2tot /= nbpx;
- c3tot /= nbpx;
-
- /*
- * Derivee numerique
- */
- diff = abs (score - prev_score);
- prev_score = score;
-
- g->push_data (score, c1tot, c2tot, c3tot);
-
- if (diff > this->threshold && score > this->threshold)
- {
- shot s;
- s.fbegin = frame_number;
- s.msbegin = int ((frame_number * 1000) / fps);
- s.myid = shots.back ().myid + 1;
-
-#ifdef DEBUG
- cerr << "Shot log :: " << s.msbegin << endl;
-#endif
-
- /*
- * Convert to ms
- */
- shots.back ().fduration = frame_number - shots.back ().fbegin;
- shots.back ().msduration = int (((shots.back ().fduration) * 1000) / fps);
-
- /*
- * Create images if necessary
- */
- #ifdef WXWIDGETS
- if (this->first_img_set || (display && dialogParent->checkbox_1->GetValue ()))
- #else
- if (this->first_img_set)
- #endif
- {
- image *im_begin = new image (this, width, height, s.myid, BEGIN, this->thumb_set, this->shot_set);
- im_begin->SaveFrame (pFrame, frame_number);
- s.img_begin = im_begin;
- }
-
- #ifdef WXWIDGETS
- if (this->last_img_set || (display && dialogParent->checkbox_2->GetValue ()))
- #else
- if (this->last_img_set)
- #endif
- {
- image *im_end = new image (this, width, height, s.myid - 1, END, this->thumb_set, this->shot_set);
- im_end->SaveFrame (pFramePrev, frame_number);
- shots.back ().img_end = im_end;
-
- }
- shots.push_back (s);
-
- /*
- * updating display
- */
- #ifdef WXWIDGETS
- wxString nbshots;
- nbshots << shots.size ();
- if (display)
- {
- wxMutexGuiEnter ();
- dialogParent->list_films->SetItem (0, 1, nbshots);
- wxMutexGuiLeave ();
- }
- #endif
- }
-}
-
-void film::update_metadata ()
-{
- char buf[256];
- /* Video metadata */
- if (videoStream != -1)
- {
- this->height = int (pFormatCtx->streams[videoStream]->codec->height);
- this->width = int (pFormatCtx->streams[videoStream]->codec->width);
- this->fps = av_q2d (pFormatCtx->streams[videoStream]->r_frame_rate);
- avcodec_string (buf, sizeof (buf), pFormatCtx->streams[videoStream]->codec, 0);
- this->codec.video = buf;
-
- }
- else
- {
- this->codec.video = "null";
- this->height = 0;
- this->width = 0;
- this->fps = 0;
- }
-
- /* Audio metadata */
- if (audioStream != -1)
- {
- avcodec_string (buf, sizeof (buf), pCodecCtxAudio, 0);
- this->codec.audio = buf;
- this->nchannel = pCodecCtxAudio->channels;
- this->samplerate = pCodecCtxAudio->sample_rate;
- }
- else
- {
- this->codec.audio = "null";
- this->nchannel = 0;
- this->samplerate = 0;
- }
-
- duration.secs = pFormatCtx->duration / AV_TIME_BASE;
- duration.us = pFormatCtx->duration % AV_TIME_BASE;
- duration.mstotal = int (duration.secs * 1000 + duration.us / 1000);
- duration.mins = duration.secs / 60;
- duration.secs %= 60;
- duration.hours = duration.mins / 60;
- duration.mins %= 60;
-
-}
-
-void film::shotlog (string message)
-{
- #ifdef WXWIDGETS
- if (display)
- {
- wxString mess;
- mess = wxString (wxString::FromAscii (message.c_str ()));
- wxMutexGuiEnter ();
- wxMessageDialog MsgDlg (dialogParent, mess);
- MsgDlg.ShowModal ();
- wxMutexGuiLeave ();
- }
- else
- #endif
- {
- cerr << "Shot log :: " << message << endl;
- }
-}
-
-int film::process ()
-{
- int audioSize;
- uint8_t *buffer;
- uint8_t *buffer2;
- int frameFinished;
- int numBytes;
- shot s;
- static struct SwsContext *img_convert_ctx = NULL;
- int frame_number;
-
- create_main_dir ();
-
- string graphpath = this->global_path + "/" + this->alphaid;
- g = new graph (600, 400, graphpath, threshold, this);
- g->set_title ("Quantité de mouvement en fonction de la frame");
-
- /*
- * Register all formats and codecs
- */
- av_register_all ();
-
- if (av_open_input_file (&pFormatCtx, input_path.c_str (), NULL, 0, NULL) != 0)
- {
- string error_msg = "Could not open file ";
- error_msg += input_path;
- shotlog (error_msg);
- return -1; // Couldn't open file
- }
-
- /*
- * Retrieve stream information
- */
- if (av_find_stream_info (pFormatCtx) < 0)
- return -1; // Couldn't find stream information
-
-
- // dump_format (pFormatCtx, 0, input_path.c_str (), false);
- videoStream = -1;
- audioStream = -1;
-
-
- /*
- * Detect streams types
- */
- for (int j = 0; j < pFormatCtx->nb_streams; j++)
- {
- switch (pFormatCtx->streams[j]->codec->codec_type)
- {
- case AVMEDIA_TYPE_VIDEO:
- videoStream = j;
- break;
-
- case AVMEDIA_TYPE_AUDIO:
- audioStream = j;
- break;
-
- default:
- break;
- }
- }
-
-
-
- /*
- * Get a pointer to the codec context for the video stream
- */
- if (audioStream != -1)
- {