Use libswscale in fish vhook.
Patch by Victor Paesa <wzrlpy@arsystel.com> Original thread: Date: Aug 30, 2006 1:16 AM Subject: Re: [Ffmpeg-devel] [PATCH] enable libswscale Originally committed as revision 6128 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
47
vhook/fish.c
47
vhook/fish.c
@@ -45,6 +45,9 @@
|
|||||||
#include "framehook.h"
|
#include "framehook.h"
|
||||||
#include "dsputil.h"
|
#include "dsputil.h"
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
|
#include "swscale.h"
|
||||||
|
|
||||||
|
static int sws_flags = SWS_BICUBIC;
|
||||||
|
|
||||||
#define SCALEBITS 10
|
#define SCALEBITS 10
|
||||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
#define ONE_HALF (1 << (SCALEBITS - 1))
|
||||||
@@ -88,6 +91,9 @@ typedef struct {
|
|||||||
int64_t next_pts;
|
int64_t next_pts;
|
||||||
int inset;
|
int inset;
|
||||||
int min_width;
|
int min_width;
|
||||||
|
struct SwsContext *toRGB_convert_ctx;
|
||||||
|
enum PixelFormat sws_pix_fmt; // Sws_Context is opaque, we need to save
|
||||||
|
int sws_width, sws_height; // this to check if we can re-use contexts
|
||||||
} ContextInfo;
|
} ContextInfo;
|
||||||
|
|
||||||
static void dorange(const char *s, int *first, int *second, int maxval)
|
static void dorange(const char *s, int *first, int *second, int maxval)
|
||||||
@@ -101,8 +107,13 @@ static void dorange(const char *s, int *first, int *second, int maxval)
|
|||||||
|
|
||||||
void Release(void *ctx)
|
void Release(void *ctx)
|
||||||
{
|
{
|
||||||
if (ctx)
|
ContextInfo *ci;
|
||||||
|
ci = (ContextInfo *) ctx;
|
||||||
|
|
||||||
|
if (ctx) {
|
||||||
|
sws_freeContext(ci->toRGB_convert_ctx);
|
||||||
av_free(ctx);
|
av_free(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Configure(void **ctxp, int argc, char *argv[])
|
int Configure(void **ctxp, int argc, char *argv[])
|
||||||
@@ -331,8 +342,37 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
|
|||||||
buf = av_malloc(size);
|
buf = av_malloc(size);
|
||||||
|
|
||||||
avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
|
avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
|
||||||
if (img_convert(&picture1, PIX_FMT_RGB24,
|
|
||||||
picture, pix_fmt, width, height) >= 0) {
|
// if we already got a SWS context, let's realloc if is not re-useable
|
||||||
|
if (ci->toRGB_convert_ctx != NULL) {
|
||||||
|
if ((ci->sws_pix_fmt != pix_fmt) ||
|
||||||
|
(ci->sws_width != width) || (ci->sws_height != height)) {
|
||||||
|
sws_freeContext(ci->toRGB_convert_ctx);
|
||||||
|
ci->toRGB_convert_ctx = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ci->toRGB_convert_ctx == NULL) {
|
||||||
|
ci->sws_pix_fmt = pix_fmt;
|
||||||
|
ci->sws_width = width;
|
||||||
|
ci->sws_height = height;
|
||||||
|
ci->toRGB_convert_ctx = sws_getContext(
|
||||||
|
ci->sws_width, ci->sws_height,
|
||||||
|
ci->sws_pix_fmt,
|
||||||
|
ci->sws_width, ci->sws_height,
|
||||||
|
PIX_FMT_RGB24,
|
||||||
|
sws_flags, NULL, NULL, NULL);
|
||||||
|
if (ci->toRGB_convert_ctx == NULL) {
|
||||||
|
av_log(NULL, AV_LOG_ERROR,
|
||||||
|
"Cannot initialize the toRGB conversion context\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// img_convert parameters are 2 first destination, then 4 source
|
||||||
|
// sws_scale parameters are context, 4 first source, then 2 destination
|
||||||
|
sws_scale(ci->toRGB_convert_ctx,
|
||||||
|
picture->data, picture->linesize, 0, ci->sws_height,
|
||||||
|
picture1.data, picture1.linesize);
|
||||||
|
|
||||||
/* Write out the PPM file */
|
/* Write out the PPM file */
|
||||||
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@@ -345,7 +385,6 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
|
|||||||
fwrite(buf, width * height * 3, 1, f);
|
fwrite(buf, width * height * 3, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
av_free(buf);
|
av_free(buf);
|
||||||
ci->next_pts = pts + ci->min_interval;
|
ci->next_pts = pts + ci->min_interval;
|
||||||
|
|||||||
Reference in New Issue
Block a user