diff options
Diffstat (limited to 'rotord/src/libavwrapper.cpp')
| -rw-r--r-- | rotord/src/libavwrapper.cpp | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index b7b5688..321725e 100644 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -80,8 +80,9 @@ void libav::maybeInitFFMpegLib() { if (b_is_one_time_inited) return; - av_register_all(); - avcodec_register_all(); + FFMS_Init(0, 0); //should do for all + //av_register_all(); + //avcodec_register_all(); avformat_network_init(); b_is_one_time_inited = true; } @@ -556,7 +557,56 @@ bool libav::decoder::avtry(int result, const std::string& msg) { return true; } + void libav::ffms2_decoder::cleanup(){ + if (loaded) { + mutex.lock(); + FFMS_DestroyVideoSource(videosource); + mutex.unlock(); + loaded=false; + } +} +bool libav::ffms2_decoder::open(const std::string& filename){ + mutex.lock(); + loaded=false; + FFMS_Index *index = FFMS_MakeIndex(filename.c_str(), 0, 0, NULL, NULL, FFMS_IEH_ABORT, NULL, NULL, &errinfo); + if (index == NULL) { + std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + mutex.unlock(); + return false; + } + int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_VIDEO, &errinfo); + if (trackno < 0) { + std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + mutex.unlock(); + return false; + } + videosource = FFMS_CreateVideoSource(filename.c_str(), trackno, index, 1, FFMS_SEEK_NORMAL, &errinfo); + if (videosource == NULL) { + std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + mutex.unlock(); + return false; + } + FFMS_DestroyIndex(index); + videoprops = FFMS_GetVideoProperties(videosource); + const FFMS_Frame *propframe = FFMS_GetFrame(videosource, 0, &errinfo); + w=propframe->EncodedWidth; + h=propframe->EncodedHeight; + //propframe->EncodedPixelFormat; + + if (FFMS_SetOutputFormatV2(videosource, pixfmts, propframe->EncodedWidth, propframe->EncodedHeight, FFMS_RESIZER_BICUBIC, &errinfo)) { + std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + mutex.unlock(); + return false; + } + int framenumber = 0; /* valid until next call to FFMS_GetFrame* on the same video object */ + + + std::cerr<<"ffmpegsource: successfully opened "<<filename<<std::endl; + loaded=true; + mutex.unlock(); + return loaded; +} /////////////////////////// // encoder methods // @@ -1245,7 +1295,7 @@ void libav::exporter::open_video(AVFormatContext *oc, AVCodec *codec, AVStream * AVFrame *frame = avcodec_alloc_frame(); int got_packet, ret; - av_init_packet(&pkt); + //av_init_packet(&pkt); 111013 NOT NECESSARY c = st->codec; //get_audio_frame(samples, audio_input_frame_size, c->channels); @@ -1406,7 +1456,7 @@ void libav::exporter::open_video(AVFormatContext *oc, AVCodec *codec, AVStream * if (oc->oformat->flags & AVFMT_RAWPICTURE) { // Raw video case - directly store the picture in the packet // AVPacket pkt; - av_init_packet(&pkt); + //av_init_packet(&pkt); ///removed 101013 NOT NECESSARY pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index = st->index; @@ -1418,7 +1468,7 @@ void libav::exporter::open_video(AVFormatContext *oc, AVCodec *codec, AVStream * } else { AVPacket pkt = { 0 }; int got_packet; - av_init_packet(&pkt); + //av_init_packet(&pkt); ///removed 101013 NOT NECESSARY // encode the image // |
