Bug 76 - Now supports CVS ffmpeg.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1497 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2005-10-03 20:38:40 +00:00
parent 7b72d64dd0
commit 209f65e10f
3 changed files with 33 additions and 4 deletions

View File

@ -1,6 +1,5 @@
AUTOMAKE_OPTIONS = gnu AUTOMAKE_OPTIONS = gnu
LDADD = @MYSQL_LIBS@
AM_CPPFLAGS = @MYSQL_CFLAGS@ @FFMPEG_CFLAGS@ AM_CPPFLAGS = @MYSQL_CFLAGS@ @FFMPEG_CFLAGS@
# This should be set to your CGI directory # This should be set to your CGI directory

View File

@ -75,7 +75,12 @@ void VideoStream::SetupCodec( int colours, int width, int height, int bitrate, i
Fatal(( "Could not alloc stream" )); Fatal(( "Could not alloc stream" ));
} }
#if ZM_FFMPEG_CVS
AVCodecContext *c = ost->codec;
#else
AVCodecContext *c = &ost->codec; AVCodecContext *c = &ost->codec;
#endif
c->codec_id = of->video_codec; c->codec_id = of->video_codec;
c->codec_type = CODEC_TYPE_VIDEO; c->codec_type = CODEC_TYPE_VIDEO;
@ -84,9 +89,18 @@ void VideoStream::SetupCodec( int colours, int width, int height, int bitrate, i
/* resolution must be a multiple of two */ /* resolution must be a multiple of two */
c->width = width; c->width = width;
c->height = height; c->height = height;
#if ZM_FFMPEG_CVS
/* time base: this is the fundamental unit of time (in seconds) in terms
of which frame timestamps are represented. for fixed-fps content,
timebase should be 1/framerate and timestamp increments should be
identically 1. */
c->time_base.den = frame_rate;
c->time_base.num = 1;
#else
/* frames per second */ /* frames per second */
c->frame_rate = frame_rate; c->frame_rate = frame_rate;
c->frame_rate_base = 1; c->frame_rate_base = 1;
#endif
c->gop_size = frame_rate/2; /* emit one intra frame every half second or so */ c->gop_size = frame_rate/2; /* emit one intra frame every half second or so */
c->gop_size = 30; c->gop_size = 30;
if ( c->gop_size < 3 ) if ( c->gop_size < 3 )
@ -117,7 +131,11 @@ void VideoStream::OpenStream()
video codecs and allocate the necessary encode buffers */ video codecs and allocate the necessary encode buffers */
if (ost) if (ost)
{ {
#if ZM_FFMPEG_CVS
AVCodecContext *c = ost->codec;
#else
AVCodecContext *c = &ost->codec; AVCodecContext *c = &ost->codec;
#endif
/* find the video encoder */ /* find the video encoder */
AVCodec *codec = avcodec_find_encoder(c->codec_id); AVCodec *codec = avcodec_find_encoder(c->codec_id);
@ -217,7 +235,11 @@ VideoStream::~VideoStream()
/* close each codec */ /* close each codec */
if (ost) if (ost)
{ {
#if ZM_FFMPEG_CVS
avcodec_close(ost->codec);
#else
avcodec_close(&ost->codec); avcodec_close(&ost->codec);
#endif
av_free(opicture->data[0]); av_free(opicture->data[0]);
av_free(opicture); av_free(opicture);
if (tmp_opicture) if (tmp_opicture)
@ -253,14 +275,18 @@ double VideoStream::EncodeFrame( uint8_t *buffer, int buffer_size, bool add_time
if (ost) if (ost)
{ {
#if FFMPEG_VERSION_INT <= 0x000408 #if FFMPEG_VERSION_INT < 0x000409
pts = (double)ost->pts.val * ofc->pts_num / ofc->pts_den; pts = (double)ost->pts.val * ofc->pts_num / ofc->pts_den;
#else #else
pts = (double)ost->pts.val * ost->time_base.num / ost->time_base.den; pts = (double)ost->pts.val * ost->time_base.num / ost->time_base.den;
#endif #endif
} }
#if ZM_FFMPEG_CVS
AVCodecContext *c = ost->codec;
#else
AVCodecContext *c = &ost->codec; AVCodecContext *c = &ost->codec;
#endif
if (c->pix_fmt != pf) if (c->pix_fmt != pf)
{ {
memcpy( tmp_opicture->data[0], buffer, buffer_size ); memcpy( tmp_opicture->data[0], buffer, buffer_size );
@ -277,7 +303,7 @@ double VideoStream::EncodeFrame( uint8_t *buffer, int buffer_size, bool add_time
int ret = 0; int ret = 0;
if (ofc->oformat->flags & AVFMT_RAWPICTURE) if (ofc->oformat->flags & AVFMT_RAWPICTURE)
{ {
#if FFMPEG_VERSION_INT <= 0x000408 #if FFMPEG_VERSION_INT < 0x000409
ret = av_write_frame(ofc, ost->index, (uint8_t *)opicture_ptr, sizeof(AVPicture)); ret = av_write_frame(ofc, ost->index, (uint8_t *)opicture_ptr, sizeof(AVPicture));
#else #else
AVPacket pkt; AVPacket pkt;
@ -298,7 +324,7 @@ double VideoStream::EncodeFrame( uint8_t *buffer, int buffer_size, bool add_time
int out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, opicture_ptr); 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 <= 0x000408 #if FFMPEG_VERSION_INT < 0x000409
ret = av_write_frame(ofc, ost->index, video_outbuf, out_size); ret = av_write_frame(ofc, ost->index, video_outbuf, out_size);
#else #else
AVPacket pkt; AVPacket pkt;

View File

@ -24,6 +24,10 @@
#ifndef ZM_MPEG_H #ifndef ZM_MPEG_H
#define ZM_MPEG_H #define ZM_MPEG_H
#ifdef HAVE_LIBAVUTIL
#define ZM_FFMPEG_CVS 1
#endif
#include <ffmpeg/avformat.h> #include <ffmpeg/avformat.h>
class VideoStream class VideoStream