Mercurial > projects > hoofbaby
diff src/impl/hoofbaby/codec/encoder.d @ 8:71ebad05f542
It seems to be successfully opening input files... Now to transcode!
author | fraserofthenight |
---|---|
date | Sun, 12 Jul 2009 03:49:39 -0700 |
parents | 270343d824ae |
children |
line wrap: on
line diff
--- a/src/impl/hoofbaby/codec/encoder.d Sun Jul 12 03:04:27 2009 -0700 +++ b/src/impl/hoofbaby/codec/encoder.d Sun Jul 12 03:49:39 2009 -0700 @@ -25,20 +25,23 @@ { // TODO convert asserts to exceptions - public const int OUTBUF_SIZE = 100000; + private const int OUTBUF_SIZE = 1 << 19; // 512 KB... Hopefully that should be enough for one packet - public AVOutputFormat* format; - public AVFormatContext* formatContext; + private AVOutputFormat* format; + private AVFormatContext* formatContext; + private bool fileOpen; - public AVCodec* audioCodec; - public AVCodecContext* audioContext; - public AVStream* audioStream; - public char* audioOutbuf; + private AVCodec* audioCodec; + private AVCodecContext* audioContext; + private AVStream* audioStream; + private char* audioOutbuf; + private bool audioOpen = false; - public AVCodec* videoCodec; - public AVCodecContext* videoContext; - public AVStream* videoStream; - public char* videoOutbuf; + private AVCodec* videoCodec; + private AVCodecContext* videoContext; + private AVStream* videoStream; + private char* videoOutbuf; + private bool videoOpen = false; public this(char[] filename) { @@ -60,7 +63,8 @@ // TODO remove ret = url_fopen(&formatContext.pb, toStringz(filename), URL_WRONLY) < 0; - assert(ret >= 0); + assert(ret >= 0, "Could not open output file"); + fileOpen = true; AVFormatParameters params; params.prealloced_context = 1; @@ -100,6 +104,7 @@ videoContext.flags |= CODEC_FLAG_GLOBAL_HEADER; ret = avcodec_open(videoContext, videoCodec); assert(ret >= 0, "Could not open video codec"); + videoOpen = true; videoOutbuf = cast(char*) av_malloc(OUTBUF_SIZE); assert(videoOutbuf !is null, "Could not allocate video output buffer"); @@ -123,6 +128,7 @@ audioContext.flags |= CODEC_FLAG_GLOBAL_HEADER; ret = avcodec_open(audioContext, audioCodec); assert(ret >= 0, "Could not open audio codec"); + audioOpen = true; audioOutbuf = cast(char*) av_malloc(OUTBUF_SIZE); assert(audioOutbuf !is null, "Could not allocate audio output buffer"); @@ -185,6 +191,9 @@ private void freeResources() { + if(videoOpen) avcodec_close(videoContext); + if(audioOpen) avcodec_close(audioContext); + if(fileOpen) url_fclose(formatContext.pb); if(formatContext) av_free(formatContext); if(audioOutbuf) av_free(audioOutbuf); if(videoOutbuf) av_free(videoOutbuf);