rename frame to out_frame. Fix problem where we weren't copying from in_frame to out_frame

This commit is contained in:
Isaac Connor 2017-11-17 18:19:37 -05:00
parent f5f45b3397
commit 882563c06e
4 changed files with 27 additions and 26 deletions

View File

@ -2891,7 +2891,7 @@ packet->reset();
return -1;
} else if ( captureResult > 0 ) {
if ( packet->packet.size && ! packet->frame ) {
if ( packet->packet.size && ! packet->in_frame ) {
if ( packet->packet.stream_index == camera->get_VideoStreamId() ) {
packet->decode( camera->get_VideoCodecContext() );
packet->get_image();

View File

@ -26,9 +26,10 @@ using namespace std;
ZMPacket::ZMPacket( ) {
keyframe = 0;
image = NULL;
// frame from decoded packet, to be used in generating image
in_frame = NULL;
frame = NULL;
out_frame = NULL;
image = NULL;
buffer = NULL;
av_init_packet( &packet );
packet.size = 0; // So we can detect whether it has been filled.
@ -39,25 +40,23 @@ ZMPacket::ZMPacket( Image *i ) {
keyframe = 1;
image = i;
in_frame = NULL;
frame = NULL;
out_frame = NULL;
buffer = NULL;
av_init_packet( &packet );
timestamp = (struct timeval){0};
}
ZMPacket::ZMPacket( AVPacket *p ) {
frame = NULL;
image = NULL;
av_init_packet( &packet );
set_packet( p );
keyframe = p->flags & AV_PKT_FLAG_KEY;
buffer = NULL;
in_frame = NULL;
frame = NULL;
out_frame = NULL;
}
ZMPacket::ZMPacket( AVPacket *p, struct timeval *t ) {
frame = NULL;
image = NULL;
av_init_packet( &packet );
set_packet( p );
@ -65,16 +64,15 @@ ZMPacket::ZMPacket( AVPacket *p, struct timeval *t ) {
keyframe = p->flags & AV_PKT_FLAG_KEY;
buffer = NULL;
in_frame = NULL;
frame = NULL;
out_frame = NULL;
}
ZMPacket::ZMPacket( AVPacket *p, AVFrame *f, Image *i ) {
av_init_packet( &packet );
set_packet( p );
image = i;
frame = f;
buffer = NULL;
in_frame = NULL;
frame = NULL;
out_frame = f;
}
ZMPacket::~ZMPacket() {
@ -83,9 +81,9 @@ ZMPacket::~ZMPacket() {
//av_free(frame->data);
av_frame_free( &in_frame );
}
if ( frame ) {
if ( out_frame ) {
//av_free(frame->data);
av_frame_free( &frame );
av_frame_free( &out_frame );
}
if ( buffer ) {
av_freep( &buffer );
@ -102,9 +100,9 @@ void ZMPacket::reset() {
//Debug(4,"reset frame");
av_frame_free( &in_frame );
}
if ( frame ) {
if ( out_frame ) {
//Debug(4,"reset frame");
av_frame_free( &frame );
av_frame_free( &out_frame );
}
if ( buffer ) {
//Debug(4,"freeing buffer");

View File

@ -36,14 +36,14 @@ class ZMPacket {
int keyframe;
AVPacket packet; // Input packet, undecoded
AVFrame *in_frame; // Input image, decoded Theoretically only filled if needed.
AVFrame *frame; // Input image, decoded Theoretically only filled if needed.
AVFrame *out_frame; // Input image, decoded Theoretically only filled if needed.
uint8_t *buffer;
Image *image; // Our internal image object representing this frame
struct timeval timestamp;
public:
AVPacket *av_packet() { return &packet; }
AVPacket *set_packet( AVPacket *p ) ;
AVFrame *av_frame() { return frame; }
AVFrame *av_frame() { return out_frame; }
Image *get_image( Image *i=NULL );
Image *set_image( Image * );

View File

@ -305,7 +305,7 @@ Debug(2,"Sucess opening codec");
if ( !video_out_ctx->codec_tag ) {
video_out_ctx->codec_tag =
av_codec_get_tag(oc->oformat->codec_tag, AV_CODEC_ID_H264 );
Debug(2, "No codec_tag, setting to h264");
Debug(2, "No codec_tag, setting to h264 ? ");
}
} else {
Error("Codec not set");
@ -903,9 +903,9 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
if ( video_out_ctx->codec_id != video_in_ctx->codec_id ) {
Debug(3, "Have encoding video frame count (%d)", frame_count);
if ( ! zm_packet->frame ) {
if ( ! zm_packet->out_frame ) {
Debug(3, "Have no out frame");
AVFrame *out_frame = zm_packet->frame = zm_av_frame_alloc();
AVFrame *out_frame = zm_packet->out_frame = zm_av_frame_alloc();
if ( ! out_frame ) {
Error("Unable to allocate a frame");
return 0;
@ -969,20 +969,23 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
Error("Have neither in_frame or image!");
return 0;
} // end if has packet or image
} // end if no in_Frmae
} // end if no frame
} else {
// Have in_frame.... may need to convert it to out_frame
swscale.Convert(zm_packet->in_frame, zm_packet->out_frame);
} // end if no in_frame
} // end if no out_frame
if ( ! video_last_pts ) {
video_last_pts = zm_packet->timestamp.tv_sec*1000000 + zm_packet->timestamp.tv_usec;
zm_packet->frame->pts = 0;
zm_packet->out_frame->pts = 0;
} else {
zm_packet->frame->pts = ( zm_packet->timestamp.tv_sec*1000000 + zm_packet->timestamp.tv_usec ) - video_last_pts;
zm_packet->out_frame->pts = ( zm_packet->timestamp.tv_sec*1000000 + zm_packet->timestamp.tv_usec ) - video_last_pts;
}
// Do this to allow the encoder to choose whether to use I/P/B frame
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
zm_packet->frame->pict_type = AV_PICTURE_TYPE_NONE;
if ( (ret = avcodec_send_frame(video_out_ctx, zm_packet->frame)) < 0 ) {
zm_packet->out_frame->pict_type = AV_PICTURE_TYPE_NONE;
if ( (ret = avcodec_send_frame(video_out_ctx, zm_packet->out_frame)) < 0 ) {
Error("Could not send frame (error '%s')", av_make_error_string(ret).c_str());
return -1;
}
@ -1005,7 +1008,7 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
av_init_packet(&opkt);
int data_present;
if ( (ret = avcodec_encode_video2(
video_out_ctx, &opkt, zm_packet->frame, &data_present)) < 0) {
video_out_ctx, &opkt, zm_packet->out_frame, &data_present)) < 0) {
Error("Could not encode frame (error '%s')",
av_make_error_string(ret).c_str());
zm_av_packet_unref(&opkt);