Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • videolan/x264
  • EwoutH/x264
  • gramner/x264
  • BugMaster/x264
  • MaskRay/x264
  • thresh/x264
  • tpm/x264
  • wolfired/x264
  • ifb/x264
  • robinstorm/x264
  • ltnokiago/x264
  • janne/x264
  • Kromjunya/x264
  • trisnaayu0596/x264
  • felipegarcia1402/x264
  • coder2004/x264
  • philou/x264
  • walagnatalia/x264
  • DonDiego/x264
  • JHammler/x264
  • qyot27/x264
  • dwbuiten/x264
  • Kagami/x264
  • andriy-andreyev/x264
  • gxw/x264
  • trofi/x264
  • kierank/x264
  • aureliendavid/x264
  • galad/x264
  • roommini/x264
  • ocrete/x264
  • mstorsjo/x264
  • yinsj0116/x264
  • mamonet/x264
  • 1div0/x264
  • ko1265/x264
  • sergiomb2/x264
  • xutongda/x264
  • wenzhiwu/x264
  • arrowd/x264
  • FranceBB/x264
  • ziemek99/x264
  • longervision/x264
  • xopok/x264
  • jbk/x264
  • szatmary/x264
  • pekdon/x264
  • Jiangguyu/x264
  • jrtc27/x264
  • kankanol1/x264
  • gxwLite/x264
  • brad/x264
  • Gc6026/x264
  • jdek/x264
  • appcrash/x264
  • tguillem/x264
  • As/x264
  • wevian/x264
  • wangluls/x264
  • RellikJaeger/x264
  • hum/x264
  • rogerhardiman/x264
  • jankowalski12611/x264
  • zhijie1996/x264
  • yinshiyou/x264
  • Freed-Wu/x264
  • yajcoca/x264
  • bUd/x264
  • chienvannguyen2020/x264
  • nurbinakhatun386/x264
  • Siberiawind/x-264-meson
  • HecaiYuan/x264
  • david.chen/x264
  • Ytsejam76/x264
  • robUx4/x264
  • zhaoshiz/x-264-arm64ec
  • yintong.ustc/x-264-bd-ventana
  • nekobasu/x264
  • Courmisch/x264
  • BD-qjy/x264
  • quink/x264
  • markos/x264
  • pranavk/x264
  • robxnano/x264
84 results
Show changes
Commits on Source (9)
...@@ -410,6 +410,12 @@ else ifneq ($(SONAME),) ...@@ -410,6 +410,12 @@ else ifneq ($(SONAME),)
$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(libdir) $(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(libdir)
endif endif
install-bashcompletion:
ifneq ($(BASHCOMPLETIONSDIR),)
$(INSTALL) -d $(DESTDIR)$(BASHCOMPLETIONSDIR)
$(INSTALL) -m 644 -T $(SRCPATH)/tools/bash-autocomplete.sh $(DESTDIR)$(BASHCOMPLETIONSDIR)/x264
endif
uninstall: uninstall:
rm -f $(DESTDIR)$(includedir)/x264.h $(DESTDIR)$(includedir)/x264_config.h $(DESTDIR)$(libdir)/libx264.a rm -f $(DESTDIR)$(includedir)/x264.h $(DESTDIR)$(includedir)/x264_config.h $(DESTDIR)$(libdir)/libx264.a
rm -f $(DESTDIR)$(bindir)/x264$(EXE) $(DESTDIR)$(libdir)/pkgconfig/x264.pc rm -f $(DESTDIR)$(bindir)/x264$(EXE) $(DESTDIR)$(libdir)/pkgconfig/x264.pc
...@@ -418,6 +424,9 @@ ifneq ($(IMPLIBNAME),) ...@@ -418,6 +424,9 @@ ifneq ($(IMPLIBNAME),)
else ifneq ($(SONAME),) else ifneq ($(SONAME),)
rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX) rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)
endif endif
ifneq ($(BASHCOMPLETIONSDIR),)
rm -f $(DESTDIR)$(BASHCOMPLETIONSDIR)/x264
endif
etags TAGS: etags TAGS:
etags $(SRCS) $(SRCS_X) $(SRCS_8) etags $(SRCS) $(SRCS_X) $(SRCS_8)
...@@ -331,8 +331,8 @@ int x264_cli_autocomplete( const char *prev, const char *cur ) ...@@ -331,8 +331,8 @@ int x264_cli_autocomplete( const char *prev, const char *cur )
OPT( "--input-fmt" ) OPT( "--input-fmt" )
{ {
#if HAVE_LAVF #if HAVE_LAVF
av_register_all(); void *i = NULL;
for( const AVInputFormat *f = NULL; (f = av_iformat_next( f )); ) for( const AVInputFormat *f; (f = av_demuxer_iterate( &i )); )
suggest_token( f->name, ',' ); suggest_token( f->name, ',' );
#endif #endif
} }
......
...@@ -198,6 +198,66 @@ error: ...@@ -198,6 +198,66 @@ error:
return NULL; return NULL;
} }
/****************************************************************************
* x264_param_strdup:
****************************************************************************/
typedef struct {
int size;
int count;
void *ptr[];
} strdup_buffer;
#define BUFFER_OFFSET offsetof(strdup_buffer, ptr)
#define BUFFER_DEFAULT_SIZE 16
char *x264_param_strdup( x264_param_t *param, const char *src )
{
strdup_buffer *buf = param->opaque;
if( !buf )
{
buf = malloc( BUFFER_OFFSET + BUFFER_DEFAULT_SIZE * sizeof(void *) );
if( !buf )
goto fail;
buf->size = BUFFER_DEFAULT_SIZE;
buf->count = 0;
param->opaque = buf;
}
else if( buf->count == buf->size )
{
if( buf->size > (INT_MAX - BUFFER_OFFSET) / 2 / (int)sizeof(void *) )
goto fail;
int new_size = buf->size * 2;
buf = realloc( buf, BUFFER_OFFSET + new_size * sizeof(void *) );
if( !buf )
goto fail;
buf->size = new_size;
param->opaque = buf;
}
char *res = strdup( src );
if( !res )
goto fail;
buf->ptr[buf->count++] = res;
return res;
fail:
x264_log_internal( X264_LOG_ERROR, "x264_param_strdup failed\n" );
return NULL;
}
/****************************************************************************
* x264_param_cleanup:
****************************************************************************/
REALIGN_STACK void x264_param_cleanup( x264_param_t *param )
{
strdup_buffer *buf = param->opaque;
if( buf )
{
for( int i = 0; i < buf->count; i++ )
free( buf->ptr[i] );
free( buf );
param->opaque = NULL;
}
}
/**************************************************************************** /****************************************************************************
* x264_picture_init: * x264_picture_init:
****************************************************************************/ ****************************************************************************/
...@@ -811,6 +871,15 @@ static double atof_internal( const char *str, int *b_error ) ...@@ -811,6 +871,15 @@ static double atof_internal( const char *str, int *b_error )
#undef atof #undef atof
#define atoi(str) atoi_internal( str, &b_error ) #define atoi(str) atoi_internal( str, &b_error )
#define atof(str) atof_internal( str, &b_error ) #define atof(str) atof_internal( str, &b_error )
#define CHECKED_ERROR_PARAM_STRDUP( var, param, src )\
do {\
var = x264_param_strdup( param, src );\
if( !var )\
{\
b_error = 1;\
errortype = X264_PARAM_ALLOC_FAILED;\
}\
} while( 0 )
REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const char *value ) REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const char *value )
{ {
...@@ -833,7 +902,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -833,7 +902,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
char *c; char *c;
name_buf = strdup(name); name_buf = strdup(name);
if( !name_buf ) if( !name_buf )
return X264_PARAM_BAD_NAME; return X264_PARAM_ALLOC_FAILED;
while( (c = strchr( name_buf, '_' )) ) while( (c = strchr( name_buf, '_' )) )
*c = '-'; *c = '-';
name = name_buf; name = name_buf;
...@@ -876,6 +945,8 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -876,6 +945,8 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
if( (p->cpu&X264_CPU_SSSE3) && !(p->cpu&X264_CPU_SSE2_IS_SLOW) ) if( (p->cpu&X264_CPU_SSSE3) && !(p->cpu&X264_CPU_SSE2_IS_SLOW) )
p->cpu |= X264_CPU_SSE2_IS_FAST; p->cpu |= X264_CPU_SSE2_IS_FAST;
} }
else
errortype = X264_PARAM_ALLOC_FAILED;
} }
} }
OPT("threads") OPT("threads")
...@@ -1062,10 +1133,10 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -1062,10 +1133,10 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
else if( strstr( value, "jvt" ) ) else if( strstr( value, "jvt" ) )
p->i_cqm_preset = X264_CQM_JVT; p->i_cqm_preset = X264_CQM_JVT;
else else
p->psz_cqm_file = strdup(value); CHECKED_ERROR_PARAM_STRDUP( p->psz_cqm_file, p, value );
} }
OPT("cqmfile") OPT("cqmfile")
p->psz_cqm_file = strdup(value); CHECKED_ERROR_PARAM_STRDUP( p->psz_cqm_file, p, value );
OPT("cqm4") OPT("cqm4")
{ {
p->i_cqm_preset = X264_CQM_CUSTOM; p->i_cqm_preset = X264_CQM_CUSTOM;
...@@ -1129,7 +1200,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -1129,7 +1200,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
OPT("log") OPT("log")
p->i_log_level = atoi(value); p->i_log_level = atoi(value);
OPT("dump-yuv") OPT("dump-yuv")
p->psz_dump_yuv = strdup(value); CHECKED_ERROR_PARAM_STRDUP( p->psz_dump_yuv, p, value );
OPT2("analyse", "partitions") OPT2("analyse", "partitions")
{ {
p->analyse.inter = 0; p->analyse.inter = 0;
...@@ -1245,8 +1316,8 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -1245,8 +1316,8 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
} }
OPT("stats") OPT("stats")
{ {
p->rc.psz_stat_in = strdup(value); CHECKED_ERROR_PARAM_STRDUP( p->rc.psz_stat_in, p, value );
p->rc.psz_stat_out = strdup(value); CHECKED_ERROR_PARAM_STRDUP( p->rc.psz_stat_out, p, value );
} }
OPT("qcomp") OPT("qcomp")
p->rc.f_qcompress = atof(value); p->rc.f_qcompress = atof(value);
...@@ -1257,7 +1328,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -1257,7 +1328,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
OPT2("cplxblur", "cplx-blur") OPT2("cplxblur", "cplx-blur")
p->rc.f_complexity_blur = atof(value); p->rc.f_complexity_blur = atof(value);
OPT("zones") OPT("zones")
p->rc.psz_zones = strdup(value); CHECKED_ERROR_PARAM_STRDUP( p->rc.psz_zones, p, value );
OPT("crop-rect") OPT("crop-rect")
b_error |= sscanf( value, "%d,%d,%d,%d", &p->crop_rect.i_left, &p->crop_rect.i_top, b_error |= sscanf( value, "%d,%d,%d,%d", &p->crop_rect.i_left, &p->crop_rect.i_top,
&p->crop_rect.i_right, &p->crop_rect.i_bottom ) != 4; &p->crop_rect.i_right, &p->crop_rect.i_bottom ) != 4;
...@@ -1292,7 +1363,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha ...@@ -1292,7 +1363,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
OPT("opencl") OPT("opencl")
p->b_opencl = atobool( value ); p->b_opencl = atobool( value );
OPT("opencl-clbin") OPT("opencl-clbin")
p->psz_clbin_file = strdup( value ); CHECKED_ERROR_PARAM_STRDUP( p->psz_clbin_file, p, value );
OPT("opencl-device") OPT("opencl-device")
p->i_opencl_device = atoi( value ); p->i_opencl_device = atoi( value );
else else
......
...@@ -261,7 +261,7 @@ X264_API void x264_reduce_fraction64( uint64_t *n, uint64_t *d ); ...@@ -261,7 +261,7 @@ X264_API void x264_reduce_fraction64( uint64_t *n, uint64_t *d );
X264_API void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg ); X264_API void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg );
X264_API void x264_log_internal( int i_level, const char *psz_fmt, ... ); X264_API void x264_log_internal( int i_level, const char *psz_fmt, ... );
/* x264_malloc : will do or emulate a memalign /* x264_malloc: will do or emulate a memalign
* you have to use x264_free for buffers allocated with x264_malloc */ * you have to use x264_free for buffers allocated with x264_malloc */
X264_API void *x264_malloc( int64_t ); X264_API void *x264_malloc( int64_t );
X264_API void x264_free( void * ); X264_API void x264_free( void * );
...@@ -269,6 +269,10 @@ X264_API void x264_free( void * ); ...@@ -269,6 +269,10 @@ X264_API void x264_free( void * );
/* x264_slurp_file: malloc space for the whole file and read it */ /* x264_slurp_file: malloc space for the whole file and read it */
X264_API char *x264_slurp_file( const char *filename ); X264_API char *x264_slurp_file( const char *filename );
/* x264_param_strdup: will do strdup and save returned pointer inside
* x264_param_t for later freeing during x264_param_cleanup */
char *x264_param_strdup( x264_param_t *param, const char *src );
/* x264_param2string: return a (malloced) string containing most of /* x264_param2string: return a (malloced) string containing most of
* the encoding options */ * the encoding options */
X264_API char *x264_param2string( x264_param_t *p, int b_res ); X264_API char *x264_param2string( x264_param_t *p, int b_res );
...@@ -287,6 +291,12 @@ do {\ ...@@ -287,6 +291,12 @@ do {\
CHECKED_MALLOC( var, size );\ CHECKED_MALLOC( var, size );\
memset( var, 0, size );\ memset( var, 0, size );\
} while( 0 ) } while( 0 )
#define CHECKED_PARAM_STRDUP( var, param, src )\
do {\
var = x264_param_strdup( param, src );\
if( !var )\
goto fail;\
} while( 0 )
/* Macros for merging multiple allocations into a single large malloc, for improved /* Macros for merging multiple allocations into a single large malloc, for improved
* use with huge pages. */ * use with huge pages. */
......
...@@ -318,7 +318,10 @@ void x264_frame_delete( x264_frame_t *frame ) ...@@ -318,7 +318,10 @@ void x264_frame_delete( x264_frame_t *frame )
x264_free( frame->base ); x264_free( frame->base );
if( frame->param && frame->param->param_free ) if( frame->param && frame->param->param_free )
{
x264_param_cleanup( frame->param );
frame->param->param_free( frame->param ); frame->param->param_free( frame->param );
}
if( frame->mb_info_free ) if( frame->mb_info_free )
frame->mb_info_free( frame->mb_info ); frame->mb_info_free( frame->mb_info );
if( frame->extra_sei.sei_free ) if( frame->extra_sei.sei_free )
......
...@@ -25,6 +25,9 @@ Configuration options: ...@@ -25,6 +25,9 @@ Configuration options:
--system-libx264 use system libx264 instead of internal --system-libx264 use system libx264 instead of internal
--enable-shared build shared library --enable-shared build shared library
--enable-static build static library --enable-static build static library
--disable-bashcompletion disable installation of bash-completion script
--enable-bashcompletion force installation of bash-completion script
--bashcompletionsdir=DIR install bash-completion script in DIR [auto]
--disable-opencl disable OpenCL features --disable-opencl disable OpenCL features
--disable-gpl disable GPL-only features --disable-gpl disable GPL-only features
--disable-thread disable multithreaded encoding --disable-thread disable multithreaded encoding
...@@ -363,6 +366,8 @@ cli="yes" ...@@ -363,6 +366,8 @@ cli="yes"
cli_libx264="internal" cli_libx264="internal"
shared="no" shared="no"
static="no" static="no"
bashcompletion="auto"
bashcompletionsdir=""
avs="auto" avs="auto"
lavf="auto" lavf="auto"
ffms="auto" ffms="auto"
...@@ -439,6 +444,15 @@ for opt do ...@@ -439,6 +444,15 @@ for opt do
--enable-static) --enable-static)
static="yes" static="yes"
;; ;;
--disable-bashcompletion)
bashcompletion="no"
;;
--enable-bashcompletion)
bashcompletion="yes"
;;
--bashcompletionsdir=*)
bashcompletionsdir="$optarg"
;;
--disable-asm) --disable-asm)
asm="no" asm="no"
;; ;;
...@@ -1154,7 +1168,7 @@ if [ "$lavf" = "auto" ] ; then ...@@ -1154,7 +1168,7 @@ if [ "$lavf" = "auto" ] ; then
done done
fi fi
if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "av_register_all();" ; then if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "av_demuxer_iterate(0);" ; then
if cc_check libavcodec/avcodec.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_send_packet(0,0);" ; then if cc_check libavcodec/avcodec.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_send_packet(0,0);" ; then
lavf="yes" lavf="yes"
else else
...@@ -1232,15 +1246,16 @@ if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then ...@@ -1232,15 +1246,16 @@ if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then
gpac="no" gpac="no"
GPAC_LIBS="-lgpac_static" GPAC_LIBS="-lgpac_static"
cc_check "" -lz && GPAC_LIBS="$GPAC_LIBS -lz" cc_check "" -lz && GPAC_LIBS="$GPAC_LIBS -lz"
cc_check "" -ldl && GPAC_LIBS="$GPAC_LIBS -ldl"
if [ "$SYS" = "WINDOWS" ] ; then if [ "$SYS" = "WINDOWS" ] ; then
cc_check "" -lws2_32 && GPAC_LIBS="$GPAC_LIBS -lws2_32" cc_check "" -lws2_32 && GPAC_LIBS="$GPAC_LIBS -lws2_32"
cc_check "" -lwinmm && GPAC_LIBS="$GPAC_LIBS -lwinmm" cc_check "" -lwinmm && GPAC_LIBS="$GPAC_LIBS -lwinmm"
fi fi
if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_close(0);" ; then if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_close(0);" ; then
if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0,0);" ; then
gpac="yes" gpac="yes"
else else
echo "Warning: gpac is too old, update to 2007-06-21 UTC or later" echo "Warning: gpac is too old, update to v0.8.0 or later"
fi fi
fi fi
fi fi
...@@ -1563,6 +1578,27 @@ if [ "$static" = "yes" ]; then ...@@ -1563,6 +1578,27 @@ if [ "$static" = "yes" ]; then
echo 'install: install-lib-static' >> config.mak echo 'install: install-lib-static' >> config.mak
fi fi
if [ "$bashcompletion" = "auto" ]; then
if [ "$cli" = "no" ]; then
bashcompletion="no"
elif [[ -z "$bashcompletionsdir" && "$prefix" != "/usr" && "$prefix" != "/usr/"* ]]; then
bashcompletion="no"
fi
fi
if [ "$bashcompletion" != "no" ]; then
if [ -z "$bashcompletionsdir" ] && pkg_check bash-completion ; then
bashcompletionsdir="$($PKGCONFIG --variable=completionsdir bash-completion)"
fi
if [ -n "$bashcompletionsdir" ]; then
bashcompletion="yes"
echo 'install: install-bashcompletion' >> config.mak
echo "BASHCOMPLETIONSDIR=$bashcompletionsdir" >> config.mak
else
bashcompletion="no"
fi
fi
cat > x264.pc << EOF cat > x264.pc << EOF
prefix=$prefix prefix=$prefix
exec_prefix=$exec_prefix exec_prefix=$exec_prefix
...@@ -1581,30 +1617,31 @@ filters="crop select_every" ...@@ -1581,30 +1617,31 @@ filters="crop select_every"
[ $swscale = yes ] && filters="resize $filters" [ $swscale = yes ] && filters="resize $filters"
cat > conftest.log <<EOF cat > conftest.log <<EOF
platform: $ARCH platform: $ARCH
byte order: $CPU_ENDIAN byte order: $CPU_ENDIAN
system: $SYS system: $SYS
cli: $cli cli: $cli
libx264: $cli_libx264 libx264: $cli_libx264
shared: $shared shared: $shared
static: $static static: $static
asm: $asm bashcompletion: $bashcompletion
interlaced: $interlaced asm: $asm
avs: $avs interlaced: $interlaced
lavf: $lavf avs: $avs
ffms: $ffms lavf: $lavf
mp4: $mp4 ffms: $ffms
gpl: $gpl mp4: $mp4
thread: $thread gpl: $gpl
opencl: $opencl thread: $thread
filters: $filters opencl: $opencl
lto: $lto filters: $filters
debug: $debug lto: $lto
gprof: $gprof debug: $debug
strip: $strip gprof: $gprof
PIC: $pic strip: $strip
bit depth: $bit_depth PIC: $pic
chroma format: $chroma_format bit depth: $bit_depth
chroma format: $chroma_format
EOF EOF
echo >> config.log echo >> config.log
......
...@@ -1460,9 +1460,27 @@ x264_t *x264_encoder_open( x264_param_t *param ) ...@@ -1460,9 +1460,27 @@ x264_t *x264_encoder_open( x264_param_t *param )
/* Create a copy of param */ /* Create a copy of param */
memcpy( &h->param, param, sizeof(x264_param_t) ); memcpy( &h->param, param, sizeof(x264_param_t) );
h->param.opaque = NULL;
h->param.param_free = NULL;
if( h->param.psz_cqm_file )
CHECKED_PARAM_STRDUP( h->param.psz_cqm_file, &h->param, h->param.psz_cqm_file );
if( h->param.psz_dump_yuv )
CHECKED_PARAM_STRDUP( h->param.psz_dump_yuv, &h->param, h->param.psz_dump_yuv );
if( h->param.rc.psz_stat_out )
CHECKED_PARAM_STRDUP( h->param.rc.psz_stat_out, &h->param, h->param.rc.psz_stat_out );
if( h->param.rc.psz_stat_in )
CHECKED_PARAM_STRDUP( h->param.rc.psz_stat_in, &h->param, h->param.rc.psz_stat_in );
if( h->param.rc.psz_zones )
CHECKED_PARAM_STRDUP( h->param.rc.psz_zones, &h->param, h->param.rc.psz_zones );
if( h->param.psz_clbin_file )
CHECKED_PARAM_STRDUP( h->param.psz_clbin_file, &h->param, h->param.psz_clbin_file );
if( param->param_free ) if( param->param_free )
{
x264_param_cleanup( param );
param->param_free( param ); param->param_free( param );
}
#if HAVE_INTEL_DISPATCHER #if HAVE_INTEL_DISPATCHER
x264_intel_dispatcher_override(); x264_intel_dispatcher_override();
...@@ -1481,11 +1499,6 @@ x264_t *x264_encoder_open( x264_param_t *param ) ...@@ -1481,11 +1499,6 @@ x264_t *x264_encoder_open( x264_param_t *param )
if( x264_cqm_parse_file( h, h->param.psz_cqm_file ) < 0 ) if( x264_cqm_parse_file( h, h->param.psz_cqm_file ) < 0 )
goto fail; goto fail;
if( h->param.rc.psz_stat_out )
h->param.rc.psz_stat_out = strdup( h->param.rc.psz_stat_out );
if( h->param.rc.psz_stat_in )
h->param.rc.psz_stat_in = strdup( h->param.rc.psz_stat_in );
x264_reduce_fraction( &h->param.i_fps_num, &h->param.i_fps_den ); x264_reduce_fraction( &h->param.i_fps_num, &h->param.i_fps_den );
x264_reduce_fraction( &h->param.i_timebase_num, &h->param.i_timebase_den ); x264_reduce_fraction( &h->param.i_timebase_num, &h->param.i_timebase_den );
...@@ -1900,6 +1913,7 @@ int x264_encoder_reconfig( x264_t *h, x264_param_t *param ) ...@@ -1900,6 +1913,7 @@ int x264_encoder_reconfig( x264_t *h, x264_param_t *param )
void x264_encoder_parameters( x264_t *h, x264_param_t *param ) void x264_encoder_parameters( x264_t *h, x264_param_t *param )
{ {
memcpy( param, &h->thread[h->i_thread_phase]->param, sizeof(x264_param_t) ); memcpy( param, &h->thread[h->i_thread_phase]->param, sizeof(x264_param_t) );
param->opaque = NULL;
} }
/* internal usage */ /* internal usage */
...@@ -3395,6 +3409,7 @@ int x264_encoder_encode( x264_t *h, ...@@ -3395,6 +3409,7 @@ int x264_encoder_encode( x264_t *h,
x264_encoder_reconfig_apply( h, h->fenc->param ); x264_encoder_reconfig_apply( h, h->fenc->param );
if( h->fenc->param->param_free ) if( h->fenc->param->param_free )
{ {
x264_param_cleanup( h->fenc->param );
h->fenc->param->param_free( h->fenc->param ); h->fenc->param->param_free( h->fenc->param );
h->fenc->param = NULL; h->fenc->param = NULL;
} }
...@@ -4418,10 +4433,7 @@ void x264_encoder_close ( x264_t *h ) ...@@ -4418,10 +4433,7 @@ void x264_encoder_close ( x264_t *h )
x264_ratecontrol_delete( h ); x264_ratecontrol_delete( h );
/* param */ /* param */
if( h->param.rc.psz_stat_out ) x264_param_cleanup( &h->param );
free( h->param.rc.psz_stat_out );
if( h->param.rc.psz_stat_in )
free( h->param.rc.psz_stat_in );
x264_cqm_delete( h ); x264_cqm_delete( h );
x264_free( h->nal_buffer ); x264_free( h->nal_buffer );
......
...@@ -1237,6 +1237,7 @@ static int parse_zone( x264_t *h, x264_zone_t *z, char *p ) ...@@ -1237,6 +1237,7 @@ static int parse_zone( x264_t *h, x264_zone_t *z, char *p )
return 0; return 0;
CHECKED_MALLOC( z->param, sizeof(x264_param_t) ); CHECKED_MALLOC( z->param, sizeof(x264_param_t) );
memcpy( z->param, &h->param, sizeof(x264_param_t) ); memcpy( z->param, &h->param, sizeof(x264_param_t) );
z->param->opaque = NULL;
z->param->param_free = x264_free; z->param->param_free = x264_free;
while( (tok = strtok_r( p, ",", &saveptr )) ) while( (tok = strtok_r( p, ",", &saveptr )) )
{ {
...@@ -1315,6 +1316,7 @@ static int parse_zones( x264_t *h ) ...@@ -1315,6 +1316,7 @@ static int parse_zones( x264_t *h )
rc->zones[0].f_bitrate_factor = 1; rc->zones[0].f_bitrate_factor = 1;
CHECKED_MALLOC( rc->zones[0].param, sizeof(x264_param_t) ); CHECKED_MALLOC( rc->zones[0].param, sizeof(x264_param_t) );
memcpy( rc->zones[0].param, &h->param, sizeof(x264_param_t) ); memcpy( rc->zones[0].param, &h->param, sizeof(x264_param_t) );
rc->zones[0].param->opaque = NULL;
for( int i = 1; i < rc->i_zones; i++ ) for( int i = 1; i < rc->i_zones; i++ )
{ {
if( !rc->zones[i].param ) if( !rc->zones[i].param )
...@@ -1391,10 +1393,14 @@ void x264_ratecontrol_delete( x264_t *h ) ...@@ -1391,10 +1393,14 @@ void x264_ratecontrol_delete( x264_t *h )
macroblock_tree_rescale_destroy( rc ); macroblock_tree_rescale_destroy( rc );
if( rc->zones ) if( rc->zones )
{ {
x264_param_cleanup( rc->zones[0].param );
x264_free( rc->zones[0].param ); x264_free( rc->zones[0].param );
for( int i = 1; i < rc->i_zones; i++ ) for( int i = 1; i < rc->i_zones; i++ )
if( rc->zones[i].param != rc->zones[0].param && rc->zones[i].param->param_free ) if( rc->zones[i].param != rc->zones[0].param && rc->zones[i].param->param_free )
{
x264_param_cleanup( rc->zones[i].param );
rc->zones[i].param->param_free( rc->zones[i].param ); rc->zones[i].param->param_free( rc->zones[i].param );
}
x264_free( rc->zones ); x264_free( rc->zones );
} }
x264_free( rc ); x264_free( rc );
......
...@@ -253,6 +253,32 @@ static float get_avs_version( avs_hnd_t *h ) ...@@ -253,6 +253,32 @@ static float get_avs_version( avs_hnd_t *h )
#endif #endif
} }
#ifdef _WIN32
static int utf16_to_ansi( const wchar_t *utf16, char *ansi )
{
BOOL invalid;
return WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, utf16, -1, ansi, MAX_PATH, NULL, &invalid ) && !invalid;
}
static int utf8_to_ansi( const char *filename, char *ansi_filename )
{
wchar_t filename_utf16[MAX_PATH];
if( utf8_to_utf16( filename, filename_utf16 ) )
{
/* Check if the filename already is valid ANSI. */
if( utf16_to_ansi( filename_utf16, ansi_filename ) )
return 1;
/* Check for a legacy 8.3 short filename. */
int short_length = GetShortPathNameW( filename_utf16, filename_utf16, MAX_PATH );
if( short_length > 0 && short_length < MAX_PATH )
if( utf16_to_ansi( filename_utf16, ansi_filename ) )
return 1;
}
return 0;
}
#endif
static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt ) static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
{ {
FILE *fh = x264_fopen( psz_filename, "r" ); FILE *fh = x264_fopen( psz_filename, "r" );
...@@ -280,7 +306,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c ...@@ -280,7 +306,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
#ifdef _WIN32 #ifdef _WIN32
/* Avisynth doesn't support Unicode filenames. */ /* Avisynth doesn't support Unicode filenames. */
char ansi_filename[MAX_PATH]; char ansi_filename[MAX_PATH];
FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 0 ), "invalid ansi filename\n" ); FAIL_IF_ERROR( !utf8_to_ansi( psz_filename, ansi_filename ), "invalid ansi filename\n" );
AVS_Value arg = avs_new_value_string( ansi_filename ); AVS_Value arg = avs_new_value_string( ansi_filename );
#else #else
AVS_Value arg = avs_new_value_string( psz_filename ); AVS_Value arg = avs_new_value_string( psz_filename );
......
...@@ -168,7 +168,6 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c ...@@ -168,7 +168,6 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
lavf_hnd_t *h = calloc( 1, sizeof(lavf_hnd_t) ); lavf_hnd_t *h = calloc( 1, sizeof(lavf_hnd_t) );
if( !h ) if( !h )
return -1; return -1;
av_register_all();
if( !strcmp( psz_filename, "-" ) ) if( !strcmp( psz_filename, "-" ) )
psz_filename = "pipe:"; psz_filename = "pipe:";
......
...@@ -27,10 +27,6 @@ ...@@ -27,10 +27,6 @@
#include "output.h" #include "output.h"
#include <gpac/isomedia.h> #include <gpac/isomedia.h>
#ifdef _WIN32
#include <windows.h>
#endif
typedef struct typedef struct
{ {
GF_ISOFile *p_file; GF_ISOFile *p_file;
...@@ -147,7 +143,11 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest ...@@ -147,7 +143,11 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
{ {
uint32_t mvhd_timescale = gf_isom_get_timescale( p_mp4->p_file ); uint32_t mvhd_timescale = gf_isom_get_timescale( p_mp4->p_file );
uint64_t tkhd_duration = (uint64_t)( mdhd_duration * ( (double)mvhd_timescale / p_mp4->i_time_res ) ); uint64_t tkhd_duration = (uint64_t)( mdhd_duration * ( (double)mvhd_timescale / p_mp4->i_time_res ) );
#if GPAC_VERSION_MAJOR > 8
gf_isom_append_edit( p_mp4->p_file, p_mp4->i_track, tkhd_duration, sample->CTS_Offset, GF_ISOM_EDIT_NORMAL );
#else
gf_isom_append_edit_segment( p_mp4->p_file, p_mp4->i_track, tkhd_duration, sample->CTS_Offset, GF_ISOM_EDIT_NORMAL ); gf_isom_append_edit_segment( p_mp4->p_file, p_mp4->i_track, tkhd_duration, sample->CTS_Offset, GF_ISOM_EDIT_NORMAL );
#endif
} }
gf_isom_sample_del( &sample ); gf_isom_sample_del( &sample );
...@@ -177,15 +177,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ...@@ -177,15 +177,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt
if( !p_mp4 ) if( !p_mp4 )
return -1; return -1;
#ifdef _WIN32
/* GPAC doesn't support Unicode filenames. */
char ansi_filename[MAX_PATH];
FAIL_IF_ERR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 1 ), "mp4", "invalid ansi filename\n" );
p_mp4->p_file = gf_isom_open( ansi_filename, GF_ISOM_OPEN_WRITE, NULL );
#else
p_mp4->p_file = gf_isom_open( psz_filename, GF_ISOM_OPEN_WRITE, NULL ); p_mp4->p_file = gf_isom_open( psz_filename, GF_ISOM_OPEN_WRITE, NULL );
#endif
p_mp4->b_dts_compress = opt->use_dts_compress; p_mp4->b_dts_compress = opt->use_dts_compress;
if( !(p_mp4->p_sample = gf_isom_sample_new()) ) if( !(p_mp4->p_sample = gf_isom_sample_new()) )
...@@ -233,7 +225,7 @@ static int set_param( hnd_t handle, x264_param_t *p_param ) ...@@ -233,7 +225,7 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
dw *= sar; dw *= sar;
else else
dh /= sar; dh /= sar;
gf_isom_set_pixel_aspect_ratio( p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_param->vui.i_sar_width, p_param->vui.i_sar_height ); gf_isom_set_pixel_aspect_ratio( p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_param->vui.i_sar_width, p_param->vui.i_sar_height, 0 );
gf_isom_set_track_layout_info( p_mp4->p_file, p_mp4->i_track, dw, dh, 0, 0, 0 ); gf_isom_set_track_layout_info( p_mp4->p_file, p_mp4->i_track, dw, dh, 0, 0, 0 );
} }
......
...@@ -65,6 +65,14 @@ ...@@ -65,6 +65,14 @@
#include <ffms.h> #include <ffms.h>
#endif #endif
#if HAVE_GPAC
#include <gpac/version.h>
#endif
#if HAVE_LSMASH
#include <lsmash.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
#define CONSOLE_TITLE_SIZE 200 #define CONSOLE_TITLE_SIZE 200
static wchar_t org_console_title[CONSOLE_TITLE_SIZE] = L""; static wchar_t org_console_title[CONSOLE_TITLE_SIZE] = L"";
...@@ -76,40 +84,6 @@ void x264_cli_set_console_title( const char *title ) ...@@ -76,40 +84,6 @@ void x264_cli_set_console_title( const char *title )
SetConsoleTitleW( title_utf16 ); SetConsoleTitleW( title_utf16 );
} }
static int utf16_to_ansi( const wchar_t *utf16, char *ansi, int size )
{
int invalid;
return WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, utf16, -1, ansi, size, NULL, &invalid ) && !invalid;
}
/* Some external libraries doesn't support Unicode in filenames,
* as a workaround we can try to get an ANSI filename instead. */
int x264_ansi_filename( const char *filename, char *ansi_filename, int size, int create_file )
{
wchar_t filename_utf16[MAX_PATH];
if( utf8_to_utf16( filename, filename_utf16 ) )
{
if( create_file )
{
/* Create the file using the Unicode filename if it doesn't already exist. */
FILE *fh = _wfopen( filename_utf16, L"ab" );
if( fh )
fclose( fh );
}
/* Check if the filename already is valid ANSI. */
if( utf16_to_ansi( filename_utf16, ansi_filename, size ) )
return 1;
/* Check for a legacy 8.3 short filename. */
int short_length = GetShortPathNameW( filename_utf16, filename_utf16, MAX_PATH );
if( short_length > 0 && short_length < MAX_PATH )
if( utf16_to_ansi( filename_utf16, ansi_filename, size ) )
return 1;
}
return 0;
}
/* Retrieve command line arguments as UTF-8. */ /* Retrieve command line arguments as UTF-8. */
static int get_argv_utf8( int *argc_ptr, char ***argv_ptr ) static int get_argv_utf8( int *argc_ptr, char ***argv_ptr )
{ {
...@@ -288,7 +262,7 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ); ...@@ -288,7 +262,7 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt );
static int encode( x264_param_t *param, cli_opt_t *opt ); static int encode( x264_param_t *param, cli_opt_t *opt );
/* logging and printing for within the cli system */ /* logging and printing for within the cli system */
static int cli_log_level; static int cli_log_level = X264_LOG_INFO;
void x264_cli_log( const char *name, int i_level, const char *fmt, ... ) void x264_cli_log( const char *name, int i_level, const char *fmt, ... )
{ {
if( i_level > cli_log_level ) if( i_level > cli_log_level )
...@@ -344,10 +318,18 @@ static void print_version_info( void ) ...@@ -344,10 +318,18 @@ static void print_version_info( void )
#endif #endif
#if HAVE_FFMS #if HAVE_FFMS
printf( "(ffmpegsource %d.%d.%d.%d)\n", FFMS_VERSION >> 24, (FFMS_VERSION & 0xff0000) >> 16, (FFMS_VERSION & 0xff00) >> 8, FFMS_VERSION & 0xff ); printf( "(ffmpegsource %d.%d.%d.%d)\n", FFMS_VERSION >> 24, (FFMS_VERSION & 0xff0000) >> 16, (FFMS_VERSION & 0xff00) >> 8, FFMS_VERSION & 0xff );
#endif
#if HAVE_GPAC
printf( "(gpac " GPAC_VERSION ")\n" );
#endif
#if HAVE_LSMASH
printf( "(lsmash %d.%d.%d)\n", LSMASH_VERSION_MAJOR, LSMASH_VERSION_MINOR, LSMASH_VERSION_MICRO );
#endif #endif
printf( "built on " __DATE__ ", " ); printf( "built on " __DATE__ ", " );
#ifdef __INTEL_COMPILER #ifdef __INTEL_COMPILER
printf( "intel: %.2f (%d)\n", __INTEL_COMPILER / 100.f, __INTEL_COMPILER_BUILD_DATE ); printf( "intel: %.2f (%d)\n", __INTEL_COMPILER / 100.f, __INTEL_COMPILER_BUILD_DATE );
#elif defined(__clang__)
printf( "clang: " __clang_version__ "\n" );
#elif defined(__GNUC__) #elif defined(__GNUC__)
printf( "gcc: " __VERSION__ "\n" ); printf( "gcc: " __VERSION__ "\n" );
#elif defined(_MSC_FULL_VER) #elif defined(_MSC_FULL_VER)
...@@ -393,6 +375,7 @@ REALIGN_STACK int main( int argc, char **argv ) ...@@ -393,6 +375,7 @@ REALIGN_STACK int main( int argc, char **argv )
_setmode( _fileno( stderr ), _O_BINARY ); _setmode( _fileno( stderr ), _O_BINARY );
#endif #endif
x264_param_default( &param );
/* Parse command line */ /* Parse command line */
if( parse( argc, argv, &param, &opt ) < 0 ) if( parse( argc, argv, &param, &opt ) < 0 )
ret = -1; ret = -1;
...@@ -419,6 +402,7 @@ REALIGN_STACK int main( int argc, char **argv ) ...@@ -419,6 +402,7 @@ REALIGN_STACK int main( int argc, char **argv )
fclose( opt.tcfile_out ); fclose( opt.tcfile_out );
if( opt.qpfile ) if( opt.qpfile )
fclose( opt.qpfile ); fclose( opt.qpfile );
x264_param_cleanup( &param );
#ifdef _WIN32 #ifdef _WIN32
SetConsoleTitleW( org_console_title ); SetConsoleTitleW( org_console_title );
...@@ -1412,16 +1396,6 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) ...@@ -1412,16 +1396,6 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
char *preset = NULL; char *preset = NULL;
char *tune = NULL; char *tune = NULL;
x264_param_default( &defaults );
cli_log_level = defaults.i_log_level;
memset( &input_opt, 0, sizeof(cli_input_opt_t) );
memset( &output_opt, 0, sizeof(cli_output_opt_t) );
input_opt.bit_depth = 8;
input_opt.input_range = input_opt.output_range = param->vui.b_fullrange = RANGE_AUTO;
int output_csp = defaults.i_csp;
opt->b_progress = 1;
/* Presets are applied before all other options. */ /* Presets are applied before all other options. */
for( optind = 0;; ) for( optind = 0;; )
{ {
...@@ -1439,9 +1413,19 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) ...@@ -1439,9 +1413,19 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
if( preset && !strcasecmp( preset, "placebo" ) ) if( preset && !strcasecmp( preset, "placebo" ) )
b_turbo = 0; b_turbo = 0;
if( x264_param_default_preset( param, preset, tune ) < 0 ) if( (preset || tune) && x264_param_default_preset( param, preset, tune ) < 0 )
return -1; return -1;
x264_param_default( &defaults );
cli_log_level = defaults.i_log_level;
memset( &input_opt, 0, sizeof(cli_input_opt_t) );
memset( &output_opt, 0, sizeof(cli_output_opt_t) );
input_opt.bit_depth = 8;
input_opt.input_range = input_opt.output_range = param->vui.b_fullrange = RANGE_AUTO;
int output_csp = defaults.i_csp;
opt->b_progress = 1;
/* Parse command line options */ /* Parse command line options */
for( optind = 0;; ) for( optind = 0;; )
{ {
......
...@@ -45,7 +45,7 @@ extern "C" { ...@@ -45,7 +45,7 @@ extern "C" {
#include "x264_config.h" #include "x264_config.h"
#define X264_BUILD 160 #define X264_BUILD 161
#ifdef _WIN32 #ifdef _WIN32
# define X264_DLL_IMPORT __declspec(dllimport) # define X264_DLL_IMPORT __declspec(dllimport)
...@@ -583,6 +583,9 @@ typedef struct x264_param_t ...@@ -583,6 +583,9 @@ typedef struct x264_param_t
* e.g. if doing multiple encodes in one process. * e.g. if doing multiple encodes in one process.
*/ */
void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque ); void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque );
/* For internal use only */
void *opaque;
} x264_param_t; } x264_param_t;
X264_API void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal ); X264_API void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
...@@ -625,11 +628,20 @@ X264_API void x264_param_default( x264_param_t * ); ...@@ -625,11 +628,20 @@ X264_API void x264_param_default( x264_param_t * );
* note: BAD_VALUE occurs only if it can't even parse the value, * note: BAD_VALUE occurs only if it can't even parse the value,
* numerical range is not checked until x264_encoder_open() or * numerical range is not checked until x264_encoder_open() or
* x264_encoder_reconfig(). * x264_encoder_reconfig().
* value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. */ * value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans.
* can allocate memory which should be freed by call of x264_param_cleanup. */
#define X264_PARAM_BAD_NAME (-1) #define X264_PARAM_BAD_NAME (-1)
#define X264_PARAM_BAD_VALUE (-2) #define X264_PARAM_BAD_VALUE (-2)
#define X264_PARAM_ALLOC_FAILED (-3)
X264_API int x264_param_parse( x264_param_t *, const char *name, const char *value ); X264_API int x264_param_parse( x264_param_t *, const char *name, const char *value );
/* x264_param_cleanup:
* Cleans up and frees allocated members of x264_param_t.
* This *does not* free the x264_param_t itself, as it may exist on the
* stack. It only frees any members of the struct that were allocated by
* x264 itself, in e.g. x264_param_parse(). */
X264_API void x264_param_cleanup( x264_param_t *param );
/**************************************************************************** /****************************************************************************
* Advanced parameter handling functions * Advanced parameter handling functions
****************************************************************************/ ****************************************************************************/
......