summaryrefslogtreecommitdiff
path: root/rotord/libavexporter.h
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/libavexporter.h')
-rw-r--r--rotord/libavexporter.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/rotord/libavexporter.h b/rotord/libavexporter.h
index df28c90..9ff72d7 100644
--- a/rotord/libavexporter.h
+++ b/rotord/libavexporter.h
@@ -133,7 +133,7 @@ namespace libav {
// audio output //
- static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
+ static int open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
{
AVCodecContext *c;
int ret;
@@ -167,6 +167,7 @@ namespace libav {
exit(1);
}
*/
+ return audio_input_frame_size;
}
// Prepare a 16 bit dummy audio frame of 'frame_size' samples and
@@ -198,13 +199,25 @@ namespace libav {
//get_audio_frame(samples, audio_input_frame_size, c->channels);
frame->nb_samples = audio_input_frame_size;
+ uint8_t *sampleptr;
+ int bufsize=audio_input_frame_size * av_get_bytes_per_sample(c->sample_fmt) *c->channels;
+ if (samples) {
+ sampleptr=(uint8_t*)samples;
+ }
+ else {
+ sampleptr=new uint8_t[bufsize];
+ memset(sampleptr,0,bufsize);
+ }
avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt,
- (uint8_t *)samples,
+ sampleptr,
audio_input_frame_size *
av_get_bytes_per_sample(c->sample_fmt) *
c->channels, 1);
ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
+ if (!samples) {
+ free(sampleptr);
+ }
if (ret < 0) {
//fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret));
exit(1);
@@ -399,12 +412,13 @@ namespace libav {
//av_free(outPixels); SIGSEV here
}
- class exporter {
+ class Exporter {
public:
bool setup(int w,int h, int bitRate, int frameRate, std::string container);
bool record(std::string filename);
- bool encodeFrame(unsigned char *pixels);
+ bool encodeFrame(unsigned char *pixels, uint16_t *samples);
void finishRecord();
+ int get_audio_framesize(){return size;};
private:
AVOutputFormat *fmt;
AVFormatContext *oc;
@@ -412,6 +426,7 @@ namespace libav {
AVCodec *audio_codec, *video_codec;
double audio_pts, video_pts;
+ int size;
int w;
int h;
int bitRate;
@@ -419,6 +434,7 @@ namespace libav {
std::string container;
int outputframe;
+
};
//************************************************************//