Changeset 9e516d0d in git


Ignore:
Timestamp:
17/06/11 07:18:26 (8 years ago)
Author:
Olly Betts <olly@…>
Branches:
add-show-splays, line_contents, master, stereo, svn/github/master, svn/origin/master, svn/tags/1.2.0, svn/tags/1.2.1, svn/tags/1.2.2, svn/tags/1.2.3, svn/tags/1.2.4, svn/tags/1.2.5, svn/trunk, travis-osx
Children:
fed3713
Parents:
d10d369
Message:

configure.in,src/moviemaker.cc,src/moviemaker.h: Use libswscale to
convert images to add to the video. Movie export now working
again!

git-svn-id: file:///home/survex-svn/survex/trunk@3619 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rd10d369 r9e516d0d  
     1Fri Jun 17 06:17:20 GMT 2011  Olly Betts <olly@survex.com>
     2
     3        * configure.in,src/moviemaker.cc,src/moviemaker.h: Use libswscale to
     4          convert images to add to the video.  Movie export now working
     5          again!
     6
    17Fri Jun 17 06:16:46 GMT 2011  Olly Betts <olly@survex.com>
    28
  • configure.in

    rd10d369 r9e516d0d  
    203203AC_CHECK_LIB(avcodec, avcodec_init,
    204204  [AC_CHECK_LIB(avformat, av_register_all,
    205     [AC_CHECK_HEADERS([libavformat/avformat.h],
    206       [MOVIE_LIBS="-lavformat -lavcodec"])], [], [-lavcodec $WX_LIBS])])
     205    [AC_CHECK_LIB(swscale, sws_scale,
     206      [AC_CHECK_HEADERS([libavformat/avformat.h],
     207        [MOVIE_LIBS="-lswscale -lavformat -lavcodec"])],
     208      [], [-lavformat -lavcodec $WX_LIBS])],
     209    [], [-lavcodec $WX_LIBS])
     210])
    207211AC_SUBST(MOVIE_LIBS)
    208212
  • src/moviemaker.cc

    rd10d369 r9e516d0d  
    6262extern "C" {
    6363#include "libavformat/avformat.h"
     64#include "libswscale/swscale.h"
    6465}
    6566#ifndef AV_PKT_FLAG_KEY
     
    7576
    7677MovieMaker::MovieMaker()
    77     : oc(0), st(0), frame(0), outbuf(0), in(0), out(0), pixels(0)
     78    : oc(0), st(0), frame(0), outbuf(0), pixels(0), sws_ctx(0)
    7879{
    7980#ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
     
    185186    }
    186187    int size = avpicture_get_size(c->pix_fmt, width, height);
    187     in = (unsigned char*)av_malloc(size);
    188     if (!in) {
     188    uint8_t * picture_buf = (uint8_t*)av_malloc(size);
     189    if (!picture_buf) {
    189190        av_free(frame);
    190191        // FIXME : out of memory
    191192        return false;
    192193    }
    193     avpicture_fill((AVPicture *)frame, in, c->pix_fmt, width, height);
    194 
    195     out = NULL;
     194    avpicture_fill((AVPicture *)frame, picture_buf, c->pix_fmt, width, height);
     195
    196196    if (c->pix_fmt != PIX_FMT_YUV420P) {
    197197        // FIXME need to allocate another frame for this case if we stop
     
    216216        return false;
    217217    }
     218
     219    av_free(sws_ctx);
     220    sws_ctx = sws_getContext(width, height, PIX_FMT_RGB24,
     221                             width, height, c->pix_fmt, SWS_BICUBIC,
     222                             NULL, NULL, NULL);
     223    if (sws_ctx == NULL) {
     224        fprintf(stderr, "Cannot initialize the conversion context!\n");
     225        return false;
     226    }
     227
    218228    return true;
    219229#else
     
    223233
    224234unsigned char * MovieMaker::GetBuffer() const {
    225     return pixels;
     235    AVCodecContext * c = st->codec;
     236    return pixels + c->height * c->width * 3;
    226237}
    227238
     
    256267    }
    257268
    258     const int len = 3 * c->width;
     269    int len = 3 * c->width;
    259270    const int h = c->height;
    260271    // Flip image vertically
     272    unsigned char * src = pixels + h * len;
     273    unsigned char * dest = src - len;
    261274    for (int y = 0; y < h; ++y) {
    262         memcpy(pixels + (2 * h - y - 1) * len, pixels + y * len, len);
    263     }
    264 
    265     // FIXME: Need to convert this to use sws_scale() instead of img_convert().
    266     //img_convert(out, PIX_FMT_YUV420P, in, PIX_FMT_RGB24, c->width, c->height);
     275        memcpy(dest, src, len);
     276        src += len;
     277        dest -= len;
     278    }
     279    sws_scale(sws_ctx, &pixels, &len, 0, c->height, frame->data, frame->linesize);
     280
    267281    if (oc->oformat->flags & AVFMT_RAWPICTURE) {
    268282        abort();
     
    336350    free(outbuf);
    337351    free(pixels);
    338     free(in);
    339     free(out);
     352    av_free(sws_ctx);
    340353
    341354    if (oc) {
  • src/moviemaker.h

    rd10d369 r9e516d0d  
    2525struct AVFrame;
    2626struct AVPicture;
     27struct SwsContext;
    2728
    2829class MovieMaker {
     
    3233    AVFrame *frame;
    3334    unsigned char *outbuf;
    34     unsigned char *in;
    3535    AVPicture *out;
    3636    unsigned char *pixels;
     37    SwsContext *sws_ctx;
    3738 
    3839public:
Note: See TracChangeset for help on using the changeset viewer.