summaryrefslogtreecommitdiff
path: root/rotord/ofxMovieExporter.cpp
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-04-18 02:05:13 +0100
committerComment <tim@gray.(none)>2013-04-18 02:05:13 +0100
commit295bd6aa3509ed07b998f2b98cfe4852da317ec2 (patch)
tree06cf0beed692978d6bb2ba2af278cfd5351b37e7 /rotord/ofxMovieExporter.cpp
parentbd728800f22d6086ef1c901d7a212d655640c97c (diff)
muxing audio
Diffstat (limited to 'rotord/ofxMovieExporter.cpp')
-rwxr-xr-xrotord/ofxMovieExporter.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/rotord/ofxMovieExporter.cpp b/rotord/ofxMovieExporter.cpp
index ef5b783..d57c8a3 100755
--- a/rotord/ofxMovieExporter.cpp
+++ b/rotord/ofxMovieExporter.cpp
@@ -33,7 +33,7 @@
//#include "ofThread.h"
const std::string ofxMovieExporter::FILENAME_PREFIX = "capture";
- const std::string ofxMovieExporter::CONTAINER = "mp4";
+ const std::string ofxMovieExporter::CONTAINER = "mov";
ofxMovieExporter::ofxMovieExporter() {
outputFormat = NULL;
@@ -216,6 +216,7 @@
pkt.size = outSize;
av_write_frame(formatCtx, &pkt);
}
+
frameNum++;
}
@@ -248,6 +249,20 @@
}
//is it as simple as writing an audio packet for every video packet?
+ // avcodec_encode_audio2(AVCodecContext *avctx,AVPacket *avpkt,const AVFrame *frame,int *got_packet_ptr);
+ AVPacket apkt;
+ AVFrame afrm;
+
+ afrm.nb_samples=44100/25;
+ afrm.format=AV_SAMPLE_FMT_S16;
+ uint8_t *d=new uint8_t[afrm.nb_samples*2*2];
+ afrm.data[0]=d;
+
+ int gpp;
+
+ int audioOutSize = avcodec_encode_audio2(acodecCtx,&apkt,&afrm,&gpp);
+
+ av_write_frame(formatCtx, &apkt);
frameNum++;
@@ -295,6 +310,8 @@
codec = avcodec_find_encoder(codecId);
//if (!codec) ofLog(OF_LOG_ERROR, "ofxMovieExporter: Codec not found");
+
+
////////////////////////////////////////////////////////////
// auto detect the output format from the name. default is mpeg.
ostringstream oss;
@@ -304,6 +321,7 @@
// set the format codec (the format also has a default codec that can be read from it)
outputFormat->video_codec = codec->id;
+ acodec = avcodec_find_encoder(outputFormat->audio_codec);
//--------------------------->
//leaving the audio codec at the default for now
//--------------------------->
@@ -314,11 +332,14 @@
//if (!formatCtx) ofLog(OF_LOG_ERROR, "ofxMovieExporter: Could not allocate format context");
formatCtx->oformat = outputFormat;
+
+
/////////////////////////////////////////////////////////////
// set up the video stream
- videoStream = av_new_stream(formatCtx, 0);
+ videoStream = avformat_new_stream(formatCtx,codec);
+ //videoStream = av_new_stream(formatCtx, 0);
+
-
/////////////////////////////////////////////////////////////
// init codec context for video
codecCtx = videoStream->codec;
@@ -367,6 +388,20 @@
// < 0) ofLog(OF_LOG_ERROR, "ofxMovieExproter: Could not open codec");
//do all the same for audio?
- //audioStream = av_new_stream(formatCtx, 1); //???
+ audioStream = av_new_stream(formatCtx, 1); //???
+ acodecCtx = audioStream->codec;
+ acodecCtx->sample_rate=44100;
+ acodecCtx->sample_fmt=AV_SAMPLE_FMT_S16;
+ acodecCtx->channels=2;
+ acodecCtx->channel_layout=AV_CH_LAYOUT_STEREO;
+ avcodec_open2(acodecCtx, acodec,&options);
+
+ if (outputFormat->flags & AVFMT_GLOBALHEADER) {
+ videoStream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
+ audioStream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
+ }
+
+
+ av_dump_format(formatCtx, 0, oss.str().c_str(), 1);
}