diff options
Diffstat (limited to 'contrib/ffmpeg/vhook')
-rw-r--r-- | contrib/ffmpeg/vhook/Makefile | 50 | ||||
-rw-r--r-- | contrib/ffmpeg/vhook/drawtext.c | 6 | ||||
-rw-r--r-- | contrib/ffmpeg/vhook/fish.c | 2 | ||||
-rw-r--r-- | contrib/ffmpeg/vhook/imlib2.c | 183 | ||||
-rw-r--r-- | contrib/ffmpeg/vhook/ppm.c | 5 | ||||
-rw-r--r-- | contrib/ffmpeg/vhook/watermark.c | 8 |
6 files changed, 122 insertions, 132 deletions
diff --git a/contrib/ffmpeg/vhook/Makefile b/contrib/ffmpeg/vhook/Makefile deleted file mode 100644 index 167b8bfb0..000000000 --- a/contrib/ffmpeg/vhook/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -include ../config.mak - -VPATH=$(SRC_PATH_BARE)/vhook - -CFLAGS=-I$(BUILD_ROOT) -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec \ - -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libswscale $(VHOOKCFLAGS) -DHAVE_AV_CONFIG_H -LDFLAGS+= -g - -HOOKS=null$(SLIBSUF) fish$(SLIBSUF) ppm$(SLIBSUF) watermark$(SLIBSUF) -ALLHOOKS=$(HOOKS) imlib2$(SLIBSUF) drawtext$(SLIBSUF) - -ifeq ($(HAVE_IMLIB2),yes) - HOOKS += imlib2$(SLIBSUF) - CFLAGS += `imlib2-config --cflags` - LIBS_imlib2$(SLIBSUF) = `imlib2-config --libs` -endif - -ifeq ($(HAVE_FREETYPE2),yes) - HOOKS += drawtext$(SLIBSUF) - CFLAGS += `freetype-config --cflags` - LIBS_drawtext$(SLIBSUF) = `freetype-config --libs` -endif - -SRCS := $(HOOKS:$(SLIBSUF)=.c) - -all: $(HOOKS) - -depend dep: $(SRCS) - $(CC) -MM $(CFLAGS) $^ 1>.depend - -install: $(HOOKS) - install -d "$(shlibdir)/vhook" - install -m 755 $(HOOKS) "$(shlibdir)/vhook" - -uninstall: - rm -f $(addprefix $(shlibdir)/vhook/,$(ALLHOOKS)) - -rmdir "$(shlibdir)/vhook/" - -%$(SLIBSUF): %.o - $(CC) $(LDFLAGS) -o $@ $(VHOOKSHFLAGS) $< $(VHOOKLIBS) $(LIBS_$@) - -clean: - rm -f *.o *.d *~ *.a *.lib *.so *.dylib *.dll - -distclean: clean - rm -f .depend - -.PHONY: all depend dep clean distclean install* uninstall* - --include .depend diff --git a/contrib/ffmpeg/vhook/drawtext.c b/contrib/ffmpeg/vhook/drawtext.c index 081847620..d3ca767fe 100644 --- a/contrib/ffmpeg/vhook/drawtext.c +++ b/contrib/ffmpeg/vhook/drawtext.c @@ -172,7 +172,7 @@ int Configure(void **ctxp, int argc, char *argv[]) ci->outline = 0; ci->text_height = 0; - optind = 0; + optind = 1; while ((c = getopt(argc, argv, "f:t:T:x:y:s:c:C:bo")) > 0) { switch (c) { case 'f': @@ -203,7 +203,7 @@ int Configure(void **ctxp, int argc, char *argv[]) case 'C': if (ParseColor(optarg, ci->bgcolor) == -1) { - av_log(NULL, AV_LOG_ERROR, "Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n", optarg); + av_log(NULL, AV_LOG_ERROR, "Invalid background color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -C #ffffff (for white background)\n", optarg); return -1; } break; @@ -506,7 +506,7 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, if ( ( (c == '_') && (text == ci->text) ) || /* skip '_' (consider as space) IF text was specified in cmd line - (which doesn't like neasted quotes) */ + (which doesn't like nested quotes) */ ( c == '\n' ) /* Skip new line char, just go to new line */ ) continue; diff --git a/contrib/ffmpeg/vhook/fish.c b/contrib/ffmpeg/vhook/fish.c index 1571cf9b9..be23dc644 100644 --- a/contrib/ffmpeg/vhook/fish.c +++ b/contrib/ffmpeg/vhook/fish.c @@ -124,7 +124,7 @@ int Configure(void **ctxp, int argc, char *argv[]) *ctxp = av_mallocz(sizeof(ContextInfo)); ci = (ContextInfo *) *ctxp; - optind = 0; + optind = 1; ci->dir = "/tmp"; ci->threshold = 100; diff --git a/contrib/ffmpeg/vhook/imlib2.c b/contrib/ffmpeg/vhook/imlib2.c index 4e6ffb67c..7df4c0aca 100644 --- a/contrib/ffmpeg/vhook/imlib2.c +++ b/contrib/ffmpeg/vhook/imlib2.c @@ -2,52 +2,6 @@ * imlib2 based hook * Copyright (c) 2002 Philip Gladstone * - * 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. - * - * 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 - * - * Options: - * - * -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 - * -x <expresion> X coordinate of text or image - * -y <expresion> Y coordinate of text or image - * -i <filename> The filename to read a image from - * - * Expresions are functions of: - * 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 - * 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 @@ -126,10 +80,13 @@ typedef struct { Imlib_Font fn; char *text; char *file; - int r, g, b; + int r, g, b, a; + AVEvalExpr *eval_r, *eval_g, *eval_b, *eval_a; + char *expr_R, *expr_G, *expr_B, *expr_A; + int eval_colors; double x, y; char *fileImage; - struct _CachedImage *cache; + struct CachedImage *cache; Imlib_Image imageOverlaid; AVEvalExpr *eval_x, *eval_y; char *expr_x, *expr_y; @@ -142,8 +99,8 @@ typedef struct { struct SwsContext *fromRGB_convert_ctx; } ContextInfo; -typedef struct _CachedImage { - struct _CachedImage *next; +typedef struct CachedImage { + struct CachedImage *next; Imlib_Image image; int width; int height; @@ -164,8 +121,19 @@ void Release(void *ctx) imlib_context_set_image(ci->imageOverlaid); imlib_free_image(); } - ff_eval_free(ci->expr_x); - ff_eval_free(ci->expr_y); + 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); + ff_eval_free(ci->eval_a); + + 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); + av_free(ci->expr_A); sws_freeContext(ci->toRGB_convert_ctx); sws_freeContext(ci->fromRGB_convert_ctx); av_free(ctx); @@ -176,11 +144,13 @@ int Configure(void **ctxp, int argc, char *argv[]) { int c; ContextInfo *ci; + char *rgbtxt = 0; char *font = "LucidaSansDemiBold/16"; char *fp = getenv("FONTPATH"); char *color = 0; FILE *f; char *p; + char *error; *ctxp = av_mallocz(sizeof(ContextInfo)); ci = (ContextInfo *) *ctxp; @@ -190,7 +160,7 @@ int Configure(void **ctxp, int argc, char *argv[]) ci->expr_x = "0.0"; ci->expr_y = "0.0"; - optind = 0; + optind = 1; /* Use ':' to split FONTPATH */ if (fp) @@ -203,8 +173,26 @@ int Configure(void **ctxp, int argc, char *argv[]) imlib_add_path_to_font_path(fp); - while ((c = getopt(argc, argv, "c:f:F:t:x:y:i:")) > 0) { + while ((c = getopt(argc, argv, "R:G:B:A:C:c:f:F:t:x:y:i:")) > 0) { switch (c) { + 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; + case 'A': + ci->expr_A = av_strdup(optarg); + break; + case 'C': + rgbtxt = optarg; + break; case 'c': color = optarg; break; @@ -232,25 +220,42 @@ int Configure(void **ctxp, int argc, char *argv[]) } } - if (ci->text || ci->file) { - ci->fn = imlib_load_font(font); - if (!ci->fn) { - fprintf(stderr, "Failed to load font '%s'\n", font); + 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; } - imlib_context_set_font(ci->fn); - imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT); + + if (ci->text || ci->file) { + 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); } if (color) { char buff[256]; int done = 0; - f = fopen("/usr/share/X11/rgb.txt", "r"); - if (!f) - f = fopen("/usr/lib/X11/rgb.txt", "r"); + if (ci->eval_colors) + { + fprintf(stderr, "You must not specify both a color name and expressions for the colors.\n"); + return -1; + } + + if (rgbtxt) + f = fopen(rgbtxt, "r"); + else + { + f = fopen("/usr/share/X11/rgb.txt", "r"); + if (!f) + f = fopen("/usr/lib/X11/rgb.txt", "r"); + } if (!f) { - fprintf(stderr, "Failed to find rgb.txt\n"); + fprintf(stderr, "Failed to find RGB color names file\n"); return -1; } while (fgets(buff, sizeof(buff), f)) { @@ -272,8 +277,32 @@ int Configure(void **ctxp, int argc, char *argv[]) fprintf(stderr, "Unable to find color '%s' in rgb.txt\n", color); return -1; } + } else if (ci->eval_colors) { + 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); + return -1; + } + 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); + return -1; + } + 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); + return -1; + } } - imlib_context_set_color(ci->r, ci->g, ci->b, 255); + + if (ci->expr_A) { + 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); + 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); /* load the image (for example, credits for a movie) */ if (ci->fileImage) { @@ -287,13 +316,13 @@ int Configure(void **ctxp, int argc, char *argv[]) ci->imageOverlaid_height = imlib_image_get_height(); } - if (!(ci->eval_x = ff_parse(ci->expr_x, const_names, NULL, NULL, NULL, NULL, NULL))){ - av_log(NULL, AV_LOG_ERROR, "Couldn't parse x expression '%s'\n", ci->expr_x); + 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); return -1; } - if (!(ci->eval_y = ff_parse(ci->expr_y, const_names, NULL, NULL, NULL, NULL, NULL))){ - av_log(NULL, AV_LOG_ERROR, "Couldn't parse y expression '%s'\n", ci->expr_y); + 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); return -1; } @@ -340,7 +369,7 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, imlib_context_set_image(image); data = imlib_image_get_data(); - avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGB32, width, height); + avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGB32, width, height); // 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, @@ -410,6 +439,20 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, ci->y = ff_parse_eval(ci->eval_y, const_values, ci); y = ci->y; + if (ci->eval_a) { + ci->a = ff_parse_eval(ci->eval_a, const_values, ci); + } + + 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); + } + + if (ci->eval_colors || ci->eval_a) { + imlib_context_set_color(ci->r, ci->g, ci->b, ci->a); + } + if (!(ci->imageOverlaid)) for (p = buff; p; p = q) { q = strchr(p, '\n'); diff --git a/contrib/ffmpeg/vhook/ppm.c b/contrib/ffmpeg/vhook/ppm.c index 9f618e55b..db76998b5 100644 --- a/contrib/ffmpeg/vhook/ppm.c +++ b/contrib/ffmpeg/vhook/ppm.c @@ -28,6 +28,7 @@ #include "framehook.h" #include "avformat.h" #include "swscale.h" +#include "avstring.h" static int sws_flags = SWS_BICUBIC; @@ -68,8 +69,8 @@ static rwpipe *rwpipe_open( int argc, char *argv[] ) strcpy( command, "" ); for ( i = 0; i < argc; i ++ ) { - pstrcat( command, COMMAND_SIZE, argv[ i ] ); - pstrcat( command, COMMAND_SIZE, " " ); + av_strlcat( command, argv[ i ], COMMAND_SIZE ); + av_strlcat( command, " ", COMMAND_SIZE ); } dup2( output[ 0 ], STDIN_FILENO ); diff --git a/contrib/ffmpeg/vhook/watermark.c b/contrib/ffmpeg/vhook/watermark.c index aa6fee63c..a8f7d5728 100644 --- a/contrib/ffmpeg/vhook/watermark.c +++ b/contrib/ffmpeg/vhook/watermark.c @@ -435,9 +435,9 @@ void Process(void *ctx, { ContextInfo *ci = (ContextInfo *) ctx; if (1 == ci->mode) { - return Process1(ctx, picture, pix_fmt, src_width, src_height, pts); + Process1(ctx, picture, pix_fmt, src_width, src_height, pts); } else { - return Process0(ctx, picture, pix_fmt, src_width, src_height, pts); + Process0(ctx, picture, pix_fmt, src_width, src_height, pts); } } @@ -544,10 +544,6 @@ int get_watermark_picture(ContextInfo *ci, int cleanup) return -1; } - // Inform the codec that we can handle truncated bitstreams -- i.e., - // bitstreams where frame boundaries can fall in the middle of packets - if (ci->pCodec->capabilities & CODEC_CAP_TRUNCATED) - ci->pCodecCtx->flags|=CODEC_FLAG_TRUNCATED; // Open codec if(avcodec_open(ci->pCodecCtx, ci->pCodec)<0) { |