Mercurial > forge
changeset 11828:2555b363673c octave-forge
video: moved to a separate mercurial repo
author | carandraug |
---|---|
date | Mon, 17 Jun 2013 22:27:25 +0000 |
parents | 9fd86811bb0d |
children | 10d47c577e4c |
files | main/video/COPYING main/video/DESCRIPTION main/video/INDEX main/video/NEWS main/video/doc/README main/video/src/AVHandler.cc main/video/src/AVHandler.h main/video/src/Makefile.in main/video/src/addframe.cc main/video/src/avifile.cc main/video/src/aviinfo.cc main/video/src/aviread.cc main/video/src/bootstrap main/video/src/config.h.in main/video/src/configure.ac main/video/src/oct-avifile.cc main/video/src/oct-avifile.h |
diffstat | 17 files changed, 0 insertions(+), 1678 deletions(-) [+] |
line wrap: on
line diff
--- a/main/video/COPYING Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -Octave-Avifile : An Octave interface for handling AVI videos - -Copyright (C) 2004 Stefan van der Walt <stefan@sun.ac.za> - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--- a/main/video/DESCRIPTION Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -Name: video -Version: 1.0.2 -Date: 2009-05-03 -Author: Stefan van der Walt <stefan@sun.ac.za> and Roman Stanchak -Maintainer: Octave-Forge community <octave-dev@lists.sourceforge.net> -Title: Video functions -Description: A wrapper for ffmpeg's libavformat and libavcodec, implementing - addframe, avifile, aviinfo, and aviread. -Depends: octave (>= 2.9.12) -BuildRequires: ffmpeg (>=0.7) [Debian] libavformat-dev [Debian] libswscale-dev -License: FreeBSD -Url: http://octave.sf.net -Url: http://mentat.za.net
--- a/main/video/INDEX Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -video >> Video -Video - addframe - avifile - aviinfo - aviread
--- a/main/video/NEWS Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -Summary of important user-visible changes for video 1.2.0: -------------------------------------------------------------------- - - ** Package is no longer automatically loaded.
--- a/main/video/doc/README Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -Dependencies ------------- -This package _should_ always work with the latest version of ffmpeg. It is -known to at least work with ffmpeg SVN revision 15410. - -You can download ffmpeg from -http://ffmpeg.mplayerhq.hu - -Note that you'll need to configure it with --enable-swscale and --enable-gpl, -to enable the software scaler library (used for yuv/rgb conversions). - -Usage Notes ------------ -- If ffmpeg complains about "too many threads", increase the frame height - and width. For some obscure reason, they do a comparison between the number - of threads and the frame dimensions. - -- Remember to `clear' a movie after adding the last frame. This gives - `avifile' a chance to write some headers and close the file, i.e. - - octave:1> x = avifile("test.avi", "msmpeg4v2"); - octave:2> addframe(x, zeros(100,100)); - octave:3> clear x - -- If `aviinfo' crashes, you might have run into a libstdc++ memory allocation - bug. Work around the problem by executing - - $ export GLIBCXX_FORCE_NEW=1 - - before running Octave.
--- a/main/video/src/AVHandler.cc Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,475 +0,0 @@ -/* Copyright (c) 2005 Stefan van der Walt <stefan@sun.ac.za> - * - * Based in part on the libavformat example, which is - * Copyright (c) 2003 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "AVHandler.h" - -#include <string> -#include <cstdlib> - -extern "C" { -#if defined (HAVE_FFMPEG_AVFORMAT_H) -#include <ffmpeg/swscale.h> -#elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H) -#include <libswscale/swscale.h> -#else -#error "Missing ffmpeg headers" -#endif -} - -#ifdef _MSC_VER -#define snprintf _snprintf -#endif - -std::ostream *AVHandler::out = &std::cout; - -AVHandler::~AVHandler(void) { - if (frame) { - av_free(frame->data[0]); - av_free(frame); - frame = NULL; - } - - if (rgbframe) { - av_free(rgbframe->data[0]); - av_free(rgbframe); - rgbframe = NULL; - } - - // we can use FFMpeg's `av_close_input_file` for input files, but - // output files must be closed manually - - // flush buffers, write headers and close output file - if (av_output) { - if (av_output->pb->buf_ptr) { - while (write_frame() > 0) {} - av_write_trailer(av_output); - if (avio_close( av_output->pb ) < 0) - (*out) << "AVHandler: cannot close output file" << std::endl; - } - av_free(av_output); - } - - // close codec - if (vstream) { - if (vstream->codec->codec) { - avcodec_close( vstream->codec ); - } - } - - if (av_input) { - avformat_close_input(&av_input); - } else { - // close output stream - if (vstream) av_freep(&vstream); - } - - if (video_outbuf) { - av_free(video_outbuf); - } - -} - -int -AVHandler::setup_write() { - av_register_all(); - - AVOutputFormat *avifmt = NULL; - while (NULL != (avifmt = av_oformat_next(avifmt))) { - if (std::string(avifmt->name) == "avi") { - break; - } - } - - if (!avifmt) { - (*out) << "AVHandler: Error finding AVI output format" << std::endl; - return -1; - } - - av_output = avformat_alloc_context(); - if (!av_output) { - (*out) << "AVHandler: Memory error allocating format context" << std::endl; - return -1; - } - - // use AVI encoding - av_output->oformat = avifmt; - av_output->oformat->audio_codec = CODEC_ID_NONE; - - if (avifmt->video_codec != CODEC_ID_NONE) { - if (add_video_stream() != 0) return -1; - } - - /* av_set_parameters is mandatory */ - // FIXME: deprecated, but there's no replacement yet - if (av_set_parameters(av_output, NULL) < 0) { - (*out) << "AVHandler: Error setting output format parameters" << std::endl; - return -1; - } - - snprintf(av_output->filename, sizeof(av_output->filename), "%s", filename.c_str()); -// FIXME: snprintf(av_output->title, sizeof(av_output->title), "%s", title.c_str()); -// FIXME: snprintf(av_output->author, sizeof(av_output->author), "%s", author.c_str()); -// FIXME: snprintf(av_output->comment, sizeof(av_output->comment), "%s", comment.c_str()); - - if (avio_open(&av_output->pb, filename.c_str(), URL_WRONLY) < 0) { - (*out) << "AVHandler: Could not open \"" << filename << "\" for output" << std::endl; - return -1; - } - - if (init_video_codecs() != 0) return -1; - - frame = create_frame(vstream->codec->pix_fmt); - rgbframe = create_frame(PIX_FMT_RGB24); - if (!frame || !rgbframe) return -1; - - avformat_write_header(av_output, NULL); - - return 0; -} - -int -AVHandler::setup_read() { - av_register_all(); - - if (avformat_open_input(&av_input, filename.c_str(), NULL, NULL) != 0) { - (*out) << "AVHandler: Could not open \"" << filename << "\" for reading" << std::endl; - return -1; - } - - if (avformat_find_stream_info(av_input, NULL) < 0) { - (*out) << "AVHandler: No stream information available" << std::endl; - return -1; - } - - for (int i=0; i < av_input->nb_streams; i++) { - if (av_input->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - vstream = av_input->streams[i]; - break; - } - } - if (!vstream) { - (*out) << "AVHandler: No video streams found" << std::endl; - return -1; - } - - for (int i=0; i < av_input->nb_streams; i++) { - if (av_input->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - astream = av_input->streams[i]; - break; - } - } - - AVCodec *codec; - codec = avcodec_find_decoder(vstream->codec->codec_id); - - if (!codec) { - (*out) << "AVHandler: Cannot find codec used in stream" << std::endl; - return -1; - } - codec_name = codec->name; - - // We can handle truncated bitstreams - if (codec->capabilities & CODEC_CAP_TRUNCATED) - vstream->codec->flags |= CODEC_FLAG_TRUNCATED; - - if (avcodec_open2(vstream->codec, codec, NULL) < 0) { - (*out) << "AVHandler: Cannot open codec " << codec_name << std::endl; - vstream->codec->codec = NULL; - return -1; - } - - /// XXX TODO XXX Verify that this calculation is correct - AVRational av_fr = vstream->r_frame_rate; - framerate = (double)av_fr.num / (double)av_fr.den; - width = vstream->codec->width; - height = vstream->codec->height; - -// FIXME: title = av_input->title; -// FIXME: author = av_input->author; -// FIXME: comment = av_input->comment; - - rgbframe = create_frame(PIX_FMT_RGB24); - if (!rgbframe) return -1; - - return 0; -} - -void -AVHandler::draw_background(unsigned char r, unsigned char g, unsigned char b) { - int x, y; - for (y = 0; y < vstream->codec->height; y++) { - for (x = 0; x < vstream->codec->width; x++) { - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x] = r; - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x+1] = g; - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x+2] = b; - } - } -} - -int -AVHandler::write_frame() { - if (video_outbuf == NULL) { - return 0; - } - - lock_parameters = true; - - AVCodecContext *c = vstream->codec; - - if (frame && rgbframe) { - SwsContext *sc = sws_getContext(c->width, c->height, PIX_FMT_BGR24, - c->width, c->height, c->pix_fmt, - SWS_BICUBIC, 0, 0, 0); - sws_scale(sc, rgbframe->data, rgbframe->linesize, 0, - c->height, frame->data, frame->linesize); - } - - int out_size = avcodec_encode_video(c, video_outbuf, - VIDEO_OUTBUF_SIZE, - frame); - if (out_size > 0) { - AVPacket pkt; - av_init_packet(&pkt); - - pkt.stream_index = vstream->index; - pkt.data = video_outbuf; - pkt.size = out_size; - - if (c->coded_frame) - pkt.pts = c->coded_frame->pts; - if (c->coded_frame && c->coded_frame->key_frame) - pkt.flags |= AV_PKT_FLAG_KEY; - /// XXX FIXME XXX does this ensure that the first frame is always a key frame? - - if (av_write_frame(av_output, &pkt) != 0) { - (*out) << "AVHandler: error writing video frame" << std::endl; - return -1; - } - - } - - frame_nr++; - return out_size; -} - -int -AVHandler::read_frame(unsigned int nr) { - nr--; // zero-based calculations - - AVCodecContext *cc = vstream->codec; - - // Calculate timestamp of target frame - uint64_t start_time = 0; - if ((uint64_t)vstream->start_time != AV_NOPTS_VALUE) { - start_time = vstream->start_time; - } - uint64_t target_timestamp = start_time + nr*(uint64_t)(AV_TIME_BASE / framerate); - - if (((target_timestamp - start_time) < 0) || - ((target_timestamp - start_time) >= (uint64_t)av_input->duration)) { - (*out) << "AVHandler: Invalid frame requested" << std::endl; - return -1; - } - - // Seek to closest keyframe - if (av_seek_frame(av_input, -1, target_timestamp, AVSEEK_FLAG_BACKWARD) < 0) { - (*out) << "AVHandler: Error seeking to " << target_timestamp << std::endl; - return -1; - } - cc->skip_frame; - - // Flush stream buffers after seek - avcodec_flush_buffers(cc); - - // Calculate stream time base - double stream_time_base = 1; - if (vstream->time_base.den != 0) { - stream_time_base = (double)vstream->time_base.num / vstream->time_base.den; - } - - frame = avcodec_alloc_frame(); - - uint64_t current_timestamp = 0; - AVPacket packet; - - while (current_timestamp <= target_timestamp) { - - // Read until we find a packet from the video stream - packet.stream_index = -1; - while (packet.stream_index != vstream->index) { - if (av_read_frame(av_input, &packet)) { - (*out) << "AVHandler: Error reading packet after timestamp " << current_timestamp << std::endl; - av_free_packet(&packet); - av_free(frame); frame = NULL; - return -1; - } - - if (av_input->pb->eof_reached) { - (*out) << "AVHandler: EOF reached" << std::endl; - } - } - - // Decode the packet into a frame - int frameFinished; - - // HACK for CorePNG to decode as normal PNG by default - packet.flags = AV_PKT_FLAG_KEY; - - if (avcodec_decode_video2(cc, frame, &frameFinished, &packet) < 0) { - (*out) << "AVHandler: Error decoding video stream" << std::endl; - av_free_packet(&packet); - av_free(frame); frame = NULL; - return -1; - } - - if (frameFinished) { - current_timestamp = (uint64_t)(vstream->cur_dts * AV_TIME_BASE * (long double)stream_time_base); - } - } -// http://ffmpeg.org/pipermail/ffmpeg-cvslog/2011-April/035933.html -// FIXME maybe use: cc->skip_frame; -// cc->hurry_up = 0; - - SwsContext *sc = sws_getContext(cc->width, cc->height, cc->pix_fmt, - cc->width, cc->height, PIX_FMT_BGR24, - SWS_BICUBIC, 0, 0, 0); - sws_scale(sc, frame->data, frame->linesize, 0, - cc->height, rgbframe->data, rgbframe->linesize); - - av_free_packet(&packet); - av_free(frame); frame = NULL; - - return 0; -} - -void -AVHandler::print_file_formats() { - (*out) << "Supported file formats:" << std::endl; - av_register_all(); - - AVOutputFormat *ofmt = NULL; - while (NULL != (ofmt = av_oformat_next(ofmt))) { - (*out) << ofmt->name << " "; - } - (*out) << std::endl << std::endl; -} - -void -AVHandler::print_codecs() { - (*out) << "Supported video codecs:" << std::endl; - av_register_all(); - - AVCodec *codec; - for (codec = av_codec_next(0); codec != NULL; codec = av_codec_next(codec)) { - if ((codec->type == AVMEDIA_TYPE_VIDEO) && - (codec->encode)) { - (*out) << codec->name << " "; - } - } - (*out) << std::endl; -} - -int -AVHandler::add_video_stream() { - AVCodecContext *cc; - - // FIXME: vstream = avformat_new_stream(av_output, av_find_default_stream_index(av_output)); - vstream = avformat_new_stream(av_output, NULL); - if (!vstream) { - (*out) << "AVHandler: error opening video output stream" << std::endl; - return -1; - } - - cc = vstream->codec; - - cc->codec_type = AVMEDIA_TYPE_VIDEO; - - cc->bit_rate = bitrate; - cc->width = width; - cc->height = height; - - // XXX TODO XXX Make sure this calculation is correct // - cc->time_base.num = 1; - cc->time_base.den = (int)(framerate); - cc->pix_fmt = PIX_FMT_YUV420P; - - cc->gop_size = gop_size; - - return 0; -} - -int -AVHandler::init_video_codecs() { - AVCodec *codec; - AVCodecContext *cc; - - cc = vstream->codec; - - //codec = avcodec_find_encoder(cc->codec_id); - codec = avcodec_find_encoder_by_name(codec_name.c_str()); - - if (!codec) { - (*out) << "AVHandler: cannot find codec " << codec_name << std::endl; - return -1; - } - - if (avcodec_open2(cc, codec, NULL) < 0) { - (*out) << "AVHandler: cannot open codec" << std::endl; - cc->codec = NULL; - return -1; - } - - // XXX FIXME XXX What is the best size for video_outbuf? - video_outbuf = (uint8_t *)malloc(VIDEO_OUTBUF_SIZE); - - return 0; -} - -AVFrame* -AVHandler::create_frame(PixelFormat fmt) { - AVFrame *frame; - uint8_t *frame_buf; - - frame = avcodec_alloc_frame(); - if (!frame) { - (*out) << "AVHandler: cannot allocate frame" << std::endl; - return NULL; - } - - int size = avpicture_get_size(fmt, - vstream->codec->width, - vstream->codec->height); - - frame_buf = (uint8_t *)malloc(size); - if (!frame_buf) { - av_free(frame); - (*out) << "AVHandler: error initialising frame" << std::endl; - return NULL; - } - - avpicture_fill((AVPicture *)frame, frame_buf, fmt, - vstream->codec->width, vstream->codec->height); - - return frame; -}
--- a/main/video/src/AVHandler.h Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,248 +0,0 @@ -/* Copyright (C) 2005 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef _AVHANDLER_H -#define _AVHANDLER_H -#include "config.h" - -#include <errno.h> -extern "C" { -#if defined (HAVE_FFMPEG_AVFORMAT_H) - #include <ffmpeg/avformat.h> -#elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H) - #include <libavformat/avformat.h> -#else - #error "Missing ffmpeg headers" -#endif -} -#include <iostream> - -class AVHandler { - public: - AVHandler() { - av_output = NULL; - av_input = NULL; - vstream = NULL; - astream = NULL; - frame = NULL; - rgbframe = NULL; - video_outbuf = NULL; - filename = ""; - frame_nr = 0; - - bitrate = 400000; - framerate = 25; - gop_size = 10; - width = 352; - height = 288; - codec_name = "msmpeg4v2"; - - title = ""; - author = ""; - comment = ""; - - lock_parameters = false; - } - - ~AVHandler(void); - - int setup_write(); - - int setup_read(); - - void draw_background(unsigned char r, unsigned char g, unsigned char b); - - // write rgbframe to file - int write_frame(); - - // read frame nr from file into rgbframe - int read_frame(unsigned int nr); - - static void print_file_formats(); - - static void print_codecs(); - - // The following routines can be used before `setup_write' - - void set_filename(const std::string &filename) { - this->filename = filename; - } - - std::string get_filename() const { - return filename; - } - - void set_codec(const std::string &codec) { - codec_name = codec; - } - - std::string get_codec() const { - return codec_name; - } - - std::string get_audio_codec() const { - if (!astream) return ""; - - AVCodec *codec; - codec = avcodec_find_decoder(astream->codec->codec_id); - if (!codec) { - return ""; - } - return std::string(codec->name); - } - - unsigned int get_audio_samplerate() const { - if (!astream) return 0; - - return astream->codec->sample_rate; - } - - unsigned int get_audio_channels() const { - if (!astream) return 0; - - return astream->codec->channels; - } - - void set_bitrate(const unsigned int br) { - bitrate = br; - } - - unsigned int get_bitrate() const { - return bitrate; - } - - void set_framerate(double fr) { - framerate = fr; - } - - void set_gop_size(int gop) { - gop_size = gop; - } - - double get_framerate() const { - return framerate; - } - - void set_width(unsigned int width) { - this->width = width; - } - - unsigned int get_width() const { - return width; - } - - void set_height(unsigned int height) { - this->height = height; - } - - unsigned int get_height() const { - return height; - } - - unsigned int get_total_frames() const { - if (vstream) { - return (unsigned int) vstream->nb_frames; - } else { - return 0; - } - } - - unsigned int get_filesize() const { - if (av_input) { - return avio_size(av_input->pb); - } else { - return 0; - } - } - - void set_title(const std::string &t) { - title = t; - } - - std::string get_title() const { - return title; - } - - void set_author(const std::string &a) { - author = a; - } - - std::string get_author() const { - return author; - } - - void set_comment(const std::string &c) { - comment = c; - } - - std::string get_comment() const { - return comment; - } - - AVFrame *get_rgbframe() { - return rgbframe; - } - - static void set_log(std::ostream *log) { - AVHandler::out = log; } - - private: - static std::ostream *out; - - AVFormatContext *av_output; - AVFormatContext *av_input; - AVStream *vstream; - AVStream *astream; - - AVFrame *frame; - AVFrame *rgbframe; - - uint8_t *video_outbuf; - - std::string filename; - - int frame_nr; - - unsigned int bitrate; - double framerate; - int gop_size; - unsigned int width; - unsigned int height; - std::string codec_name; - - std::string title; - std::string author; - std::string comment; - - bool lock_parameters; - - int add_video_stream(); - - int init_video_codecs(); - - AVFrame *create_frame(PixelFormat fmt); - -}; - -#endif
--- a/main/video/src/Makefile.in Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -OCTFILES = avifile.oct aviread.oct aviinfo.oct addframe.oct -AVOBJS = AVHandler.o oct-avifile.o -FILES_WITH_TESTS = avifile.cc addframe.cc - -.PHONY: clean -.PHONY: realclean -.PHONY: distclean - -all: ${OCTFILES} - -oct-avifile.o: AVHandler.o - -${AVOBJS}: %.o: %.cc - mkoctfile -Wall -v -c @DEFS@ $< -o $@ - -${OCTFILES}: %.oct: %.cc AVHandler.o oct-avifile.o - mkoctfile -Wall -v @DEFS@ $< $(filter %.o, $^) @LIBS@ - -clean: - rm -f *.o *~ *.orig octave-workspace - -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
--- a/main/video/src/addframe.cc Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -/* Copyright (C) 2004 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - 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 <octave/oct.h> -#include "oct-avifile.h" - -DEFUN_DLD(addframe, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} addframe (@var{avi}, @var{image})\n\ -Add a frame to an AVI file.\n\ -\n\ -@var{avi} is created using @code{avifile}. @var{image} must be \n\ -of class @code{double} and scaled to be in [0-1].\n\ -@end deftypefn\n\ -\n\ -@seealso{avifile, aviread, aviinfo}") -{ - octave_value_list retval; - - if (args.length() != 2) { - print_usage(); - return retval; - } - - if (args(0).type_id() != Avifile::static_type_id()) { - print_usage(); - return retval; - } - - NDArray f = args(1).array_value(); - if (error_state) { - error("addframe: frame should be a matrix"); - return retval; - } - - // Check if input image is in [0-1] - if (f.any_element_is_negative() || (1-f).any_element_is_negative()) { - error("addframe: input frame should be in [0-1]"); - return retval; - } - - Avifile *m = (Avifile*)args(0).internal_rep(); - m->addframe(f); - if (error_state) { - octave_stdout << "addframe: error adding frame to avifile" << std::endl; - } - - return retval; -} - -/* -%!test -%! 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) -*/
--- a/main/video/src/avifile.cc Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -/* Copyright (C) 2005 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - 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 <octave/oct.h> -#include "oct-avifile.h" - -template <typename Num> -void setp(Num &p, Num v) { - if (!error_state) { - p = v; - } else { - error_state = 0; - } -} - -DEFUN_DLD(avifile, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{f} =} avifile (@var{filename}, [@var{parameter}, @var{value}, @dots{}])\n\ -@deftypefnx {Loadable Function} avifile (\"codecs\")\n\ -Create an AVI-format video file.\n\ -\n\ -The supported parameters are\n\ -\n\ -@table @asis\n\ -@item @code{\"compression\"} or @code{\"codec\"}\n\ -The type of encoder used (default: @code{\"msmpeg4v2\"})\n\ -\n\ -@item @code{\"fps\"}\n\ -Encoding frame rate per second (default: @code{25.0})\n\ -\n\ -@item @code{\"gop\"}\n\ -Group-of-pictures -- the number of frames after which a keyframe\n\ -is inserted (default: @code{10})\n\ -\n\ -@item @code{\"bitrate\"}\n\ -Encoding bitrate (default: @code{400000})\n\ -@end table\n\ -\n\ -To see a list of the available codecs, do @code{avifile(\"codecs\")}.\n\ -@end deftypefn\n\ -\n\ -@seealso{addframe, aviinfo, aviread}") -{ - octave_value_list retval; - - if ( (args.length() == 1) && (args(0).string_value() == "codecs") ) { - AVHandler::print_codecs(); - return retval; - } - - if ((args.length() == 0) || (args.length() % 2 != 1)) { - print_usage(); - return retval; - } - - std::string filename = args(0).string_value(); - if (error_state) { - print_usage(); - return retval; - } - - // Parse parameters - std::string codec = "mpeg4"; - unsigned int bitrate = 400000; - int gop_size = 10; - double fps = 25; - std::string title = ""; - std::string author = ""; - std::string comment = "Created using Octave-Avifile"; - - for (unsigned int i = 1; i < args.length(); i++) { - std::string p = args(i).string_value(); - octave_value v = args(i+1); - if (!error_state) { - if ((p == "codec") || (p == "compression")) { setp(codec, v.string_value()); } - else if (p == "bitrate") { setp(bitrate, (unsigned int)v.int_value()); } - else if (p == "gop") { setp(gop_size, v.int_value()); } - else if (p == "fps") { setp(fps, v.double_value()); } - else if (p == "title") { setp(title, v.string_value()); } - else if (p == "author") { setp(author, v.string_value()); } - else if (p == "comment") { setp(comment, v.string_value()); } - else { - error("avifile: unknown parameter \"%s\"", p.c_str()); - return retval; - } - } - i++; - } - - Avifile *m = new Avifile(filename); - if (error_state) { - return retval; - } - m->av->set_codec(codec); - m->av->set_bitrate(bitrate); - m->av->set_gop_size(gop_size); - m->av->set_framerate(fps); - - // Doesn't look like these values are ever encoded - m->av->set_title(title); - m->av->set_author(author); - m->av->set_comment(comment); - - retval.append(octave_value(m)); - return retval; -} - -/* -%!test -%! 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); -%! endfor -%! clear m -%! assert(exist(fn,"file")) -%! delete(fn) -*/
--- a/main/video/src/aviinfo.cc Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* Copyright (C) 2004 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - 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 <octave/oct.h> -#include <octave/oct-map.h> - -#include <octave/file-stat.h> -#include <octave/oct-time.h> -#include <ctime> - -#include "AVHandler.h" - -std::string get_filedate(const std::string &fn) { - time_t file_mod = file_stat(fn).mtime().unix_time(); - - char *timestr = new char[30]; - strftime(timestr, 30, "%d-%b-%Y %H:%M:%S", localtime(&file_mod)); - - return std::string(timestr); -} - -DEFUN_DLD(aviinfo, args, , -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{info} =} aviinfo (@var{filename})\n\ -Return the properties of an AVI file.\n\ -@end deftypefn\n\ -\n\ -@seealso{avifile, aviread, addframe}") -{ - octave_value_list retval; - - if (args.length() != 1) { - print_usage(); - return retval; - } - - std::string filename = args(0).string_value(); - if (error_state) { - print_usage(); - return retval; - } - - AVHandler av = AVHandler(); - av.set_filename(filename); - av.set_log(&octave_stdout); - - if (av.setup_read() != 0) { - error("aviread: AVHandler setup failed"); - return retval; - } - - Octave_map m; - - m.assign("Filename", av.get_filename()); - m.assign("FileSize", av.get_filesize()); - m.assign("FileModDate", get_filedate(filename)); - m.assign("NumFrames", av.get_total_frames()); - m.assign("FramesPerSecond", av.get_framerate()); - m.assign("Width", av.get_width()); - m.assign("Height", av.get_height()); - m.assign("ImageType", "truecolor"); - m.assign("VideoCompression", av.get_codec()); - m.assign("Quality", 100); - m.assign("NumColormapEntries", 0); - m.assign("AudioFormat", av.get_audio_codec()); - m.assign("AudioRate", av.get_audio_samplerate()); - m.assign("NumAudioChannels", av.get_audio_channels()); - - // m.assign("Title", av.get_title()); - // m.assign("Author", av.get_author()); - // m.assign("Comment", av.get_comment()); - - retval.append(octave_value(m)); - return retval; -}
--- a/main/video/src/aviread.cc Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -/* Copyright (C) 2005 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - 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 <octave/oct.h> -#include "AVHandler.h" - -DEFUN_DLD(aviread, args, , -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{image} =} aviread (@var{filename}, @var{N})\n\ -Load frame @var{N} from the AVI file @var{filename}.\n\ -@end deftypefn\n\ -\n\ -@seealso{avifile, aviinfo, addframe}") -{ - octave_value_list retval; - - if (args.length() != 2) { - print_usage(); - return retval; - } - - std::string filename = args(0).string_value(); - if (error_state) { - print_usage(); - return retval; - } - - unsigned int framenr = (unsigned int)args(1).scalar_value(); - if (error_state) { - print_usage(); - } - - AVHandler av = AVHandler(); - av.set_filename(filename); - av.set_log(&octave_stdout); - - if (av.setup_read() != 0) { - error("aviread: AVHandler setup failed"); - return retval; - } - - if (av.read_frame(framenr) != 0) { - error("aviread: cannot read frame %d", framenr); - return retval; - } - - AVFrame *frame = av.get_rgbframe(); - - dim_vector d = dim_vector(av.get_height(), av.get_width(), 3); - NDArray image = NDArray(d, 0); - for (unsigned int y = 0; y < av.get_height(); y++) { - for (unsigned int x = 0; x < av.get_width(); x++) { - image(y, x, 0) = (double)frame->data[0][y * frame->linesize[0] + 3*x + 2]/255; - image(y, x, 1) = (double)frame->data[0][y * frame->linesize[0] + 3*x + 1]/255; - image(y, x, 2) = (double)frame->data[0][y * frame->linesize[0] + 3*x + 0]/255; - } - } - - retval.append(octave_value(image)); - return retval; -} - -/* -%!demo -%! # Create an AVI with a low bitrate -%! x = avifile("test.avi"); -%! -%! # 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)); -%! -%! # Display the picture -%! 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 -%! 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); -*/
--- a/main/video/src/bootstrap Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#!/bin/bash -## Octave-Forge: video package bootstrap script -## Run this to generate the configure script - -set -e # halt if unhandled error -autoconf # generate configure script
--- a/main/video/src/config.h.in Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* config.h.in. Generated from configure.ac by autoheader and edited by hand */ - -/* Define to 1 if you have the <ffmpeg/avcodec.h> header file. */ -#undef HAVE_FFMPEG_AVCODEC_H - -/* Define to 1 if you have the <ffmpeg/avformat.h> header file. */ -#undef HAVE_FFMPEG_AVFORMAT_H - -/* Define to 1 if you have the <inttypes.h> 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 <libavcodec/avcodec.h> 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 <libavformat/avformat.h> 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 <memory.h> header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the <stdint.h> header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the <stdlib.h> header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the <strings.h> header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the <string.h> header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the <sys/stat.h> header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the <sys/types.h> header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the <unistd.h> 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 <sys/synch.h>, - <pthread.h>, or <semaphore.h> 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 <sys/synch.h>, - <pthread.h>, or <semaphore.h> 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
--- a/main/video/src/configure.ac Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_PREREQ([2.67]) -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, [], [workaround for C++ programs to use C99 macros]) -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 - -# Checks for libraries. - -AC_CHECK_LIB([avformat], [av_write_frame], [], - [AC_MSG_ERROR([$PACKAGE_NAME requires libavformat from FFmpeg])]) -AC_CHECK_LIB([avcodec], [av_malloc], [], - [AC_MSG_ERROR([$PACKAGE_NAME requires libavcodec from FFmpeg])]) -AC_CHECK_LIB([swscale], [sws_scale], [], - [AC_MSG_ERROR([$PACKAGE_NAME requires libswscale from FFmpeg])]) - -# Checks for header files. - -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) -#include <ffmpeg/avformat.h> -#elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H) -#include <libavformat/avformat.h> -#endif]) - -# 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_OUTPUT - -AC_MSG_NOTICE([ - -$PACKAGE_NAME is now configured with - - FFMPEG LIBS: $LIBS - DEFS: $DEFS -])
--- a/main/video/src/oct-avifile.cc Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -/* Copyright (C) 2005 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - 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 <octave/oct.h> -#include "oct-avifile.h" - -DEFINE_OCTAVE_ALLOCATOR(Avifile); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(Avifile, "avifile", "avifile"); - -Avifile::Avifile(std::string fn) : octave_base_value(), - filename(fn), frames(0), frame_rows(0), frame_columns(0) { - - av = new AVHandler(); - av->set_filename(fn); - av->set_log(&octave_stdout); -} - -Avifile::Avifile(const Avifile& m) { - filename = m.filename; - frames = m.frames; - frame_rows = m.frame_rows; - frame_columns = m.frame_columns; - av = m.av; - - octave_stdout << "avifile: copy constructor shouldn't be called" << std::endl; -} - -void -Avifile::print(std::ostream& os, bool pr_as_read_syntax = false) const { - os << "AVI movie [" << filename << "][" << av->get_codec() << "]: " - << frames << " frame" << (frames != 1 ? "s" : "") << ", " - << frame_rows << "x" << frame_columns << "\n"; -} - -void -Avifile::addframe(const NDArray &f) { - if (frames == 0) { -// FIXME: this suppresses warnings from ffmpeg, but completely prevents -// working with many videos. -// if ( (f.columns() % 2 != 0) || (f.rows() % 2 != 0) ) { -// error("avifile: matrix dimensions must be multiple of two"); -// return; -// } - - if ( (f.columns() == 0) || (f.rows() == 0) ) { - error("avifile: matrix must have non-zero dimensions"); - return; - } - - frame_columns = f.columns(); - frame_rows = f.rows(); - - av->set_height(frame_rows); - av->set_width(frame_columns); - - if (av->setup_write() != 0) { - error("avifile: AVHandler setup failed"); - return; - } - } - if ( (frame_columns != f.columns()) || - (frame_rows != f.rows()) ) { - error("avifile: all frames must have the same dimensions (%dx%d)", - frame_rows, frame_columns); - return; - } - - // convert matrix to AVFrame - AVFrame *rgbframe = av->get_rgbframe(); - - dim_vector d = f.dims(); - unsigned char bands = 0; - - if ( (d.length() == 3) && (d(2) == 3) ) { - // RGB image - bands = 3; - } else if ( d.length() == 2 ) { - // gray or B&W image - bands = 1; - } else { - error("avifile: invalid matrix dimensions"); - return; - } - - for (unsigned int y = 0; y < frame_rows; y++) { - for (unsigned int x = 0; x < frame_columns; x++) { - if (bands == 3) { - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x + 2] = (unsigned char)(f(y,x,0)*255); - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x + 1] = (unsigned char)(f(y,x,1)*255); - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x + 0] = (unsigned char)(f(y,x,2)*255); - } - else { - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x + 0] = (unsigned char)(f(y,x)*255); - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x + 1] = (unsigned char)(f(y,x)*255); - rgbframe->data[0][y * rgbframe->linesize[0] + 3*x + 2] = (unsigned char)(f(y,x)*255); - } - } - } - - if (av->write_frame() < 0) { - error("avifile: error writing frame"); - return; - } - frames++; -} - -Avifile::~Avifile(void) { - //octave_stdout << "avifile: writing headers and closing " << filename << std::endl; - delete av; -}
--- a/main/video/src/oct-avifile.h Mon Jun 17 21:08:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* Copyright (C) 2004 Stefan van der Walt <stefan@sun.ac.za> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef _AVIFILE_H -#define _AVIFILE_H - -#include "AVHandler.h" - -class Avifile: public octave_base_value { - - public: - AVHandler *av; - - Avifile(void) { *this = Avifile("default.avi"); } - - Avifile(std::string fn); - - octave_base_value *clone(void) const { return new Avifile(*this); } - octave_base_value *empty_clone(void) const { return new Avifile(); } - - ~Avifile(void); - - void print(std::ostream& os, bool pr_as_read_syntax) const; - - void addframe(const NDArray &f); - - bool is_defined(void) const { return true; } - - bool is_constant(void) const { return true; } - - private: - Avifile(const Avifile& m); - - std::string filename; - unsigned int frames; - unsigned int frame_rows; - unsigned int frame_columns; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; -#endif