Index: AVHandler.cc =================================================================== --- AVHandler.cc (Revision 11491) +++ AVHandler.cc (Arbeitskopie) @@ -473,4 +473,3 @@ return frame; } - Index: oct-avifile.h =================================================================== --- oct-avifile.h (Revision 11491) +++ oct-avifile.h (Arbeitskopie) @@ -60,5 +60,4 @@ DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; - #endif Index: AVHandler.h =================================================================== --- AVHandler.h (Revision 11491) +++ AVHandler.h (Arbeitskopie) @@ -24,22 +24,16 @@ #ifndef _AVHANDLER_H #define _AVHANDLER_H +#include "config.h" -#define VIDEO_OUTBUF_SIZE 200000 - -// FIXME: should define -D__STDC_CONSTANT_MACROS instead of the following -#define INT64_C -#define UINT64_C -#define __STDC_CONSTANT_MACROS - #include extern "C" { #if defined (HAVE_FFMPEG_AVFORMAT_H) -#include + #include #elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H) -#include + #include #else -#error "Missing ffmpeg headers" + #error "Missing ffmpeg headers" #endif } #include Index: avctest.cc =================================================================== --- avctest.cc (Revision 11491) +++ avctest.cc (Arbeitskopie) @@ -1,55 +0,0 @@ -#include "AVHandler.h" -#include - -#define FRAMES 255 - -int output_avi(std::string fn, std::string codec) -{ - AVHandler *av = new AVHandler(); - - av->set_filename(fn); - av->set_height(100); - av->set_width(300); - av->set_codec(codec); - - int err = av->setup_write(); - if (err != 0) { - delete av; - return err; - } - - std::cout << "starting..." << std::endl; - for (int i = 0; i < FRAMES; i++) { - std::cout << "\r" << i << std::flush; - av->draw_background((unsigned char)((1+sin(double(i)/1000*2*M_PI))*255/2), - (unsigned char)((1+cos(double(i)/1000*2*M_PI))*255/2), 200); - av->write_frame(); - } - - delete av; - return 0; -} - -int main() { -#if defined(HAVE_THREADS) - std::cout << "Warning: threads are active" << std::endl; -#endif - - std::cout << "Built for libavcodec " << LIBAVCODEC_BUILD; - std::cout << " (using version " << avcodec_build() << ")" << std::endl; - - if (output_avi("testc1.avi", "wmv1") != 0) - std::cout << "Error writing testc1.avi" << std::endl; - if (output_avi("testc2.avi", "wmv1") != 0) - std::cout << "Error writing testc2.avi" << std::endl; - - AVHandler av = AVHandler(); - av.set_filename("testc2.avi"); - av.setup_read(); - for (unsigned int i = 1; i < av.get_total_frames()+1; i++) { - std::cout << "Reading frame " << i << "...\r" << std::flush; - av.read_frame(i); - } - - return 0; -} Index: fntest.m =================================================================== --- fntest.m (Revision 0) +++ fntest.m (Revision 0) @@ -0,0 +1,5 @@ +## call tests for the octave-forge video package + +test("avifile.cc","quiet",stdout) +test("addframe.cc","quiet",stdout) +test("aviread.cc","quiet",stdout) Index: aviinfo.cc =================================================================== --- aviinfo.cc (Revision 11491) +++ aviinfo.cc (Arbeitskopie) @@ -22,6 +22,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include #include Index: aviread.cc =================================================================== --- aviread.cc (Revision 11491) +++ aviread.cc (Arbeitskopie) @@ -22,6 +22,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include #include "AVHandler.h" @@ -92,15 +93,51 @@ %! I = cat(3, I, 0.3*ones(256,256)); %! %! # Display the picture -%! imshow(I(:,:,1), I(:,:,2), I(:,:,3)); +%! figure(1) +%! imshow(I); %! %! # Write it to the AVI and close the AVI %! addframe(x, I); +%! addframe(x, I); %! clear x %! %! # Read the first frame from the AVI %! I = aviread("test.avi", 1); %! %! # Display the frame read -%! imshow(I(:,:,1), I(:,:,2), I(:,:,3)); +%! figure(2) +%! imshow(I); */ + +/* +%!test +%! fn = tmpnam; +%! x = avifile(fn); +%! +%! # Generate some picture +%! I = repmat(0:255, 256, 1)/255; +%! I = cat(3, I, repmat([0:255]', 1, 256)/255); +%! I = cat(3, I, 0.3*ones(256,256)); +%! +%! # Write it to the AVI and close the AVI +%! addframe(x, I); +%! addframe(x, I); #FIXME: aviread currently fails if only 1 frame +%! clear x +%! assert(exist(fn,"file")) +%! I2 = aviread(fn, 1); +%! +%! #allow max. 5% difference between pixels +%! assert(!any((I-I2)(:)>0.05)) +%! delete(fn); +*/ + +/* +%!xtest +%! fn = tmpnam; +%! x = avifile(fn); +%! I = ones(256,256); +%! addframe(x, I); +%! clear x +%! #FIXME: This fails if there is only 1 frame +%! I = aviread(fn, 1); +*/ Index: config.h.in =================================================================== --- config.h.in (Revision 0) +++ config.h.in (Revision 0) @@ -0,0 +1,86 @@ +/* config.h.in. Generated from configure.ac by autoheader and edited by hand */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_FFMPEG_AVCODEC_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FFMPEG_AVFORMAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `avcodec' library (-lavcodec). */ +#undef HAVE_LIBAVCODEC + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIBAVCODEC_AVCODEC_H + +/* Define to 1 if you have the `avformat' library (-lavformat). */ +#undef HAVE_LIBAVFORMAT + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIBAVFORMAT_AVFORMAT_H + +/* Define to 1 if you have the `swscale' library (-lswscale). */ +#undef HAVE_LIBSWSCALE + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#undef HAVE_MALLOC + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if the system has the type `_Bool'. */ +#undef HAVE__BOOL + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* size of video buffer */ +#undef VIDEO_OUTBUF_SIZE + +/* Define for Solaris 2.5.1 so the uint64_t typedef from , + , or is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT64_T + +/* Define for Solaris 2.5.1 so the uint8_t typedef from , + , or is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT8_T + +/* workaraound for C++ programs to use C99 makros */ +#undef __STDC_CONSTANT_MACROS + +/* Define to rpl_malloc if the replacement function should be used. */ +#undef malloc + +/* Define to the type of an unsigned integer type of width exactly 64 bits if + such a type exists and the standard includes do not define it. */ +#undef uint64_t + +/* Define to the type of an unsigned integer type of width exactly 8 bits if + such a type exists and the standard includes do not define it. */ +#undef uint8_t Index: Makefile.in =================================================================== --- Makefile.in (Revision 11491) +++ Makefile.in (Arbeitskopie) @@ -1,39 +1,31 @@ OCTFILES = avifile.oct aviread.oct aviinfo.oct addframe.oct - -FFMPEG_CONFIG = @FFMPEG_CONFIG@ -ifdef FFMPEG_CONFIG - FFMPEG_LIBS = $(shell pkg-config libavformat libavcodec libavutil libswscale --libs) - FFMPEG_CFLAGS = $(shell pkg-config libavformat libavcodec libavutil libswscale --cflags) -else - FFMPEG_LIBS = -lavformat -lavcodec -lavutil -lswscale -lz -lm - FFMPEG_CFLAGS = -endif - AVOBJS = AVHandler.o oct-avifile.o +FILES_WITH_TESTS = avifile.cc addframe.cc .PHONY: clean -clean: - rm -f *.o *.oct avctest *~ octave-core +.PHONY: realclean +.PHONY: distclean +all: ${OCTFILES} + oct-avifile.o: AVHandler.o ${AVOBJS}: %.o: %.cc - mkoctfile -v -c $(FFMPEG_DEFS) $(FFMPEG_CFLAGS) $< -o $@ + mkoctfile -Wall -v -c @DEFS@ $< -o $@ ${OCTFILES}: %.oct: %.cc AVHandler.o oct-avifile.o - mkoctfile -v $(FFMPEG_DEFS) $< $(filter %.o, $^) $(FFMPEG_LIBS) $(FFMPEG_CFLAGS) + mkoctfile -Wall -v @DEFS@ $< $(filter %.o, $^) @LIBS@ -avctest.o: avctest.cc - g++ -Wall -c avctest.cc -o avctest.o +check: + @octave -q fntest.m + +clean: + rm -f *.o *~ *.orig octave-workspace -avctest: AVHandler.o avctest.o - g++ $^ -Wall ${FFMPEG_OPTS} -o $@ - -TEST_CASES = \ - avitest - -NOT_BROKEN_TEST_CASES = $(TEST_CASES:=.test) -.PHONY: check -check: $(NOT_BROKEN_TEST_CASES) -%.test: - octave -q tests/$*.m > /dev/null +realclean: clean + rm -f *.oct avctest + +distclean: realclean + rm -rf autom4te.cache + rm -f Makefile config.status config.log config.h configure + rm -f *.avi Index: avifile.cc =================================================================== --- avifile.cc (Revision 11491) +++ avifile.cc (Arbeitskopie) @@ -22,6 +22,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include #include "oct-avifile.h" @@ -81,7 +82,7 @@ } // Parse parameters - std::string codec = "msmpeg4v2"; + std::string codec = "mpeg4"; unsigned int bitrate = 400000; int gop_size = 10; double fps = 25; @@ -128,42 +129,15 @@ /* %!test -%! avifile("codecs") - -%!test -%! m = avifile("test.avi", "codec", "msmpeg4v2") +%! fn="test_avifile1.avi"; +%! m = avifile(fn, "codec", "mpeg4"); %! for i = 1:100 %! I = zeros(100,100); %! I(i,:) = i; %! I(:,i) = 200-i; -%! addframe(m, I/255) -%! printf(".") +%! addframe(m, I/255); %! endfor -%! printf("\n") %! clear m - -%!test -%! m = avifile("test2.avi", "codec", "msmpeg4v2") -%! for i = 1:100 -%! I = zeros(100,100,3); -%! -%! for x = 1:100 -%! I(round(50+10*sin((x+i)/100*4*pi)), x, 1) = 40; -%! I(round(50+10*sin((x+i)/100*4*pi)), x, 2) = 40; -%! I(round(50+10*sin((x+i)/100*4*pi)), x, 3) = 180; -%! endfor -%! -%! I(i,:,1) = 0; -%! I(i,:,2) = 50 + i*2; -%! I(i,:,3) = 0; -%! I(:,i,1) = 200 - i*2; -%! I(:,i,2) = 0; -%! I(:,i,3) = i*2; -%! -%! addframe(m, I/255) -%! printf(".") -%! endfor -%! printf("\n") -%! clear m - +%! assert(exist(fn,"file")) +%! delete(fn) */ Index: configure.ac =================================================================== --- configure.ac (Revision 11491) +++ configure.ac (Arbeitskopie) @@ -1,51 +1,40 @@ -dnl Process this file with autoconf to produce a configure script. +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. -AC_PREREQ([2.67]) +AC_PREREQ([2.6]) AC_INIT([Octave-Forge video package], [1.1.0+]) +AC_CONFIG_HEADERS([config.h]) +# Checks for programs. AC_PROG_CXX AC_LANG(C++) +# Define macros needed for libav +AC_DEFINE(__STDC_CONSTANT_MACROS, [], [workaraound for C++ programs to use C99 makros]) +AC_DEFINE(VIDEO_OUTBUF_SIZE, [200000], [size of video buffer]) + AC_CHECK_PROG([HAVE_MKOCTFILE], [mkoctfile], [yes], [no]) if [test $HAVE_MKOCTFILE = "no"]; then AC_MSG_ERROR([mkoctfile required to install $PACKAGE_NAME]) fi -dnl Check for ffmpeg -AC_CHECK_PROG([FFMPEG_CONFIG], [pkg-config], [pkg-config]) -if test -z $FFMPEG_CONFIG ; then - AC_MSG_WARN([`pkg-config' not found -- using default configuration]) - FFMPEG_FLAGS="-lavcodec -lavutil -lm" - echo $FFMPEG_FLAGS -else - FFMPEG_FLAGS=`pkg-config libavformat libavcodec libavutil libswscale --libs --cflags` - echo $FFMPEG_FLAGS -fi +# Checks for libraries. AC_CHECK_LIB([avformat], [av_write_frame], [], - [AC_MSG_ERROR([$PACKAGE_NAME requires libavformat from FFmpeg])], - [$FFMPEG_FLAGS]) + [AC_MSG_ERROR([$PACKAGE_NAME requires libavformat from FFmpeg])]) AC_CHECK_LIB([avcodec], [av_malloc], [], - [AC_MSG_ERROR([$PACKAGE_NAME requires libavcodec from FFmpeg])], - [$FFMPEG_FLAGS]) + [AC_MSG_ERROR([$PACKAGE_NAME requires libavcodec from FFmpeg])]) AC_CHECK_LIB([swscale], [sws_scale], [], - [AC_MSG_ERROR([$PACKAGE_NAME requires libswscale from FFmpeg])], - [$FFMPEG_FLAGS]) + [AC_MSG_ERROR([$PACKAGE_NAME requires libswscale from FFmpeg])]) + +# Checks for header files. -OLD_CPPFLAGS=$CPPFLAGS -CPPFLAGS="$CPPFLAGS $FFMPEG_FLAGS" -FFMPEG_DEFS= -AC_SUBST(FFMPEG_DEFS) -AC_CHECK_HEADERS(ffmpeg/avformat.h, - FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_FFMPEG_AVFORMAT_H", [ - AC_CHECK_HEADERS(libavformat/avformat.h, - FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_LIBAVFORMAT_AVFORMAT_H", - AC_MSG_ERROR([FFMpeg header files not found]))]) -AC_CHECK_HEADERS(ffmpeg/avcodec.h, - FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_FFMPEG_AVCODEC_H", [ - AC_CHECK_HEADERS(libavcodec/avcodec.h, - FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_LIBAVCODEC_AVCODEC_H", - AC_MSG_ERROR([FFMpeg header files not found]))]) +AC_CHECK_HEADERS([ffmpeg/avformat.h], [], [AC_CHECK_HEADERS([libavformat/avformat.h], [], + AC_MSG_ERROR([FFMpeg header avformat.h not found]))]) + +AC_CHECK_HEADERS([ffmpeg/avcodec.h], [], [AC_CHECK_HEADERS([libavcodec/avcodec.h], [], + AC_MSG_ERROR([FFMpeg header avcodec.h not found]))]) + AC_CHECK_DECL(AVSEEK_FLAG_BACKWARD, [], AC_MSG_ERROR([need a newer version of FFMpeg]), [ #if defined(HAVE_FFMPEG_AVFORMAT_H) @@ -53,8 +42,23 @@ #elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H) #include #endif]) -CPPFLAGS=$OLD_CPPFLAGS +# Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_HEADER_STDBOOL +AC_TYPE_UINT64_T +AC_TYPE_UINT8_T + +# Checks for library functions. +AC_FUNC_ERROR_AT_LINE +AC_FUNC_MALLOC + AC_CONFIG_FILES([Makefile]) -AC_SUBST([FFMPEG_CONFIG]) AC_OUTPUT + +AC_MSG_NOTICE([ + +$PACKAGE_NAME is now configured with + + FFMPEG LIBS: $LIBS + DEFS: $DEFS +]) Index: oct-avifile.cc =================================================================== --- oct-avifile.cc (Revision 11491) +++ oct-avifile.cc (Arbeitskopie) @@ -22,6 +22,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include #include "oct-avifile.h" @@ -126,7 +127,6 @@ } Avifile::~Avifile(void) { - octave_stdout << "avifile: writing headers and closing " << filename << std::endl; + //octave_stdout << "avifile: writing headers and closing " << filename << std::endl; delete av; } - Index: addframe.cc =================================================================== --- addframe.cc (Revision 11491) +++ addframe.cc (Arbeitskopie) @@ -22,6 +22,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include #include "oct-avifile.h" @@ -71,6 +72,44 @@ /* %!test -%! m = avifile("test.avi") -%! addframe(m, zeros(2,2)) +%! fn="test_addframe.avi"; +%! m = avifile(fn); +%! addframe(m, zeros(10,15)) +%! addframe(m, ones(10,15)) +%! addframe(m, rand(10,15)) +%! clear m +%! assert(exist(fn,"file")) +%! r=aviinfo(fn); +%! assert(r.Filename,fn); +%! assert(r.NumFrames,3); +%! assert(r.Width,15); +%! assert(r.Height,10); +%! delete(fn) */ + +/* +%!demo +%! fn="test_avifile2.avi"; +%! m = avifile(fn, "codec", "mpeg4"); +%! for i = 1:100 +%! I = zeros(100,100,3); +%! +%! for x = 1:100 +%! I(round(50+10*sin((x+i)/100*4*pi)), x, 1) = 40; +%! I(round(50+10*sin((x+i)/100*4*pi)), x, 2) = 40; +%! I(round(50+10*sin((x+i)/100*4*pi)), x, 3) = 180; +%! endfor +%! +%! I(i,:,1) = 0; +%! I(i,:,2) = 50 + i*2; +%! I(i,:,3) = 0; +%! I(:,i,1) = 200 - i*2; +%! I(:,i,2) = 0; +%! I(:,i,3) = i*2; +%! +%! addframe(m, I/255) +%! endfor +%! clear m +%! assert(exist(fn,"file")) +%! delete(fn) +*/