rename frame to out_frame. Fix problem where we weren't copying from in_frame to out_frame
This commit is contained in:
parent
f5f45b3397
commit
882563c06e
|
@ -2891,7 +2891,7 @@ packet->reset();
|
||||||
return -1;
|
return -1;
|
||||||
} else if ( captureResult > 0 ) {
|
} 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() ) {
|
if ( packet->packet.stream_index == camera->get_VideoStreamId() ) {
|
||||||
packet->decode( camera->get_VideoCodecContext() );
|
packet->decode( camera->get_VideoCodecContext() );
|
||||||
packet->get_image();
|
packet->get_image();
|
||||||
|
|
|
@ -26,9 +26,10 @@ using namespace std;
|
||||||
|
|
||||||
ZMPacket::ZMPacket( ) {
|
ZMPacket::ZMPacket( ) {
|
||||||
keyframe = 0;
|
keyframe = 0;
|
||||||
image = NULL;
|
// frame from decoded packet, to be used in generating image
|
||||||
in_frame = NULL;
|
in_frame = NULL;
|
||||||
frame = NULL;
|
out_frame = NULL;
|
||||||
|
image = NULL;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
av_init_packet( &packet );
|
av_init_packet( &packet );
|
||||||
packet.size = 0; // So we can detect whether it has been filled.
|
packet.size = 0; // So we can detect whether it has been filled.
|
||||||
|
@ -39,25 +40,23 @@ ZMPacket::ZMPacket( Image *i ) {
|
||||||
keyframe = 1;
|
keyframe = 1;
|
||||||
image = i;
|
image = i;
|
||||||
in_frame = NULL;
|
in_frame = NULL;
|
||||||
frame = NULL;
|
out_frame = NULL;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
av_init_packet( &packet );
|
av_init_packet( &packet );
|
||||||
timestamp = (struct timeval){0};
|
timestamp = (struct timeval){0};
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMPacket::ZMPacket( AVPacket *p ) {
|
ZMPacket::ZMPacket( AVPacket *p ) {
|
||||||
frame = NULL;
|
|
||||||
image = NULL;
|
image = NULL;
|
||||||
av_init_packet( &packet );
|
av_init_packet( &packet );
|
||||||
set_packet( p );
|
set_packet( p );
|
||||||
keyframe = p->flags & AV_PKT_FLAG_KEY;
|
keyframe = p->flags & AV_PKT_FLAG_KEY;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
in_frame = NULL;
|
in_frame = NULL;
|
||||||
frame = NULL;
|
out_frame = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMPacket::ZMPacket( AVPacket *p, struct timeval *t ) {
|
ZMPacket::ZMPacket( AVPacket *p, struct timeval *t ) {
|
||||||
frame = NULL;
|
|
||||||
image = NULL;
|
image = NULL;
|
||||||
av_init_packet( &packet );
|
av_init_packet( &packet );
|
||||||
set_packet( p );
|
set_packet( p );
|
||||||
|
@ -65,16 +64,15 @@ ZMPacket::ZMPacket( AVPacket *p, struct timeval *t ) {
|
||||||
keyframe = p->flags & AV_PKT_FLAG_KEY;
|
keyframe = p->flags & AV_PKT_FLAG_KEY;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
in_frame = NULL;
|
in_frame = NULL;
|
||||||
frame = NULL;
|
out_frame = NULL;
|
||||||
}
|
}
|
||||||
ZMPacket::ZMPacket( AVPacket *p, AVFrame *f, Image *i ) {
|
ZMPacket::ZMPacket( AVPacket *p, AVFrame *f, Image *i ) {
|
||||||
av_init_packet( &packet );
|
av_init_packet( &packet );
|
||||||
set_packet( p );
|
set_packet( p );
|
||||||
image = i;
|
image = i;
|
||||||
frame = f;
|
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
in_frame = NULL;
|
in_frame = NULL;
|
||||||
frame = NULL;
|
out_frame = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMPacket::~ZMPacket() {
|
ZMPacket::~ZMPacket() {
|
||||||
|
@ -83,9 +81,9 @@ ZMPacket::~ZMPacket() {
|
||||||
//av_free(frame->data);
|
//av_free(frame->data);
|
||||||
av_frame_free( &in_frame );
|
av_frame_free( &in_frame );
|
||||||
}
|
}
|
||||||
if ( frame ) {
|
if ( out_frame ) {
|
||||||
//av_free(frame->data);
|
//av_free(frame->data);
|
||||||
av_frame_free( &frame );
|
av_frame_free( &out_frame );
|
||||||
}
|
}
|
||||||
if ( buffer ) {
|
if ( buffer ) {
|
||||||
av_freep( &buffer );
|
av_freep( &buffer );
|
||||||
|
@ -102,9 +100,9 @@ void ZMPacket::reset() {
|
||||||
//Debug(4,"reset frame");
|
//Debug(4,"reset frame");
|
||||||
av_frame_free( &in_frame );
|
av_frame_free( &in_frame );
|
||||||
}
|
}
|
||||||
if ( frame ) {
|
if ( out_frame ) {
|
||||||
//Debug(4,"reset frame");
|
//Debug(4,"reset frame");
|
||||||
av_frame_free( &frame );
|
av_frame_free( &out_frame );
|
||||||
}
|
}
|
||||||
if ( buffer ) {
|
if ( buffer ) {
|
||||||
//Debug(4,"freeing buffer");
|
//Debug(4,"freeing buffer");
|
||||||
|
|
|
@ -36,14 +36,14 @@ class ZMPacket {
|
||||||
int keyframe;
|
int keyframe;
|
||||||
AVPacket packet; // Input packet, undecoded
|
AVPacket packet; // Input packet, undecoded
|
||||||
AVFrame *in_frame; // Input image, decoded Theoretically only filled if needed.
|
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;
|
uint8_t *buffer;
|
||||||
Image *image; // Our internal image object representing this frame
|
Image *image; // Our internal image object representing this frame
|
||||||
struct timeval timestamp;
|
struct timeval timestamp;
|
||||||
public:
|
public:
|
||||||
AVPacket *av_packet() { return &packet; }
|
AVPacket *av_packet() { return &packet; }
|
||||||
AVPacket *set_packet( AVPacket *p ) ;
|
AVPacket *set_packet( AVPacket *p ) ;
|
||||||
AVFrame *av_frame() { return frame; }
|
AVFrame *av_frame() { return out_frame; }
|
||||||
Image *get_image( Image *i=NULL );
|
Image *get_image( Image *i=NULL );
|
||||||
Image *set_image( Image * );
|
Image *set_image( Image * );
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@ Debug(2,"Sucess opening codec");
|
||||||
if ( !video_out_ctx->codec_tag ) {
|
if ( !video_out_ctx->codec_tag ) {
|
||||||
video_out_ctx->codec_tag =
|
video_out_ctx->codec_tag =
|
||||||
av_codec_get_tag(oc->oformat->codec_tag, AV_CODEC_ID_H264 );
|
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 {
|
} else {
|
||||||
Error("Codec not set");
|
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 ) {
|
if ( video_out_ctx->codec_id != video_in_ctx->codec_id ) {
|
||||||
Debug(3, "Have encoding video frame count (%d)", frame_count);
|
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");
|
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 ) {
|
if ( ! out_frame ) {
|
||||||
Error("Unable to allocate a frame");
|
Error("Unable to allocate a frame");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -969,20 +969,23 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
|
||||||
Error("Have neither in_frame or image!");
|
Error("Have neither in_frame or image!");
|
||||||
return 0;
|
return 0;
|
||||||
} // end if has packet or image
|
} // end if has packet or image
|
||||||
} // end if no in_Frmae
|
} else {
|
||||||
} // end if no frame
|
// 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 ) {
|
if ( ! video_last_pts ) {
|
||||||
video_last_pts = zm_packet->timestamp.tv_sec*1000000 + zm_packet->timestamp.tv_usec;
|
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 {
|
} 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
|
// Do this to allow the encoder to choose whether to use I/P/B frame
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
zm_packet->frame->pict_type = AV_PICTURE_TYPE_NONE;
|
zm_packet->out_frame->pict_type = AV_PICTURE_TYPE_NONE;
|
||||||
if ( (ret = avcodec_send_frame(video_out_ctx, zm_packet->frame)) < 0 ) {
|
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());
|
Error("Could not send frame (error '%s')", av_make_error_string(ret).c_str());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1005,7 +1008,7 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
|
||||||
av_init_packet(&opkt);
|
av_init_packet(&opkt);
|
||||||
int data_present;
|
int data_present;
|
||||||
if ( (ret = avcodec_encode_video2(
|
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')",
|
Error("Could not encode frame (error '%s')",
|
||||||
av_make_error_string(ret).c_str());
|
av_make_error_string(ret).c_str());
|
||||||
zm_av_packet_unref(&opkt);
|
zm_av_packet_unref(&opkt);
|
||||||
|
|
Loading…
Reference in New Issue