summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-04-18 18:06:11 +0100
committerTim Redfern <tim@herge.(none)>2013-04-18 18:06:11 +0100
commit8f75260c27d739aad3b019d29ba4178ba8ce55b5 (patch)
treed048e0d44cffe75c01cce40e5baaeb62c0c52cce
parent295bd6aa3509ed07b998f2b98cfe4852da317ec2 (diff)
audio writing with an error
-rwxr-xr-xrotord/ofxMovieExporter.cpp39
-rwxr-xr-xrotord/rotor.cpp2
-rw-r--r--rotord/rotord.cbp1
3 files changed, 26 insertions, 16 deletions
diff --git a/rotord/ofxMovieExporter.cpp b/rotord/ofxMovieExporter.cpp
index d57c8a3..815daa1 100755
--- a/rotord/ofxMovieExporter.cpp
+++ b/rotord/ofxMovieExporter.cpp
@@ -216,7 +216,7 @@
pkt.size = outSize;
av_write_frame(formatCtx, &pkt);
}
-
+
frameNum++;
}
@@ -245,24 +245,33 @@
pkt.stream_index = videoStream->index;
pkt.data = encodedBuf;
pkt.size = outSize;
- av_write_frame(formatCtx, &pkt);
+ av_interleaved_write_frame(formatCtx, &pkt);
}
//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;
+ av_init_packet(&apkt);
+ apkt.pts = (int64_t)frameNum*(frameInterval*(((float)videoStream->time_base.den)/videoStream->time_base.num));//ofGetFrameNum();//codecCtx->coded_frame->pts;
+ apkt.flags |= AV_PKT_FLAG_KEY;
+ apkt.dts = apkt.pts;
+ apkt.stream_index = audioStream->index;
+ //apkt.data = encodedBuf;
+ apkt.size = outSize;
+
+ AVFrame* afrm=avcodec_alloc_frame();
+ 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);
+ //avcodec_fill_audio_frame(afrm, 2, AV_SAMPLE_FMT_S16,(uint8_t *)d,(44100/25) * 2 * 2,1);
+
+ int audioOutSize = avcodec_encode_audio2(acodecCtx,&apkt,afrm,&gpp);
+
+ av_interleaved_write_frame(formatCtx, &apkt);
frameNum++;
@@ -310,7 +319,7 @@
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.
@@ -338,8 +347,8 @@
// set up the video stream
videoStream = avformat_new_stream(formatCtx,codec);
//videoStream = av_new_stream(formatCtx, 0);
-
-
+
+
/////////////////////////////////////////////////////////////
// init codec context for video
codecCtx = videoStream->codec;
@@ -351,7 +360,7 @@
codecCtx->time_base.den = frameRate;
videoStream->time_base = codecCtx->time_base;
//audioStream->time_base = codecCtx->time_base; //???has the capability of crashing
-
+
codecCtx->gop_size = 10; /* emit one intra frame every ten frames */
codecCtx->pix_fmt = PIX_FMT_YUV420P;
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
index b06122f..975ec85 100755
--- a/rotord/rotor.cpp
+++ b/rotord/rotor.cpp
@@ -768,7 +768,7 @@ bool Video_output::render(const float duration, const float framerate,const stri
int bitRate=4000000;
int frameRate=25;
AVCodecID codecId=AV_CODEC_ID_MPEG4;
- std::string container ="m4v";
+ std::string container ="mov";
if (exporter->setup(outW,outH,bitRate,frameRate,codecId,container)) {
diff --git a/rotord/rotord.cbp b/rotord/rotord.cbp
index 6bae8c7..566a10c 100644
--- a/rotord/rotord.cbp
+++ b/rotord/rotord.cbp
@@ -49,6 +49,7 @@
<Add option="-Wall" />
</Compiler>
<Unit filename="Makefile" />
+ <Unit filename="avCodec.h" />
<Unit filename="ofUtils.cpp" />
<Unit filename="ofUtils.h" />
<Unit filename="ofxMovieExporter.cpp" />