summaryrefslogtreecommitdiff
path: root/rotord/libavexporter.h
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/libavexporter.h')
-rw-r--r--rotord/libavexporter.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/rotord/libavexporter.h b/rotord/libavexporter.h
index 9ff72d7..fd2da93 100644
--- a/rotord/libavexporter.h
+++ b/rotord/libavexporter.h
@@ -238,6 +238,61 @@ namespace libav {
avcodec_free_frame(&frame);
}
+ static void write_audio_frame(AVFormatContext *oc, AVStream *st,AVPacket *pkt)
+ {
+ /*
+ AVCodecContext *c;
+ AVPacket pkt = { 0 }; // data and size must be 0;
+ AVFrame *frame = avcodec_alloc_frame();
+ int got_packet, ret;
+
+ av_init_packet(&pkt);
+ c = st->codec;
+
+ //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,
+ 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);
+ }
+
+ if (!got_packet)
+ return;
+ */
+
+ pkt->stream_index = st->index;
+
+ // Write the compressed frame to the media file. //
+ int ret = av_interleaved_write_frame(oc, pkt);
+ if (ret != 0) {
+ //fprintf(stderr, "Error while writing audio frame: %s\n",
+ // av_err2str(ret));
+ exit(1);
+ }
+ //avcodec_free_frame(&frame);
+ av_free_packet(pkt);
+ }
+
+
static void close_audio(AVFormatContext *oc, AVStream *st)
{
avcodec_close(st->codec);
@@ -417,8 +472,10 @@ namespace libav {
bool setup(int w,int h, int bitRate, int frameRate, std::string container);
bool record(std::string filename);
bool encodeFrame(unsigned char *pixels, uint16_t *samples);
+ bool encodeFrame(unsigned char *pixels,AVPacket *audiopkt);
void finishRecord();
int get_audio_framesize(){return size;};
+
private:
AVOutputFormat *fmt;
AVFormatContext *oc;