diff options
Diffstat (limited to 'rotord/src/libavwrapper.cpp')
| -rw-r--r-- | rotord/src/libavwrapper.cpp | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index ed0d0d0..ae770c4 100644 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -187,8 +187,11 @@ bool libav::exporter::record(std::string filename){ // Now that all the parameters are set, we can open the audio and // * video codecs and allocate the necessary encode buffers. // - if (video_st) - open_video(oc, video_codec, video_st); + if (video_st) { + if (!open_video(oc, video_codec, video_st)){ + return false; + } + } if (audio_st) { audioframesize=open_audio(oc, audio_codec, audio_st); audiostep=((float)audioframesize)/(audio_st->codec->sample_rate); @@ -200,8 +203,7 @@ bool libav::exporter::record(std::string filename){ av_dump_format(oc, 0, filename.c_str(), 1); // open the output file, if needed // - //if (!(fmt->flags & AVFMT_NOFILE)) { //removed 011013 trying to catch elusive crash - { + if (!(fmt->flags & AVFMT_NOFILE)) { Mutex::ScopedLock lock(mutex); int ret = avio_open(&oc->pb, filename.c_str(), AVIO_FLAG_WRITE); if (ret < 0) { @@ -315,9 +317,7 @@ void libav::exporter::finishRecord(){ if (audio_st) close_audio(oc, audio_st); - - //if (!(fmt->flags & AVFMT_NOFILE)) { //removed 011013 trying to catch elusive crash - { + if (!(fmt->flags & AVFMT_NOFILE)) { // Close the output file. // Mutex::ScopedLock lock(mutex); avio_close(oc->pb); @@ -405,65 +405,59 @@ AVStream* libav::exporter::add_stream(AVFormatContext *oc, AVCodec **codec,enum return st; } -void libav::exporter::open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st) +bool libav::exporter::open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st) { - printf("open video 1.\n"); int ret; AVCodecContext *c = st->codec; - printf("open video 2.\n"); // open the codec // { Mutex::ScopedLock lock(mutex); - printf("open video 3.\n"); ret = avcodec_open2(c, codec, NULL); //OPTIONS CAN GO HERE - printf("open video 4.\n"); + } if (ret < 0) { - //fprintf(stderr, "Could not open video codec: %s\n", av_err2str(ret)); - exit(1); + //string e=av_err2str(ret); + cerr<<"Could not open video codec"<<endl; + return false; } - printf("open video 5.\n"); + // allocate and init a re-usable frame // frame = avcodec_alloc_frame(); - printf("open video 6.\n"); + // moved to constructor and freeing in destructor -- stills crashes the same if (!frame) { - //fprintf(stderr, "Could not allocate video frame\n"); - exit(1); + cerr<<"Could not allocate video frame "<<endl; + return false; } - printf("open video 7.\n"); // Allocate the encoded raw picture. // ret = avpicture_alloc(&dst_picture, c->pix_fmt, c->width, c->height); if (ret < 0) { - //fprintf(stderr, "Could not allocate picture: %s\n", av_err2str(ret)); - exit(1); + //av_err2str(ret)<< + cerr<<"Could not allocate picture"<<endl; + return false; } - printf("open video 8.\n"); // If the output format is not YUV420P, then a temporary YUV420P // * picture is needed too. It is then converted to the required // * output format. // if (c->pix_fmt != AV_PIX_FMT_YUV420P) { ret = avpicture_alloc(&src_picture, AV_PIX_FMT_RGB24, c->width, c->height); if (ret < 0) { - //fprintf(stderr, "Could not allocate temporary picture: %s\n", - // av_err2str(ret)); - exit(1); + //<<av_err2str(ret) + cerr<<"Could not allocate temporary picture"<<endl; + return false; } } - printf("open video 9.\n"); - // copy data and linesize picture pointers to frame // *((AVPicture *)frame) = dst_picture; - printf("open video 10.\n"); - outPixels = (uint8_t*)av_malloc(avpicture_get_size(PIX_FMT_YUV420P, st->codec->width,st->codec->height)); + return true; } int libav::exporter::open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st) |
