source: git/src/moviemaker.cc @ ff7dec7

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey debian-1.2.27-1
Last change on this file since ff7dec7 was f4e4b56, checked in by Olly Betts <olly@…>, 9 years ago

Fix movie export to Unicode out path on wxMSW

  • Property mode set to 100644
File size: 15.6 KB
RevLine 
[6a4cdcb6]1//
2//  moviemaker.cc
3//
4//  Class for writing movies from Aven.
5//
[b282f44]6//  Copyright (C) 2004,2011,2012,2013,2014,2015,2016 Olly Betts
[6a4cdcb6]7//
8//  This program is free software; you can redistribute it and/or modify
9//  it under the terms of the GNU General Public License as published by
10//  the Free Software Foundation; either version 2 of the License, or
11//  (at your option) any later version.
12//
13//  This program is distributed in the hope that it will be useful,
14//  but WITHOUT ANY WARRANTY; without even the implied warranty of
15//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16//  GNU General Public License for more details.
17//
18//  You should have received a copy of the GNU General Public License
19//  along with this program; if not, write to the Free Software
[ecbc6c18]20//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
[6a4cdcb6]21//
22
[cc9e7a06]23/* Based on output-example.c:
24 *
25 * Libavformat API example: Output a media file in any supported
26 * libavformat format. The default codecs are used.
27 *
28 * Copyright (c) 2003 Fabrice Bellard
29 *
30 * Permission is hereby granted, free of charge, to any person obtaining a copy
31 * of this software and associated documentation files (the "Software"), to deal
32 * in the Software without restriction, including without limitation the rights
33 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34 * copies of the Software, and to permit persons to whom the Software is
35 * furnished to do so, subject to the following conditions:
36 *
37 * The above copyright notice and this permission notice shall be included in
38 * all copies or substantial portions of the Software.
39 *
40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46 * THE SOFTWARE.
47 */
48
[6a4cdcb6]49#ifdef HAVE_CONFIG_H
50#include <config.h>
51#endif
52
[cc9e7a06]53#define __STDC_CONSTANT_MACROS
54
[1805274]55#include <assert.h>
[6a4cdcb6]56#include <stdlib.h>
57#include <string.h>
58
59#include "moviemaker.h"
60
[f678705]61#ifdef WITH_LIBAV
[cc9e7a06]62extern "C" {
[b282f44]63# include <libavutil/imgutils.h>
[008f2f3]64# include <libavutil/mathematics.h>
[64d06c0]65# include <libavformat/avformat.h>
[86d8ee5]66# include <libswscale/swscale.h>
[cc9e7a06]67}
[7831cef]68# ifndef AV_PKT_FLAG_KEY
69#  define AV_PKT_FLAG_KEY PKT_FLAG_KEY
70# endif
71# ifndef HAVE_AV_GUESS_FORMAT
72#  define av_guess_format guess_format
73# endif
74# ifndef HAVE_AVIO_OPEN
75#  define avio_open url_fopen
76# endif
77# ifndef HAVE_AVIO_CLOSE
78#  define avio_close url_fclose
79# endif
[8364c65f]80# ifndef HAVE_AV_FRAME_ALLOC
81static inline AVFrame * av_frame_alloc() {
82    return avcodec_alloc_frame();
83}
84# endif
85# ifndef HAVE_AV_FRAME_FREE
86#  ifdef HAVE_AVCODEC_FREE_FRAME
87static inline void av_frame_free(AVFrame ** frame) {
88    avcodec_free_frame(frame);
89}
90#  else
91static inline void av_frame_free(AVFrame ** frame) {
[ec81f086]92    free((*frame)->data[0]);
93    free(*frame);
[e9ae5837]94    *frame = NULL;
[cc69cf5]95}
[8364c65f]96#  endif
[cc69cf5]97# endif
[86d8ee5]98# ifndef HAVE_AVCODEC_OPEN2
99// We always pass NULL for OPTS below.
100#  define avcodec_open2(CTX, CODEC, OPTS) avcodec_open(CTX, CODEC)
101# endif
102# ifndef HAVE_AVFORMAT_NEW_STREAM
103// We always pass NULL for CODEC below.
104#  define avformat_new_stream(S, CODEC) av_new_stream(S, 0)
105# endif
[7831cef]106# if !HAVE_DECL_AVMEDIA_TYPE_VIDEO
107#  define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
108# endif
[8364c65f]109# if !HAVE_DECL_AV_CODEC_ID_NONE
110#  define AV_CODEC_ID_NONE CODEC_ID_NONE
[64d06c0]111# endif
[ad04c87]112# if !HAVE_DECL_AV_PIX_FMT_RGB24
113#  define AV_PIX_FMT_RGB24 PIX_FMT_RGB24
114# endif
[64d06c0]115# if !HAVE_DECL_AV_PIX_FMT_YUV420P
116#  define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
117# endif
118# ifndef AVIO_FLAG_WRITE
119#  define AVIO_FLAG_WRITE URL_WRONLY
120# endif
[6a4cdcb6]121
[091069f]122enum {
123    MOVIE_NO_SUITABLE_FORMAT = 1,
124    MOVIE_AUDIO_ONLY,
[c648bd1]125    MOVIE_FILENAME_TOO_LONG
[091069f]126};
127
[bc6faa9]128# ifndef HAVE_AVCODEC_ENCODE_VIDEO2
[1805274]129const int OUTBUF_SIZE = 200000;
[bc6faa9]130# endif
131#endif
[6a4cdcb6]132
[1805274]133MovieMaker::MovieMaker()
[f678705]134#ifdef WITH_LIBAV
[64d06c0]135    : oc(0), video_st(0), frame(0), outbuf(0), pixels(0), sws_ctx(0), averrno(0)
[ccb83b7]136#endif
[6a4cdcb6]137{
[f678705]138#ifdef WITH_LIBAV
[6a4cdcb6]139    static bool initialised_ffmpeg = false;
[1805274]140    if (initialised_ffmpeg) return;
[6a4cdcb6]141
[1805274]142    // FIXME: register only the codec(s) we want to use...
[64d06c0]143    avcodec_register_all();
[1805274]144    av_register_all();
[6a4cdcb6]145
[1805274]146    initialised_ffmpeg = true;
147#endif
148}
149
[f4e4b56]150static int
151write_packet(void *opaque, uint8_t *buf, int buf_size) {
152    FILE * fh = (FILE*)opaque;
153    size_t res = fwrite(buf, 1, buf_size, fh);
154    return res > 0 ? res : -1;
155}
156
157#define MAX_EXTENSION_LEN 8
158
159bool MovieMaker::Open(FILE* fh, const char * ext, int width, int height)
[1805274]160{
[f678705]161#ifdef WITH_LIBAV
[f4e4b56]162    fh_to_close = fh;
163
164    AVOutputFormat * fmt = NULL;
165    char dummy_filename[MAX_EXTENSION_LEN + 3] = "x.";
166    if (strlen(ext) <= MAX_EXTENSION_LEN) {
167        strcpy(dummy_filename + 2, ext);
168        // Pass "x." + extension to av_guess_format() to avoid having to deal
169        // with wide character filenames.
170        fmt = av_guess_format(NULL, dummy_filename, NULL);
171    }
[1805274]172    if (!fmt) {
173        // We couldn't deduce the output format from file extension so default
174        // to MPEG.
[7831cef]175        fmt = av_guess_format("mpeg", NULL, NULL);
[1805274]176        if (!fmt) {
[091069f]177            averrno = MOVIE_NO_SUITABLE_FORMAT;
[1805274]178            return false;
179        }
[f4e4b56]180        strcpy(dummy_filename + 2, "mpg");
[1805274]181    }
[8364c65f]182    if (fmt->video_codec == AV_CODEC_ID_NONE) {
[091069f]183        averrno = MOVIE_AUDIO_ONLY;
[1805274]184        return false;
[6a4cdcb6]185    }
186
[64d06c0]187    /* Allocate the output media context. */
[6ed625e]188    oc = avformat_alloc_context();
[1805274]189    if (!oc) {
[63621a7]190        averrno = AVERROR(ENOMEM);
[1805274]191        return false;
[6a4cdcb6]192    }
[1805274]193    oc->oformat = fmt;
[f4e4b56]194    strcpy(oc->filename, dummy_filename);
[6a4cdcb6]195
[64d06c0]196    /* find the video encoder */
197    AVCodec *codec = avcodec_find_encoder(fmt->video_codec);
198    if (!codec) {
199        // FIXME : Erm - internal ffmpeg library problem?
[63621a7]200        averrno = AVERROR(ENOMEM);
[1805274]201        return false;
[6a4cdcb6]202    }
203
[64d06c0]204    // Add the video stream.
205    video_st = avformat_new_stream(oc, codec);
206    if (!video_st) {
207        averrno = AVERROR(ENOMEM);
208        return false;
209    }
[6a4cdcb6]210
211    // Set sample parameters.
[64d06c0]212    AVCodecContext *c = video_st->codec;
[6a4cdcb6]213    c->bit_rate = 400000;
[64d06c0]214    /* Resolution must be a multiple of two. */
[1805274]215    c->width = width;
216    c->height = height;
[64d06c0]217    /* timebase: This is the fundamental unit of time (in seconds) in terms
218     * of which frame timestamps are represented. For fixed-fps content,
219     * timebase should be 1/framerate and timestamp increments should be
220     * identical to 1. */
[5270758]221#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(55, 44, 0)
222    // Old way, which now causes deprecation warnings.
[cc9e7a06]223    c->time_base.den = 25; // Frames per second.
[64d06c0]224    c->time_base.num = 1;
[5270758]225#else
226    video_st->time_base.den = 25; // Frames per second.
227    video_st->time_base.num = 1;
228    c->time_base = video_st->time_base;
229#endif
[64d06c0]230    c->gop_size = 12; /* emit one intra frame every twelve frames at most */
231    c->pix_fmt = AV_PIX_FMT_YUV420P;
[997509d]232    c->rc_buffer_size = c->bit_rate * 4; // Enough for 4 seconds
[5270758]233    c->rc_max_rate = c->bit_rate * 2;
[1805274]234    // B frames are backwards predicted - they can improve compression,
235    // but may slow encoding and decoding.
[64d06c0]236    // if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
237    //     c->max_b_frames = 2;
238    // }
[6a4cdcb6]239
[64d06c0]240    /* Some formats want stream headers to be separate. */
[cc9e7a06]241    if (oc->oformat->flags & AVFMT_GLOBALHEADER)
242        c->flags |= CODEC_FLAG_GLOBAL_HEADER;
243
[7831cef]244    int retval;
245#ifndef HAVE_AVFORMAT_WRITE_HEADER
[1805274]246    // Set the output parameters (must be done even if no parameters).
[7831cef]247    retval = av_set_parameters(oc, NULL);
[091069f]248    if (retval < 0) {
249        averrno = retval;
[1805274]250        return false;
251    }
[7831cef]252#endif
[1805274]253
[64d06c0]254    retval = avcodec_open2(c, NULL, NULL);
[091069f]255    if (retval < 0) {
256        averrno = retval;
[1805274]257        return false;
[6a4cdcb6]258    }
[1805274]259
[64d06c0]260#ifndef HAVE_AVCODEC_ENCODE_VIDEO2
261    outbuf = NULL;
262    if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
[d13aea6]263        outbuf = (unsigned char *)av_malloc(OUTBUF_SIZE);
[cc9e7a06]264        if (!outbuf) {
[63621a7]265            averrno = AVERROR(ENOMEM);
[cc9e7a06]266            return false;
267        }
[6a4cdcb6]268    }
[64d06c0]269#endif
[1805274]270
[64d06c0]271    /* Allocate the encoded raw picture. */
[8364c65f]272    frame = av_frame_alloc();
[cc9e7a06]273    if (!frame) {
[63621a7]274        averrno = AVERROR(ENOMEM);
[1805274]275        return false;
[6a4cdcb6]276    }
[b282f44]277    retval = av_image_alloc(frame->data, frame->linesize,
278                            c->width, c->height, c->pix_fmt, 1);
[64d06c0]279    if (retval < 0) {
280        averrno = retval;
[1805274]281        return false;
[6a4cdcb6]282    }
[cc9e7a06]283
[8364c65f]284    if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
[cc9e7a06]285        // FIXME need to allocate another frame for this case if we stop
[8364c65f]286        // hardcoding AV_PIX_FMT_YUV420P.
[cc9e7a06]287        abort();
288    }
[6a4cdcb6]289
[5270758]290    frame->format = c->pix_fmt;
291    frame->width = c->width;
292    frame->height = c->height;
293
[d13aea6]294    pixels = (unsigned char *)av_malloc(width * height * 6);
[6a4cdcb6]295    if (!pixels) {
[63621a7]296        averrno = AVERROR(ENOMEM);
[1805274]297        return false;
[6a4cdcb6]298    }
[1805274]299
[64d06c0]300    // Show the format we've ended up with (for debug purposes).
301    // av_dump_format(oc, 0, fnm, 1);
302
303    av_free(sws_ctx);
[ad04c87]304    sws_ctx = sws_getContext(width, height, AV_PIX_FMT_RGB24,
[64d06c0]305                             width, height, c->pix_fmt, SWS_BICUBIC,
306                             NULL, NULL, NULL);
307    if (sws_ctx == NULL) {
308        fprintf(stderr, "Cannot initialize the conversion context!\n");
309        averrno = AVERROR(ENOMEM);
[1805274]310        return false;
311    }
312
[64d06c0]313    if (!(fmt->flags & AVFMT_NOFILE)) {
[f4e4b56]314        const int buf_size = 8192;
315        void * buf = av_malloc(buf_size);
316        oc->pb = avio_alloc_context(static_cast<uint8_t*>(buf), buf_size, 1,
317                                    fh, NULL, write_packet, NULL);
318        if (!oc->pb) {
319            averrno = AVERROR(ENOMEM);
[64d06c0]320            return false;
321        }
322    }
323
[1805274]324    // Write the stream header, if any.
[7831cef]325#ifdef HAVE_AVFORMAT_WRITE_HEADER
326    retval = avformat_write_header(oc, NULL);
327#else
[091069f]328    retval = av_write_header(oc);
[7831cef]329#endif
[091069f]330    if (retval < 0) {
331        averrno = retval;
[1805274]332        return false;
333    }
[9e516d0d]334
[091069f]335    averrno = 0;
[1805274]336    return true;
[6a4cdcb6]337#else
[f4e4b56]338    (void)fh;
339    (void)ext;
[6e22f11]340    (void)width;
341    (void)height;
[6a4cdcb6]342    return false;
343#endif
344}
345
346unsigned char * MovieMaker::GetBuffer() const {
[f678705]347#ifdef WITH_LIBAV
[64d06c0]348    AVCodecContext * c = video_st->codec;
[9e516d0d]349    return pixels + c->height * c->width * 3;
[eac4514]350#else
351    return NULL;
352#endif
[6a4cdcb6]353}
354
355int MovieMaker::GetWidth() const {
[f678705]356#ifdef WITH_LIBAV
[ccb83b7]357    assert(video_st);
[64d06c0]358    AVCodecContext *c = video_st->codec;
[6a4cdcb6]359    return c->width;
[1805274]360#else
361    return 0;
362#endif
[6a4cdcb6]363}
364
365int MovieMaker::GetHeight() const {
[f678705]366#ifdef WITH_LIBAV
[ccb83b7]367    assert(video_st);
[64d06c0]368    AVCodecContext *c = video_st->codec;
[6a4cdcb6]369    return c->height;
[1805274]370#else
371    return 0;
372#endif
[6a4cdcb6]373}
374
[98fd937]375bool MovieMaker::AddFrame()
[6a4cdcb6]376{
[f678705]377#ifdef WITH_LIBAV
[64d06c0]378    AVCodecContext * c = video_st->codec;
[cc9e7a06]379
[8364c65f]380    if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
[cc9e7a06]381        // FIXME convert...
382        abort();
383    }
[1805274]384
[9e516d0d]385    int len = 3 * c->width;
[fed3713]386    {
387        // Flip image vertically
388        int h = c->height;
389        unsigned char * src = pixels + h * len;
390        unsigned char * dest = src - len;
391        while (h--) {
392            memcpy(dest, src, len);
393            src += len;
394            dest -= len;
395        }
[6a4cdcb6]396    }
[9e516d0d]397    sws_scale(sws_ctx, &pixels, &len, 0, c->height, frame->data, frame->linesize);
[6a4cdcb6]398
[cc9e7a06]399    if (oc->oformat->flags & AVFMT_RAWPICTURE) {
400        abort();
401    }
[6a4cdcb6]402
[1805274]403    // Encode this frame.
[64d06c0]404#ifdef HAVE_AVCODEC_ENCODE_VIDEO2
[710bd97]405    AVPacket pkt;
[64d06c0]406    int got_packet;
407    av_init_packet(&pkt);
[710bd97]408    pkt.data = NULL;
[64d06c0]409
410    int ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
411    if (ret < 0) {
[98fd937]412        averrno = ret;
413        return false;
[64d06c0]414    }
415    if (got_packet && pkt.size) {
416        // Write the compressed frame to the media file.
[710bd97]417        if (pkt.pts != int64_t(AV_NOPTS_VALUE)) {
[64d06c0]418            pkt.pts = av_rescale_q(pkt.pts,
419                                   c->time_base, video_st->time_base);
420        }
[710bd97]421        if (pkt.dts != int64_t(AV_NOPTS_VALUE)) {
[64d06c0]422            pkt.dts = av_rescale_q(pkt.dts,
423                                   c->time_base, video_st->time_base);
424        }
425        pkt.stream_index = video_st->index;
426
427        /* Write the compressed frame to the media file. */
[98fd937]428        ret = av_interleaved_write_frame(oc, &pkt);
429        if (ret < 0) {
430            averrno = ret;
431            return false;
[64d06c0]432        }
433    }
434#else
[6a4cdcb6]435    out_size = avcodec_encode_video(c, outbuf, OUTBUF_SIZE, frame);
[1805274]436    // outsize == 0 means that this frame has been buffered, so there's nothing
437    // to write yet.
[cc9e7a06]438    if (out_size) {
[1805274]439        // Write the compressed frame to the media file.
[cc9e7a06]440        AVPacket pkt;
441        av_init_packet(&pkt);
442
[63621a7]443        if (c->coded_frame->pts != (int64_t)AV_NOPTS_VALUE)
[64d06c0]444            pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
[cc9e7a06]445        if (c->coded_frame->key_frame)
446            pkt.flags |= AV_PKT_FLAG_KEY;
[64d06c0]447        pkt.stream_index = video_st->index;
[cc9e7a06]448        pkt.data = outbuf;
449        pkt.size = out_size;
450
[64d06c0]451        /* Write the compressed frame to the media file. */
[98fd937]452        int ret = av_interleaved_write_frame(oc, &pkt);
453        if (ret < 0) {
454            averrno = ret;
455            return false;
[1805274]456        }
[6a4cdcb6]457    }
458#endif
[64d06c0]459#endif
[98fd937]460    return true;
[6a4cdcb6]461}
462
[98fd937]463bool
464MovieMaker::Close()
[6a4cdcb6]465{
[f678705]466#ifdef WITH_LIBAV
[64d06c0]467    if (video_st && averrno == 0) {
[1805274]468        // No more frames to compress.  The codec may have a few frames
469        // buffered if we're using B frames, so write those too.
[64d06c0]470        AVCodecContext * c = video_st->codec;
[1805274]471
[64d06c0]472#ifdef HAVE_AVCODEC_ENCODE_VIDEO2
473        while (1) {
[710bd97]474            AVPacket pkt;
[64d06c0]475            int got_packet;
476            av_init_packet(&pkt);
[710bd97]477            pkt.data = NULL;
[5270758]478            pkt.size = 0;
[64d06c0]479
480            int ret = avcodec_encode_video2(c, &pkt, NULL, &got_packet);
481            if (ret < 0) {
[98fd937]482                release();
483                averrno = ret;
484                return false;
[64d06c0]485            }
486            if (!got_packet) break;
487            if (!pkt.size) continue;
488
489            // Write the compressed frame to the media file.
[710bd97]490            if (pkt.pts != int64_t(AV_NOPTS_VALUE)) {
[64d06c0]491                pkt.pts = av_rescale_q(pkt.pts,
492                                       c->time_base, video_st->time_base);
493            }
[710bd97]494            if (pkt.dts != int64_t(AV_NOPTS_VALUE)) {
[64d06c0]495                pkt.dts = av_rescale_q(pkt.dts,
496                                       c->time_base, video_st->time_base);
497            }
498            pkt.stream_index = video_st->index;
499
500            /* Write the compressed frame to the media file. */
[98fd937]501            ret = av_interleaved_write_frame(oc, &pkt);
502            if (ret < 0) {
503                release();
504                averrno = ret;
505                return false;
[64d06c0]506            }
507        }
508#else
[1805274]509        while (out_size) {
510            out_size = avcodec_encode_video(c, outbuf, OUTBUF_SIZE, NULL);
511            if (out_size) {
[cc9e7a06]512                // Write the compressed frame to the media file.
513                AVPacket pkt;
514                av_init_packet(&pkt);
515
[63621a7]516                if (c->coded_frame->pts != (int64_t)AV_NOPTS_VALUE)
[64d06c0]517                    pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
[cc9e7a06]518                if (c->coded_frame->key_frame)
519                    pkt.flags |= AV_PKT_FLAG_KEY;
[64d06c0]520                pkt.stream_index = video_st->index;
[cc9e7a06]521                pkt.data = outbuf;
522                pkt.size = out_size;
523
524                /* write the compressed frame in the media file */
[98fd937]525                int ret = av_interleaved_write_frame(oc, &pkt);
526                if (ret < 0) {
527                    release();
528                    averrno = ret;
529                    return false;
[1805274]530                }
531            }
[6a4cdcb6]532        }
[64d06c0]533#endif
[6a4cdcb6]534
[cc9e7a06]535        av_write_trailer(oc);
[091069f]536    }
[cc9e7a06]537
[98fd937]538    release();
539#endif
540    return true;
541}
542
[f678705]543#ifdef WITH_LIBAV
[98fd937]544void
545MovieMaker::release()
546{
[64d06c0]547    if (video_st) {
[1805274]548        // Close codec.
[64d06c0]549        avcodec_close(video_st->codec);
[98fd937]550        video_st = NULL;
[6a4cdcb6]551    }
552
[cc9e7a06]553    if (frame) {
[8364c65f]554        av_frame_free(&frame);
[cc9e7a06]555    }
[d13aea6]556    av_free(pixels);
[98fd937]557    pixels = NULL;
[d13aea6]558    av_free(outbuf);
[98fd937]559    outbuf = NULL;
[9e516d0d]560    av_free(sws_ctx);
[98fd937]561    sws_ctx = NULL;
[1805274]562
563    if (oc) {
564        // Free the streams.
[cc9e7a06]565        for (size_t i = 0; i < oc->nb_streams; ++i) {
566            av_freep(&oc->streams[i]->codec);
[1805274]567            av_freep(&oc->streams[i]);
568        }
569
[cc9e7a06]570        if (!(oc->oformat->flags & AVFMT_NOFILE)) {
[f4e4b56]571            // Release the AVIOContext.
572            av_free(oc->pb);
[cc9e7a06]573        }
[1805274]574
575        // Free the stream.
[6ed625e]576        av_free(oc);
[98fd937]577        oc = NULL;
[1805274]578    }
[f4e4b56]579    if (fh_to_close) {
580        fclose(fh_to_close);
581        fh_to_close = NULL;
582    }
[6a4cdcb6]583}
[c648bd1]584#endif
[091069f]585
[98fd937]586MovieMaker::~MovieMaker()
587{
[f678705]588#ifdef WITH_LIBAV
[98fd937]589    release();
[c648bd1]590#endif
[98fd937]591}
592
[091069f]593const char *
594MovieMaker::get_error_string() const
595{
[f678705]596#ifdef WITH_LIBAV
[091069f]597    switch (averrno) {
[63621a7]598        case AVERROR(EIO):
[091069f]599            return "I/O error";
[63621a7]600        case AVERROR(EDOM):
[091069f]601            return "Number syntax expected in filename";
602        case AVERROR_INVALIDDATA:
603            /* same as AVERROR_UNKNOWN: return "unknown error"; */
604            return "invalid data found";
[63621a7]605        case AVERROR(ENOMEM):
[091069f]606            return "not enough memory";
[63621a7]607        case AVERROR(EILSEQ):
[091069f]608            return "unknown format";
[63621a7]609        case AVERROR(ENOSYS):
[091069f]610            return "Operation not supported";
[63621a7]611        case AVERROR(ENOENT):
[091069f]612            return "No such file or directory";
613        case AVERROR_EOF:
614            return "End of file";
615        case AVERROR_PATCHWELCOME:
616            return "Not implemented in FFmpeg";
617        case 0:
618            return "No error";
619        case MOVIE_NO_SUITABLE_FORMAT:
620            return "Couldn't find a suitable output format";
621        case MOVIE_AUDIO_ONLY:
622            return "Audio-only format specified";
623        case MOVIE_FILENAME_TOO_LONG:
624            return "Filename too long";
625    }
[eac4514]626#endif
[f4e4b56]627    return "Unknown error";
[091069f]628}
Note: See TracBrowser for help on using the repository browser.