diff options
| -rwxr-xr-x | rotord/ofxMovieExporter.cpp | 43 | ||||
| -rwxr-xr-x | rotord/ofxMovieExporter.h | 4 | ||||
| -rwxr-xr-x | rotord/rotor.cpp | 2 |
3 files changed, 44 insertions, 5 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); } diff --git a/rotord/ofxMovieExporter.h b/rotord/ofxMovieExporter.h index 507751e..4682107 100755 --- a/rotord/ofxMovieExporter.h +++ b/rotord/ofxMovieExporter.h @@ -170,6 +170,10 @@ class ofxMovieExporter AVCodec* codec; AVCodecContext* codecCtx; + AVCodec* acodec; + AVCodecContext* acodecCtx; + + SwsContext* convertCtx; unsigned char* inPixels; diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 975ec85..b06122f 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 ="mov"; + std::string container ="m4v"; if (exporter->setup(outW,outH,bitRate,frameRate,codecId,container)) { |
