diff options
author | John Stebbins <[email protected]> | 2015-10-24 14:06:56 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-01-21 12:38:42 -0700 |
commit | 10ea76c71197b302b10088d93680a4bed4bc6b8e (patch) | |
tree | 459b46b16256c39ed34fe1f0a4b9476ec3439871 /libhb/common.c | |
parent | ef956e695879c716dc22c96f7f8fa24e3fa5d08c (diff) |
libhb: Add libavfilter support and pad filter
New filter types HB_FILTER_AVFILTER and HB_FILTER_PAD.
Settings for HB_FILTER_AVFILTER are the same as you would pass to avconv
from the command line -vf option, except that we do not support
multi-input or multi-output filters.
Settings for HB_FILTER_PAD are "width:height:color:x_offset:y_offset".
width x height is the size of the output frame after padding.
color may be a w3c color name or RGB value (default black).
x_offset, y_offset is the position of the video within the padded area
(default centered).
Any of the values may be omitted or "auto".
Diffstat (limited to 'libhb/common.c')
-rw-r--r-- | libhb/common.c | 145 |
1 files changed, 143 insertions, 2 deletions
diff --git a/libhb/common.c b/libhb/common.c index f33a4abca..62826a654 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -3765,6 +3765,14 @@ hb_filter_object_t * hb_filter_init( int filter_id ) filter = &hb_filter_crop_scale; break; + case HB_FILTER_AVFILTER: + filter = &hb_filter_avfilter; + break; + + case HB_FILTER_PAD: + filter = &hb_filter_pad; + break; + case HB_FILTER_ROTATE: filter = &hb_filter_rotate; break; @@ -3803,14 +3811,28 @@ void hb_filter_close( hb_filter_object_t ** _f ) { hb_filter_object_t * f = *_f; - if( f->settings ) - free( f->settings ); + free(f->settings); free( f ); *_f = NULL; } /********************************************************************** + * hb_filter_info_close + ********************************************************************** + * + *********************************************************************/ +void hb_filter_info_close( hb_filter_info_t ** _fi ) +{ + hb_filter_info_t * fi = *_fi; + + free(fi->human_readable_desc); + + free( fi ); + *_fi = NULL; +} + +/********************************************************************** * hb_chapter_copy ********************************************************************** * @@ -4843,3 +4865,122 @@ void hb_hexdump( hb_debug_level_t level, const char * label, const uint8_t * dat hb_deep_log( level, " %-50s%20s", line, ascii ); } } + +int hb_str_vlen(char **strv) +{ + int i; + if (strv == NULL) + return 0; + for (i = 0; strv[i]; i++); + return i; +} + +static const char* strchr_quote(const char *pos, char c, char q) +{ + if (pos == NULL) + return NULL; + + while (*pos != 0 && *pos != c) + { + if (*pos == q) + { + pos = strchr_quote(pos+1, q, 0); + if (pos == NULL) + return NULL; + pos++; + } + else if (*pos == '\\' && *(pos+1) != 0) + pos += 2; + else + pos++; + } + if (*pos != c) + return NULL; + return pos; +} + +static char *strndup_quote(const char *str, char q, int len) +{ + if (str == NULL) + return NULL; + + char * res; + int str_len = strlen( str ); + int src = 0, dst = 0; + res = malloc( len > str_len ? str_len + 1 : len + 1 ); + if ( res == NULL ) return res; + + while (str[src] != 0 && src < len) + { + if (str[src] == q) + src++; + else if (str[src] == '\\' && str[src+1] != 0) + { + res[dst++] = str[src+1]; + src += 2; + } + else + res[dst++] = str[src++]; + } + res[dst] = '\0'; + return res; +} + +char** hb_str_vsplit( const char *str, char delem ) +{ + const char * pos; + const char * end; + char ** ret; + int count, i; + char quote = '"'; + + if (delem == '"') + { + quote = '\''; + } + if ( str == NULL || str[0] == 0 ) + { + ret = malloc( sizeof(char*) ); + if ( ret == NULL ) return ret; + *ret = NULL; + return ret; + } + + // Find number of elements in the string + count = 1; + pos = str; + while ( ( pos = strchr_quote( pos, delem, quote ) ) != NULL ) + { + count++; + pos++; + } + + ret = calloc( ( count + 1 ), sizeof(char*) ); + if ( ret == NULL ) return ret; + + pos = str; + for ( i = 0; i < count - 1; i++ ) + { + end = strchr_quote( pos, delem, quote ); + ret[i] = strndup_quote(pos, quote, end - pos); + pos = end + 1; + } + ret[i] = strndup_quote(pos, quote, strlen(pos)); + + return ret; +} + +void hb_str_vfree( char **strv ) +{ + int i; + + if (strv == NULL) + return; + + for ( i = 0; strv[i]; i++ ) + { + free( strv[i] ); + } + free( strv ); +} + |