From ce7164a065d20cd12e2207769c7eb98a066b5ea7 Mon Sep 17 00:00:00 2001 From: stan Date: Sun, 16 Oct 2005 21:32:37 +0000 Subject: [PATCH] Bug 178 - Added support for CVS ffmpeg. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1509 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/zm_mpeg.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index 9eb0af544..6d46119a6 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -86,6 +86,7 @@ void VideoStream::SetupCodec( int colours, int width, int height, int bitrate, i /* put sample parameters */ c->bit_rate = bitrate; + c->pix_fmt = PIX_FMT_YUV420P; /* resolution must be a multiple of two */ c->width = width; c->height = height; @@ -102,15 +103,12 @@ void VideoStream::SetupCodec( int colours, int width, int height, int bitrate, i c->frame_rate_base = 1; #endif c->gop_size = frame_rate/2; /* emit one intra frame every half second or so */ - c->gop_size = 30; + c->gop_size = 12; if ( c->gop_size < 3 ) c->gop_size = 3; - if (c->codec_id == CODEC_ID_MPEG1VIDEO || - c->codec_id == CODEC_ID_MPEG2VIDEO) - { - /* just for testing, we also add B frames */ - c->max_b_frames = 2; - } + // some formats want stream headers to be seperate + if(!strcmp(ofc->oformat->name, "mp4") || !strcmp(ofc->oformat->name, "mov") || !strcmp(ofc->oformat->name, "3gp")) + c->flags |= CODEC_FLAG_GLOBAL_HEADER; } } @@ -147,7 +145,7 @@ void VideoStream::OpenStream() /* open the codec */ if (avcodec_open(c, codec) < 0) { - Fatal(( "could not open codec" )); + Fatal(( "Could not open codec" )); } /* allocate the encoded raw picture */ @@ -322,7 +320,7 @@ double VideoStream::EncodeFrame( uint8_t *buffer, int buffer_size, bool add_time if ( add_timestamp ) ost->pts.val = timestamp; int out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, opicture_ptr); - if (out_size != 0) + if (out_size > 0) { #if FFMPEG_VERSION_INT < 0x000409 ret = av_write_frame(ofc, ost->index, video_outbuf, out_size); @@ -330,7 +328,7 @@ double VideoStream::EncodeFrame( uint8_t *buffer, int buffer_size, bool add_time AVPacket pkt; av_init_packet(&pkt); - pkt.pts = c->coded_frame->pts; + pkt.pts= av_rescale_q( c->coded_frame->pts, c->time_base, ost->time_base ); if(c->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; pkt.stream_index = ost->index;