X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_libavcodec%2Ftrgt_av.cpp;h=da8cfc6ae8fc7a2fa9d77d69f502d364c3375b0a;hb=c35ae74eae4e92c031b0fc5083af957ee485b990;hp=fa0d7542c58941dffb2ffa0f2014e18bb1d6142c;hpb=e8a065f2385c219c511b57dac52786120bfa097d;p=synfig.git diff --git a/synfig-core/trunk/src/modules/mod_libavcodec/trgt_av.cpp b/synfig-core/trunk/src/modules/mod_libavcodec/trgt_av.cpp index fa0d754..da8cfc6 100644 --- a/synfig-core/trunk/src/modules/mod_libavcodec/trgt_av.cpp +++ b/synfig-core/trunk/src/modules/mod_libavcodec/trgt_av.cpp @@ -35,7 +35,7 @@ extern "C" { -#include "libavformat/avformat.h" +#include } #include @@ -307,7 +307,7 @@ public: AVCodecContext *context; //get from inside stream - context = &stream->codec; + context = stream->codec; //search for desired codec (contained in the stream) codec = avcodec_find_encoder(context->codec_id); @@ -374,7 +374,7 @@ public: int size, ret = 0; - AVCodecContext *context = &stream->codec; + AVCodecContext *context = stream->codec; /* If pict is invalid (NULL), then we are done compressing frames and we are trying to get @@ -396,23 +396,42 @@ public: pict = encodable; } + AVPacket pkt; + av_init_packet(&pkt); + pkt.stream_index = stream->index; + pkt.data = (uint8_t *)pict; + pkt.size = sizeof(AVPicture); + if( context->coded_frame ) + pkt.pts = context->coded_frame->pts; + if( context->coded_frame && context->coded_frame->key_frame) + pkt.flags |= PKT_FLAG_KEY; + //cludge for raw picture format (they said they'd fix) if (formatc->oformat->flags & AVFMT_RAWPICTURE) { - ret = av_write_frame(formatc, stream->index, (uint8_t *)pict, sizeof(AVPicture)); + ret = av_write_frame(formatc, &pkt); } else { //encode our given image size = avcodec_encode_video(context, &videobuffer[0], videobuffer.size(), pict); - //if not zero we've got stuff to write - if (size != 0) + //if greater than zero we've got stuff to write + if (size > 0) { - ret = av_write_frame(formatc, stream->index, &videobuffer[0], size); + av_init_packet(&pkt); + pkt.stream_index = stream->index; + pkt.data = &videobuffer[0]; + pkt.size = size; + if( context->coded_frame ) + pkt.pts = context->coded_frame->pts; + if( context->coded_frame && context->coded_frame->key_frame) + pkt.flags |= PKT_FLAG_KEY; + + ret = av_write_frame(formatc, &pkt); //error detect - possibly throw later... - if(ret != 0) + if(ret < 0) { synfig::warning("write_frame: error while writing video frame"); return false; @@ -438,7 +457,7 @@ public: void close(AVFormatContext *formatc, AVStream *stream) { if(stream) - avcodec_close(&stream->codec); + avcodec_close(stream->codec); if (encodable) { @@ -567,8 +586,9 @@ public: AVFormatParameters fmtparam,*ap = &fmtparam; memset(ap, 0, sizeof(*ap)); - ap->frame_rate = vInfo.fps; - ap->frame_rate_base = 1; + // FIXME: Port next two lines to recent libavcodec versions + //ap->frame_rate = vInfo.fps; + //ap->frame_rate_base = 1; ap->width = vInfo.w; ap->height = vInfo.h; //ap->pix_fmt = frame_pix_fmt; @@ -700,7 +720,7 @@ public: return 0; } - context = &st->codec; + context = st->codec; context->codec_id = (CodecID)codec_id; context->codec_type = CODEC_TYPE_VIDEO; @@ -714,8 +734,9 @@ public: context->bit_rate = info.bitrate; //TODO: Make dependant on the quality /* frames per second */ - context->frame_rate = info.fps; - context->frame_rate_base = 1; + // FIXME: Port next two lines to recent libavcodec versions + //context->frame_rate = info.fps; + //context->frame_rate_base = 1; /* "High Quality" */ context->mb_decision=FF_MB_DECISION_BITS; @@ -746,7 +767,7 @@ public: return 0; } - context = &stream->codec; + context = stream->codec; context->codec_id = (CodecID)codec_id; context->codec_type = CODEC_TYPE_AUDIO;