2002-11-21 03:50:36 +00:00
|
|
|
/*
|
2005-12-17 18:14:38 +00:00
|
|
|
* imlib2 based hook
|
2002-11-21 03:50:36 +00:00
|
|
|
* Copyright (c) 2002 Philip Gladstone
|
2005-12-17 18:14:38 +00:00
|
|
|
*
|
2002-11-21 03:50:36 +00:00
|
|
|
* This module implements a text overlay for a video image. Currently it
|
|
|
|
* supports a fixed overlay or reading the text from a file. The string
|
|
|
|
* is passed through strftime so that it is easy to imprint the date and
|
|
|
|
* time onto the image.
|
|
|
|
*
|
2006-11-07 09:12:20 +00:00
|
|
|
* You may also overlay an image (even semi-transparent) like TV stations do.
|
|
|
|
* You may move either the text or the image around your video to create
|
|
|
|
* scrolling credits, for example.
|
|
|
|
*
|
|
|
|
* Text fonts are being looked for in FONTPATH
|
|
|
|
*
|
2002-11-21 03:50:36 +00:00
|
|
|
* Options:
|
|
|
|
*
|
2007-06-15 20:40:14 +00:00
|
|
|
* -C <rgb.txt> The filename to read RGB color names from
|
|
|
|
* Defaults if none specified:
|
|
|
|
* /usr/share/X11/rgb.txt
|
|
|
|
* /usr/lib/X11/rgb.txt
|
2002-11-21 03:50:36 +00:00
|
|
|
* -c <color> The color of the text
|
|
|
|
* -F <fontname> The font face and size
|
|
|
|
* -t <text> The text
|
|
|
|
* -f <filename> The filename to read text from
|
2007-06-16 00:26:51 +00:00
|
|
|
* -x <expression> X coordinate of text or image
|
|
|
|
* -y <expression> Y coordinate of text or image
|
2006-11-07 09:12:20 +00:00
|
|
|
* -i <filename> The filename to read a image from
|
2007-06-16 22:28:10 +00:00
|
|
|
* -R <expression> Value for R color
|
|
|
|
* -G <expression> Value for G color
|
|
|
|
* -B <expression> Value for B color
|
2007-06-18 22:17:37 +00:00
|
|
|
* -A <expression> Value for Alpha channel
|
2002-11-21 03:50:36 +00:00
|
|
|
*
|
2007-06-16 00:26:51 +00:00
|
|
|
* Expressions are functions of:
|
2006-11-07 09:12:20 +00:00
|
|
|
* N // frame number (starting at zero)
|
|
|
|
* H // frame height
|
|
|
|
* W // frame width
|
|
|
|
* h // image height
|
|
|
|
* w // image width
|
|
|
|
* X // previous x
|
|
|
|
* Y // previous y
|
|
|
|
*
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
|
|
|
|
FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
|
|
|
|
FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
|
|
|
|
export FONTPATH
|
|
|
|
|
|
|
|
ffmpeg -i input.avi -vhook \
|
|
|
|
'vhook/imlib2.dll -x W*(0.5+0.25*sin(N/47*PI))-w/2 -y H*(0.5+0.50*cos(N/97*PI))-h/2 -i /usr/share/imlib2/data/images/bulb.png'
|
|
|
|
-acodec copy -sameq output.avi
|
|
|
|
|
|
|
|
ffmpeg -i input.avi -vhook \
|
|
|
|
'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello'
|
|
|
|
-acodec copy -sameq output.avi
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
* This module is very much intended as an example of what could be done.
|
|
|
|
*
|
|
|
|
* One caution is that this is an expensive process -- in particular the
|
|
|
|
* conversion of the image into RGB and back is time consuming. For some
|
|
|
|
* special cases -- e.g. painting black text -- it would be faster to paint
|
|
|
|
* the text into a bitmap and then combine it directly into the YUV
|
2005-12-17 18:14:38 +00:00
|
|
|
* image. However, this code is fast enough to handle 10 fps of 320x240 on a
|
2002-11-21 03:50:36 +00:00
|
|
|
* 900MHz Duron in maybe 15% of the CPU.
|
2006-11-07 09:12:20 +00:00
|
|
|
|
|
|
|
* See further statistics on Pentium4, 3GHz, FFMpeg is SVN-r6798
|
|
|
|
* Input movie is 20.2 seconds of PAL DV on AVI
|
|
|
|
* Output movie is DVD compliant VOB.
|
|
|
|
*
|
|
|
|
ffmpeg -i input.avi -target pal-dvd out.vob
|
|
|
|
# 13.516s just transcode
|
|
|
|
ffmpeg -i input.avi -vhook /usr/local/bin/vhook/null.dll -target pal-dvd out.vob
|
|
|
|
# 23.546s transcode and img_convert
|
|
|
|
ffmpeg -i input.avi -vhook \
|
|
|
|
'vhook/imlib2.dll -c red -F Vera/20 -x 150-0.5*N -y 70+0.25*N -t Hello_person' \
|
|
|
|
-target pal-dvd out.vob
|
|
|
|
# 21.454s transcode, img_convert and move text around
|
|
|
|
ffmpeg -i input.avi -vhook \
|
|
|
|
'vhook/imlib2.dll -x 150-0.5*N -y 70+0.25*N -i /usr/share/imlib2/data/images/bulb.png' \
|
|
|
|
-target pal-dvd out.vob
|
|
|
|
# 20.828s transcode, img_convert and move image around
|
2002-11-21 03:50:36 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-11-21 03:50:36 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-11-21 03:50:36 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-11-21 03:50:36 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-11-21 03:50:36 +00:00
|
|
|
*/
|
2004-04-07 13:31:27 +00:00
|
|
|
|
|
|
|
#include "framehook.h"
|
2006-10-11 12:08:36 +00:00
|
|
|
#include "swscale.h"
|
2004-04-07 13:31:27 +00:00
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2004-04-07 13:31:27 +00:00
|
|
|
#undef time
|
2002-11-21 03:50:36 +00:00
|
|
|
#include <sys/time.h>
|
2004-04-07 13:31:27 +00:00
|
|
|
#include <time.h>
|
2005-12-17 18:14:38 +00:00
|
|
|
#include <Imlib2.h>
|
2006-11-07 09:12:20 +00:00
|
|
|
#include "eval.h"
|
|
|
|
|
|
|
|
const char *const_names[]={
|
|
|
|
"PI",
|
|
|
|
"E",
|
|
|
|
"N", // frame number (starting at zero)
|
|
|
|
"H", // frame height
|
|
|
|
"W", // frame width
|
|
|
|
"h", // image height
|
|
|
|
"w", // image width
|
|
|
|
"X", // previous x
|
|
|
|
"Y", // previous y
|
|
|
|
NULL
|
|
|
|
};
|
2002-11-21 03:50:36 +00:00
|
|
|
|
2006-10-11 12:08:36 +00:00
|
|
|
static int sws_flags = SWS_BICUBIC;
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
typedef struct {
|
|
|
|
int dummy;
|
|
|
|
Imlib_Font fn;
|
|
|
|
char *text;
|
|
|
|
char *file;
|
2007-06-18 22:17:37 +00:00
|
|
|
int r, g, b, a;
|
|
|
|
AVEvalExpr *eval_r, *eval_g, *eval_b, *eval_a;
|
|
|
|
char *expr_R, *expr_G, *expr_B, *expr_A;
|
2007-06-16 22:28:10 +00:00
|
|
|
int eval_colors;
|
2006-11-07 09:12:20 +00:00
|
|
|
double x, y;
|
|
|
|
char *fileImage;
|
2002-11-21 03:50:36 +00:00
|
|
|
struct _CachedImage *cache;
|
2006-11-07 09:12:20 +00:00
|
|
|
Imlib_Image imageOverlaid;
|
|
|
|
AVEvalExpr *eval_x, *eval_y;
|
|
|
|
char *expr_x, *expr_y;
|
|
|
|
int frame_number;
|
|
|
|
int imageOverlaid_width, imageOverlaid_height;
|
2006-10-11 12:08:36 +00:00
|
|
|
|
|
|
|
// This vhook first converts frame to RGB ...
|
|
|
|
struct SwsContext *toRGB_convert_ctx;
|
|
|
|
// ... and then converts back frame from RGB to initial format
|
|
|
|
struct SwsContext *fromRGB_convert_ctx;
|
2002-11-21 03:50:36 +00:00
|
|
|
} ContextInfo;
|
|
|
|
|
|
|
|
typedef struct _CachedImage {
|
|
|
|
struct _CachedImage *next;
|
|
|
|
Imlib_Image image;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
} CachedImage;
|
|
|
|
|
2002-11-30 17:17:58 +00:00
|
|
|
void Release(void *ctx)
|
|
|
|
{
|
|
|
|
ContextInfo *ci;
|
|
|
|
ci = (ContextInfo *) ctx;
|
|
|
|
|
|
|
|
if (ci->cache) {
|
|
|
|
imlib_context_set_image(ci->cache->image);
|
|
|
|
imlib_free_image();
|
|
|
|
av_free(ci->cache);
|
|
|
|
}
|
2006-10-11 12:08:36 +00:00
|
|
|
if (ctx) {
|
2006-11-07 09:12:20 +00:00
|
|
|
if (ci->imageOverlaid) {
|
|
|
|
imlib_context_set_image(ci->imageOverlaid);
|
|
|
|
imlib_free_image();
|
|
|
|
}
|
2007-06-18 12:00:06 +00:00
|
|
|
ff_eval_free(ci->eval_x);
|
|
|
|
ff_eval_free(ci->eval_y);
|
|
|
|
ff_eval_free(ci->eval_r);
|
|
|
|
ff_eval_free(ci->eval_g);
|
|
|
|
ff_eval_free(ci->eval_b);
|
2007-06-18 22:17:37 +00:00
|
|
|
ff_eval_free(ci->eval_a);
|
2007-06-18 12:00:06 +00:00
|
|
|
|
|
|
|
av_free(ci->expr_x);
|
|
|
|
av_free(ci->expr_y);
|
|
|
|
av_free(ci->expr_R);
|
|
|
|
av_free(ci->expr_G);
|
|
|
|
av_free(ci->expr_B);
|
2007-06-18 22:17:37 +00:00
|
|
|
av_free(ci->expr_A);
|
2006-10-11 12:08:36 +00:00
|
|
|
sws_freeContext(ci->toRGB_convert_ctx);
|
|
|
|
sws_freeContext(ci->fromRGB_convert_ctx);
|
2002-11-30 17:17:58 +00:00
|
|
|
av_free(ctx);
|
2006-10-11 12:08:36 +00:00
|
|
|
}
|
2002-11-30 17:17:58 +00:00
|
|
|
}
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
int Configure(void **ctxp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
ContextInfo *ci;
|
2007-06-15 20:40:14 +00:00
|
|
|
char *rgbtxt = 0;
|
2002-11-21 03:50:36 +00:00
|
|
|
char *font = "LucidaSansDemiBold/16";
|
|
|
|
char *fp = getenv("FONTPATH");
|
|
|
|
char *color = 0;
|
|
|
|
FILE *f;
|
2006-11-07 09:12:20 +00:00
|
|
|
char *p;
|
2007-06-20 23:30:01 +00:00
|
|
|
char *error;
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
*ctxp = av_mallocz(sizeof(ContextInfo));
|
|
|
|
ci = (ContextInfo *) *ctxp;
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
ci->x = 0.0;
|
|
|
|
ci->y = 0.0;
|
|
|
|
ci->expr_x = "0.0";
|
|
|
|
ci->expr_y = "0.0";
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
optind = 0;
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
/* Use ':' to split FONTPATH */
|
2002-11-21 03:50:36 +00:00
|
|
|
if (fp)
|
2006-11-07 09:12:20 +00:00
|
|
|
while (p = strchr(fp, ':')) {
|
|
|
|
*p = 0;
|
|
|
|
imlib_add_path_to_font_path(fp);
|
|
|
|
fp = p + 1;
|
|
|
|
}
|
|
|
|
if ((fp) && (*fp))
|
2002-11-21 03:50:36 +00:00
|
|
|
imlib_add_path_to_font_path(fp);
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
|
2007-06-18 22:17:37 +00:00
|
|
|
while ((c = getopt(argc, argv, "R:G:B:A:C:c:f:F:t:x:y:i:")) > 0) {
|
2002-11-21 03:50:36 +00:00
|
|
|
switch (c) {
|
2007-06-16 22:28:10 +00:00
|
|
|
case 'R':
|
|
|
|
ci->expr_R = av_strdup(optarg);
|
|
|
|
ci->eval_colors = 1;
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
ci->expr_G = av_strdup(optarg);
|
|
|
|
ci->eval_colors = 1;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
ci->expr_B = av_strdup(optarg);
|
|
|
|
ci->eval_colors = 1;
|
|
|
|
break;
|
2007-06-18 22:17:37 +00:00
|
|
|
case 'A':
|
|
|
|
ci->expr_A = av_strdup(optarg);
|
|
|
|
break;
|
2007-06-15 20:40:14 +00:00
|
|
|
case 'C':
|
|
|
|
rgbtxt = optarg;
|
|
|
|
break;
|
2002-11-21 03:50:36 +00:00
|
|
|
case 'c':
|
|
|
|
color = optarg;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
font = optarg;
|
|
|
|
break;
|
|
|
|
case 't':
|
2003-01-23 23:34:29 +00:00
|
|
|
ci->text = av_strdup(optarg);
|
2002-11-21 03:50:36 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2003-01-23 23:34:29 +00:00
|
|
|
ci->file = av_strdup(optarg);
|
2002-11-21 03:50:36 +00:00
|
|
|
break;
|
|
|
|
case 'x':
|
2006-11-07 09:12:20 +00:00
|
|
|
ci->expr_x = av_strdup(optarg);
|
2002-11-21 03:50:36 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
2006-11-07 09:12:20 +00:00
|
|
|
ci->expr_y = av_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
ci->fileImage = av_strdup(optarg);
|
2002-11-21 03:50:36 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
fprintf(stderr, "Unrecognized argument '%s'\n", argv[optind]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-16 22:28:10 +00:00
|
|
|
if (ci->eval_colors && !(ci->expr_R && ci->expr_G && ci->expr_B))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "You must specify expressions for all or no colors.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
if (ci->text || ci->file) {
|
2007-06-17 00:16:55 +00:00
|
|
|
ci->fn = imlib_load_font(font);
|
|
|
|
if (!ci->fn) {
|
|
|
|
fprintf(stderr, "Failed to load font '%s'\n", font);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
imlib_context_set_font(ci->fn);
|
|
|
|
imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);
|
2006-11-07 09:12:20 +00:00
|
|
|
}
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
if (color) {
|
|
|
|
char buff[256];
|
|
|
|
int done = 0;
|
|
|
|
|
2007-06-16 22:28:10 +00:00
|
|
|
if (ci->eval_colors)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "You must not specify both a color name and expressions for the colors.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-06-15 20:40:14 +00:00
|
|
|
if (rgbtxt)
|
|
|
|
f = fopen(rgbtxt, "r");
|
|
|
|
else
|
|
|
|
{
|
2007-06-15 20:42:56 +00:00
|
|
|
f = fopen("/usr/share/X11/rgb.txt", "r");
|
|
|
|
if (!f)
|
|
|
|
f = fopen("/usr/lib/X11/rgb.txt", "r");
|
2007-06-15 20:40:14 +00:00
|
|
|
}
|
2002-11-21 03:50:36 +00:00
|
|
|
if (!f) {
|
2007-06-15 20:40:14 +00:00
|
|
|
fprintf(stderr, "Failed to find RGB color names file\n");
|
2002-11-21 03:50:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
while (fgets(buff, sizeof(buff), f)) {
|
|
|
|
int r, g, b;
|
|
|
|
char colname[80];
|
|
|
|
|
|
|
|
if (sscanf(buff, "%d %d %d %64s", &r, &g, &b, colname) == 4 &&
|
|
|
|
strcasecmp(colname, color) == 0) {
|
|
|
|
ci->r = r;
|
|
|
|
ci->g = g;
|
|
|
|
ci->b = b;
|
|
|
|
/* fprintf(stderr, "%s -> %d,%d,%d\n", colname, r, g, b); */
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
if (!done) {
|
|
|
|
fprintf(stderr, "Unable to find color '%s' in rgb.txt\n", color);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-06-16 22:28:10 +00:00
|
|
|
} else if (ci->eval_colors) {
|
2007-06-20 23:30:01 +00:00
|
|
|
if (!(ci->eval_r = ff_parse(ci->expr_R, const_names, NULL, NULL, NULL, NULL, &error))){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't parse R expression '%s': %s\n", ci->expr_R, error);
|
2007-06-16 22:28:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-06-20 23:30:01 +00:00
|
|
|
if (!(ci->eval_g = ff_parse(ci->expr_G, const_names, NULL, NULL, NULL, NULL, &error))){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't parse G expression '%s': %s\n", ci->expr_G, error);
|
2007-06-16 22:28:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-06-20 23:30:01 +00:00
|
|
|
if (!(ci->eval_b = ff_parse(ci->expr_B, const_names, NULL, NULL, NULL, NULL, &error))){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't parse B expression '%s': %s\n", ci->expr_B, error);
|
2007-06-16 22:28:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
2007-06-16 22:28:10 +00:00
|
|
|
|
2007-06-18 22:17:37 +00:00
|
|
|
if (ci->expr_A) {
|
2007-06-20 23:30:01 +00:00
|
|
|
if (!(ci->eval_a = ff_parse(ci->expr_A, const_names, NULL, NULL, NULL, NULL, &error))){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't parse A expression '%s': %s\n", ci->expr_A, error);
|
2007-06-18 22:17:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ci->a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ci->eval_colors || ci->eval_a))
|
|
|
|
imlib_context_set_color(ci->r, ci->g, ci->b, ci->a);
|
2006-11-07 09:12:20 +00:00
|
|
|
|
|
|
|
/* load the image (for example, credits for a movie) */
|
|
|
|
if (ci->fileImage) {
|
|
|
|
ci->imageOverlaid = imlib_load_image_immediately(ci->fileImage);
|
|
|
|
if (!(ci->imageOverlaid)){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't load image '%s'\n", ci->fileImage);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
imlib_context_set_image(ci->imageOverlaid);
|
|
|
|
ci->imageOverlaid_width = imlib_image_get_width();
|
|
|
|
ci->imageOverlaid_height = imlib_image_get_height();
|
|
|
|
}
|
|
|
|
|
2007-06-20 23:30:01 +00:00
|
|
|
if (!(ci->eval_x = ff_parse(ci->expr_x, const_names, NULL, NULL, NULL, NULL, &error))){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't parse x expression '%s': %s\n", ci->expr_x, error);
|
2006-11-07 09:12:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-06-20 23:30:01 +00:00
|
|
|
if (!(ci->eval_y = ff_parse(ci->expr_y, const_names, NULL, NULL, NULL, NULL, &error))){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Couldn't parse y expression '%s': %s\n", ci->expr_y, error);
|
2006-11-07 09:12:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Imlib_Image get_cached_image(ContextInfo *ci, int width, int height)
|
|
|
|
{
|
|
|
|
CachedImage *cache;
|
|
|
|
|
|
|
|
for (cache = ci->cache; cache; cache = cache->next) {
|
|
|
|
if (width == cache->width && height == cache->height)
|
|
|
|
return cache->image;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void put_cached_image(ContextInfo *ci, Imlib_Image image, int width, int height)
|
|
|
|
{
|
|
|
|
CachedImage *cache = av_mallocz(sizeof(*cache));
|
|
|
|
|
|
|
|
cache->image = image;
|
|
|
|
cache->width = width;
|
|
|
|
cache->height = height;
|
|
|
|
cache->next = ci->cache;
|
|
|
|
ci->cache = cache;
|
|
|
|
}
|
|
|
|
|
2003-02-11 16:35:48 +00:00
|
|
|
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
|
2002-11-21 03:50:36 +00:00
|
|
|
{
|
|
|
|
ContextInfo *ci = (ContextInfo *) ctx;
|
|
|
|
AVPicture picture1;
|
|
|
|
Imlib_Image image;
|
|
|
|
DATA32 *data;
|
|
|
|
|
|
|
|
image = get_cached_image(ci, width, height);
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
image = imlib_create_image(width, height);
|
|
|
|
put_cached_image(ci, image, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
imlib_context_set_image(image);
|
|
|
|
data = imlib_image_get_data();
|
|
|
|
|
2007-06-17 00:16:55 +00:00
|
|
|
avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGB32, width, height);
|
2006-10-11 12:08:36 +00:00
|
|
|
|
|
|
|
// if we already got a SWS context, let's realloc if is not re-useable
|
|
|
|
ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
|
|
|
|
width, height, pix_fmt,
|
2007-02-07 01:48:09 +00:00
|
|
|
width, height, PIX_FMT_RGB32,
|
2006-10-11 12:08:36 +00:00
|
|
|
sws_flags, NULL, NULL, NULL);
|
|
|
|
if (ci->toRGB_convert_ctx == NULL) {
|
|
|
|
av_log(NULL, AV_LOG_ERROR,
|
|
|
|
"Cannot initialize the toRGB conversion context\n");
|
2007-04-01 17:23:15 +00:00
|
|
|
return;
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 12:08:36 +00:00
|
|
|
// 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, height,
|
|
|
|
picture1.data, picture1.linesize);
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
imlib_image_set_has_alpha(0);
|
|
|
|
|
|
|
|
{
|
2005-12-17 18:14:38 +00:00
|
|
|
int wid, hig, h_a, v_a;
|
2002-11-21 03:50:36 +00:00
|
|
|
char buff[1000];
|
|
|
|
char tbuff[1000];
|
|
|
|
char *tbp = ci->text;
|
|
|
|
time_t now = time(0);
|
|
|
|
char *p, *q;
|
2006-11-07 09:12:20 +00:00
|
|
|
int y;
|
|
|
|
|
|
|
|
double const_values[]={
|
|
|
|
M_PI,
|
|
|
|
M_E,
|
|
|
|
ci->frame_number, // frame number (starting at zero)
|
|
|
|
height, // frame height
|
|
|
|
width, // frame width
|
|
|
|
ci->imageOverlaid_height, // image height
|
|
|
|
ci->imageOverlaid_width, // image width
|
|
|
|
ci->x, // previous x
|
|
|
|
ci->y, // previous y
|
|
|
|
0
|
|
|
|
};
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
if (ci->file) {
|
|
|
|
int fd = open(ci->file, O_RDONLY);
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
tbp = "[File not found]";
|
|
|
|
} else {
|
|
|
|
int l = read(fd, tbuff, sizeof(tbuff) - 1);
|
|
|
|
|
|
|
|
if (l >= 0) {
|
|
|
|
tbuff[l] = 0;
|
|
|
|
tbp = tbuff;
|
|
|
|
} else {
|
|
|
|
tbp = "[I/O Error]";
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
if (tbp)
|
|
|
|
strftime(buff, sizeof(buff), tbp, localtime(&now));
|
|
|
|
else if (!(ci->imageOverlaid))
|
|
|
|
strftime(buff, sizeof(buff), "[No data]", localtime(&now));
|
2002-11-21 03:50:36 +00:00
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
ci->x = ff_parse_eval(ci->eval_x, const_values, ci);
|
|
|
|
ci->y = ff_parse_eval(ci->eval_y, const_values, ci);
|
2002-11-21 03:50:36 +00:00
|
|
|
y = ci->y;
|
|
|
|
|
2007-06-18 22:17:37 +00:00
|
|
|
if (ci->eval_a) {
|
|
|
|
ci->a = ff_parse_eval(ci->eval_a, const_values, ci);
|
|
|
|
}
|
|
|
|
|
2007-06-16 22:28:10 +00:00
|
|
|
if (ci->eval_colors) {
|
|
|
|
ci->r = ff_parse_eval(ci->eval_r, const_values, ci);
|
|
|
|
ci->g = ff_parse_eval(ci->eval_g, const_values, ci);
|
|
|
|
ci->b = ff_parse_eval(ci->eval_b, const_values, ci);
|
2007-06-18 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->eval_colors || ci->eval_a) {
|
|
|
|
imlib_context_set_color(ci->r, ci->g, ci->b, ci->a);
|
2007-06-16 22:28:10 +00:00
|
|
|
}
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
if (!(ci->imageOverlaid))
|
2002-11-21 03:50:36 +00:00
|
|
|
for (p = buff; p; p = q) {
|
|
|
|
q = strchr(p, '\n');
|
|
|
|
if (q)
|
|
|
|
*q++ = 0;
|
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
imlib_text_draw_with_return_metrics(ci->x, y, p, &wid, &hig, &h_a, &v_a);
|
2002-11-21 03:50:36 +00:00
|
|
|
y += v_a;
|
|
|
|
}
|
2006-11-07 09:12:20 +00:00
|
|
|
|
|
|
|
if (ci->imageOverlaid) {
|
|
|
|
imlib_context_set_image(image);
|
|
|
|
imlib_blend_image_onto_image(ci->imageOverlaid, 0,
|
|
|
|
0, 0, ci->imageOverlaid_width, ci->imageOverlaid_height,
|
|
|
|
ci->x, ci->y, ci->imageOverlaid_width, ci->imageOverlaid_height);
|
|
|
|
}
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 12:08:36 +00:00
|
|
|
ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
|
2007-02-07 01:48:09 +00:00
|
|
|
width, height, PIX_FMT_RGB32,
|
2006-10-11 12:08:36 +00:00
|
|
|
width, height, pix_fmt,
|
|
|
|
sws_flags, NULL, NULL, NULL);
|
|
|
|
if (ci->fromRGB_convert_ctx == NULL) {
|
|
|
|
av_log(NULL, AV_LOG_ERROR,
|
|
|
|
"Cannot initialize the fromRGB conversion context\n");
|
2007-04-01 17:23:15 +00:00
|
|
|
return;
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
2006-10-11 12:08:36 +00:00
|
|
|
// img_convert parameters are 2 first destination, then 4 source
|
|
|
|
// sws_scale parameters are context, 4 first source, then 2 destination
|
|
|
|
sws_scale(ci->fromRGB_convert_ctx,
|
|
|
|
picture1.data, picture1.linesize, 0, height,
|
|
|
|
picture->data, picture->linesize);
|
2002-11-21 03:50:36 +00:00
|
|
|
|
2006-11-07 09:12:20 +00:00
|
|
|
ci->frame_number++;
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
|
|
|
|