[x264-devel] [Git][videolan/x264][stable] 9 commits: lavf: Update to the new API for iterating demuxers

Anton Mitrofanov gitlab at videolan.org
Sun Oct 25 18:49:50 CET 2020



Anton Mitrofanov pushed to branch stable at VideoLAN / x264


Commits:
2e3caed2 by Henrik Gramner at 2020-07-02T19:08:51+02:00
lavf: Update to the new API for iterating demuxers

- - - - -
a41d4e29 by Henrik Gramner at 2020-07-02T19:20:21+02:00
cli: Install bash autocomplete during 'make install'

- - - - -
7c2004b5 by A. David at 2020-07-02T19:45:50+02:00
mp4: Update GPAC support to v0.8.0 or later

- - - - -
4c2aafd8 by Anton Mitrofanov at 2020-07-02T22:23:50+02:00
Add new API function: x264_param_cleanup

Should be called to free struct members allocated internally by libx264,
e.g. by x264_param_parse.
Partially based on videolan/x264!18 by Derek Buitenhuis.

- - - - -
375cc588 by Anton Mitrofanov at 2020-07-14T15:35:11+02:00
configure: Add options for bash-completion install

- - - - -
45e2f899 by Anton Mitrofanov at 2020-07-14T15:35:32+02:00
cli: Add info about gpac/lsmash into version info

- - - - -
db0d4177 by Anton Mitrofanov at 2020-07-14T15:45:40+02:00
Rename function x264_strdup to x264_param_strdup

- - - - -
2726e45d by Henrik Gramner at 2020-09-12T19:23:55+02:00
mp4: Fix compiling with recent GPAC versions

- - - - -
d198931a by Henrik Gramner at 2020-09-12T19:23:57+02:00
mp4: Remove GPAC Windows Unicode compatibility shim

GPAC has native UTF-8 support nowadays.

Also move the compatibility code to input/avs.c since that's the only
remaining code that uses it now.

- - - - -


13 changed files:

- Makefile
- autocomplete.c
- common/base.c
- common/base.h
- common/frame.c
- configure
- encoder/encoder.c
- encoder/ratecontrol.c
- input/avs.c
- input/lavf.c
- output/mp4.c
- x264.c
- x264.h


Changes:

=====================================
Makefile
=====================================
@@ -410,6 +410,12 @@ else ifneq ($(SONAME),)
 	$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(libdir)
 endif
 
+install-bashcompletion:
+ifneq ($(BASHCOMPLETIONSDIR),)
+	$(INSTALL) -d $(DESTDIR)$(BASHCOMPLETIONSDIR)
+	$(INSTALL) -m 644 -T $(SRCPATH)/tools/bash-autocomplete.sh $(DESTDIR)$(BASHCOMPLETIONSDIR)/x264
+endif
+
 uninstall:
 	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
@@ -418,6 +424,9 @@ ifneq ($(IMPLIBNAME),)
 else ifneq ($(SONAME),)
 	rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)
 endif
+ifneq ($(BASHCOMPLETIONSDIR),)
+	rm -f $(DESTDIR)$(BASHCOMPLETIONSDIR)/x264
+endif
 
 etags TAGS:
 	etags $(SRCS) $(SRCS_X) $(SRCS_8)


=====================================
autocomplete.c
=====================================
@@ -331,8 +331,8 @@ int x264_cli_autocomplete( const char *prev, const char *cur )
     OPT( "--input-fmt" )
     {
 #if HAVE_LAVF
-        av_register_all();
-        for( const AVInputFormat *f = NULL; (f = av_iformat_next( f )); )
+        void *i = NULL;
+        for( const AVInputFormat *f; (f = av_demuxer_iterate( &i )); )
             suggest_token( f->name, ',' );
 #endif
     }


=====================================
common/base.c
=====================================
@@ -198,6 +198,66 @@ error:
     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:
  ****************************************************************************/
@@ -811,6 +871,15 @@ static double atof_internal( const char *str, int *b_error )
 #undef atof
 #define atoi(str) atoi_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 )
 {
@@ -833,7 +902,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
         char *c;
         name_buf = strdup(name);
         if( !name_buf )
-            return X264_PARAM_BAD_NAME;
+            return X264_PARAM_ALLOC_FAILED;
         while( (c = strchr( name_buf, '_' )) )
             *c = '-';
         name = name_buf;
@@ -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) )
                     p->cpu |= X264_CPU_SSE2_IS_FAST;
             }
+            else
+                errortype = X264_PARAM_ALLOC_FAILED;
         }
     }
     OPT("threads")
@@ -1062,10 +1133,10 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
         else if( strstr( value, "jvt" ) )
             p->i_cqm_preset = X264_CQM_JVT;
         else
-            p->psz_cqm_file = strdup(value);
+            CHECKED_ERROR_PARAM_STRDUP( p->psz_cqm_file, p, value );
     }
     OPT("cqmfile")
-        p->psz_cqm_file = strdup(value);
+        CHECKED_ERROR_PARAM_STRDUP( p->psz_cqm_file, p, value );
     OPT("cqm4")
     {
         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
     OPT("log")
         p->i_log_level = atoi(value);
     OPT("dump-yuv")
-        p->psz_dump_yuv = strdup(value);
+        CHECKED_ERROR_PARAM_STRDUP( p->psz_dump_yuv, p, value );
     OPT2("analyse", "partitions")
     {
         p->analyse.inter = 0;
@@ -1245,8 +1316,8 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
     }
     OPT("stats")
     {
-        p->rc.psz_stat_in = strdup(value);
-        p->rc.psz_stat_out = strdup(value);
+        CHECKED_ERROR_PARAM_STRDUP( p->rc.psz_stat_in, p, value );
+        CHECKED_ERROR_PARAM_STRDUP( p->rc.psz_stat_out, p, value );
     }
     OPT("qcomp")
         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
     OPT2("cplxblur", "cplx-blur")
         p->rc.f_complexity_blur = atof(value);
     OPT("zones")
-        p->rc.psz_zones = strdup(value);
+        CHECKED_ERROR_PARAM_STRDUP( p->rc.psz_zones, p, value );
     OPT("crop-rect")
         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;
@@ -1292,7 +1363,7 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
     OPT("opencl")
         p->b_opencl = atobool( value );
     OPT("opencl-clbin")
-        p->psz_clbin_file = strdup( value );
+        CHECKED_ERROR_PARAM_STRDUP( p->psz_clbin_file, p, value );
     OPT("opencl-device")
         p->i_opencl_device = atoi( value );
     else


=====================================
common/base.h
=====================================
@@ -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_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 */
 X264_API void *x264_malloc( int64_t );
 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_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
  * the encoding options */
 X264_API char *x264_param2string( x264_param_t *p, int b_res );
@@ -287,6 +291,12 @@ do {\
     CHECKED_MALLOC( var, size );\
     memset( var, 0, size );\
 } 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
  * use with huge pages. */


=====================================
common/frame.c
=====================================
@@ -318,7 +318,10 @@ void x264_frame_delete( x264_frame_t *frame )
         x264_free( frame->base );
 
         if( frame->param && frame->param->param_free )
+        {
+            x264_param_cleanup( frame->param );
             frame->param->param_free( frame->param );
+        }
         if( frame->mb_info_free )
             frame->mb_info_free( frame->mb_info );
         if( frame->extra_sei.sei_free )


=====================================
configure
=====================================
@@ -25,6 +25,9 @@ Configuration options:
   --system-libx264         use system libx264 instead of internal
   --enable-shared          build shared 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-gpl            disable GPL-only features
   --disable-thread         disable multithreaded encoding
@@ -363,6 +366,8 @@ cli="yes"
 cli_libx264="internal"
 shared="no"
 static="no"
+bashcompletion="auto"
+bashcompletionsdir=""
 avs="auto"
 lavf="auto"
 ffms="auto"
@@ -439,6 +444,15 @@ for opt do
         --enable-static)
             static="yes"
             ;;
+        --disable-bashcompletion)
+            bashcompletion="no"
+            ;;
+        --enable-bashcompletion)
+            bashcompletion="yes"
+            ;;
+        --bashcompletionsdir=*)
+            bashcompletionsdir="$optarg"
+            ;;
         --disable-asm)
             asm="no"
             ;;
@@ -1154,7 +1168,7 @@ if [ "$lavf" = "auto" ] ; then
         done
     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
             lavf="yes"
         else
@@ -1232,15 +1246,16 @@ if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then
     gpac="no"
     GPAC_LIBS="-lgpac_static"
     cc_check "" -lz && GPAC_LIBS="$GPAC_LIBS -lz"
+    cc_check "" -ldl && GPAC_LIBS="$GPAC_LIBS -ldl"
     if [ "$SYS" = "WINDOWS" ] ; then
         cc_check "" -lws2_32 && GPAC_LIBS="$GPAC_LIBS -lws2_32"
         cc_check "" -lwinmm && GPAC_LIBS="$GPAC_LIBS -lwinmm"
     fi
     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"
         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
@@ -1563,6 +1578,27 @@ if [ "$static" = "yes" ]; then
     echo 'install: install-lib-static' >> config.mak
 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
 prefix=$prefix
 exec_prefix=$exec_prefix
@@ -1581,30 +1617,31 @@ filters="crop select_every"
 [ $swscale = yes ] && filters="resize $filters"
 
 cat > conftest.log <<EOF
-platform:      $ARCH
-byte order:    $CPU_ENDIAN
-system:        $SYS
-cli:           $cli
-libx264:       $cli_libx264
-shared:        $shared
-static:        $static
-asm:           $asm
-interlaced:    $interlaced
-avs:           $avs
-lavf:          $lavf
-ffms:          $ffms
-mp4:           $mp4
-gpl:           $gpl
-thread:        $thread
-opencl:        $opencl
-filters:       $filters
-lto:           $lto
-debug:         $debug
-gprof:         $gprof
-strip:         $strip
-PIC:           $pic
-bit depth:     $bit_depth
-chroma format: $chroma_format
+platform:       $ARCH
+byte order:     $CPU_ENDIAN
+system:         $SYS
+cli:            $cli
+libx264:        $cli_libx264
+shared:         $shared
+static:         $static
+bashcompletion: $bashcompletion
+asm:            $asm
+interlaced:     $interlaced
+avs:            $avs
+lavf:           $lavf
+ffms:           $ffms
+mp4:            $mp4
+gpl:            $gpl
+thread:         $thread
+opencl:         $opencl
+filters:        $filters
+lto:            $lto
+debug:          $debug
+gprof:          $gprof
+strip:          $strip
+PIC:            $pic
+bit depth:      $bit_depth
+chroma format:  $chroma_format
 EOF
 
 echo >> config.log


=====================================
encoder/encoder.c
=====================================
@@ -1460,9 +1460,27 @@ x264_t *x264_encoder_open( x264_param_t *param )
 
     /* Create a copy of param */
     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 )
+    {
+        x264_param_cleanup( param );
         param->param_free( param );
+    }
 
 #if HAVE_INTEL_DISPATCHER
     x264_intel_dispatcher_override();
@@ -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 )
             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_timebase_num, &h->param.i_timebase_den );
 
@@ -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 )
 {
     memcpy( param, &h->thread[h->i_thread_phase]->param, sizeof(x264_param_t) );
+    param->opaque = NULL;
 }
 
 /* internal usage */
@@ -3395,6 +3409,7 @@ int     x264_encoder_encode( x264_t *h,
         x264_encoder_reconfig_apply( h, h->fenc->param );
         if( h->fenc->param->param_free )
         {
+            x264_param_cleanup( h->fenc->param );
             h->fenc->param->param_free( h->fenc->param );
             h->fenc->param = NULL;
         }
@@ -4418,10 +4433,7 @@ void    x264_encoder_close  ( x264_t *h )
     x264_ratecontrol_delete( h );
 
     /* param */
-    if( h->param.rc.psz_stat_out )
-        free( h->param.rc.psz_stat_out );
-    if( h->param.rc.psz_stat_in )
-        free( h->param.rc.psz_stat_in );
+    x264_param_cleanup( &h->param );
 
     x264_cqm_delete( h );
     x264_free( h->nal_buffer );


=====================================
encoder/ratecontrol.c
=====================================
@@ -1237,6 +1237,7 @@ static int parse_zone( x264_t *h, x264_zone_t *z, char *p )
         return 0;
     CHECKED_MALLOC( z->param, sizeof(x264_param_t) );
     memcpy( z->param, &h->param, sizeof(x264_param_t) );
+    z->param->opaque = NULL;
     z->param->param_free = x264_free;
     while( (tok = strtok_r( p, ",", &saveptr )) )
     {
@@ -1315,6 +1316,7 @@ static int parse_zones( x264_t *h )
         rc->zones[0].f_bitrate_factor = 1;
         CHECKED_MALLOC( rc->zones[0].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++ )
         {
             if( !rc->zones[i].param )
@@ -1391,10 +1393,14 @@ void x264_ratecontrol_delete( x264_t *h )
     macroblock_tree_rescale_destroy( rc );
     if( rc->zones )
     {
+        x264_param_cleanup( rc->zones[0].param );
         x264_free( rc->zones[0].param );
         for( int i = 1; i < rc->i_zones; i++ )
             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 );
+            }
         x264_free( rc->zones );
     }
     x264_free( rc );


=====================================
input/avs.c
=====================================
@@ -253,6 +253,32 @@ static float get_avs_version( avs_hnd_t *h )
 #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 )
 {
     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
 #ifdef _WIN32
     /* Avisynth doesn't support Unicode filenames. */
     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 );
 #else
     AVS_Value arg = avs_new_value_string( psz_filename );


=====================================
input/lavf.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) );
     if( !h )
         return -1;
-    av_register_all();
     if( !strcmp( psz_filename, "-" ) )
         psz_filename = "pipe:";
 


=====================================
output/mp4.c
=====================================
@@ -27,10 +27,6 @@
 #include "output.h"
 #include <gpac/isomedia.h>
 
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
 typedef struct
 {
     GF_ISOFile *p_file;
@@ -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 );
                 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 );
+#endif
             }
             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
     if( !p_mp4 )
         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 );
-#endif
-
     p_mp4->b_dts_compress = opt->use_dts_compress;
 
     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 )
             dw *= sar;
         else
             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 );
     }
 


=====================================
x264.c
=====================================
@@ -65,6 +65,14 @@
 #include <ffms.h>
 #endif
 
+#if HAVE_GPAC
+#include <gpac/version.h>
+#endif
+
+#if HAVE_LSMASH
+#include <lsmash.h>
+#endif
+
 #ifdef _WIN32
 #define CONSOLE_TITLE_SIZE 200
 static wchar_t org_console_title[CONSOLE_TITLE_SIZE] = L"";
@@ -76,40 +84,6 @@ void x264_cli_set_console_title( const char *title )
         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. */
 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 );
 static int  encode( x264_param_t *param, cli_opt_t *opt );
 
 /* 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, ... )
 {
     if( i_level > cli_log_level )
@@ -344,10 +318,18 @@ static void print_version_info( void )
 #endif
 #if HAVE_FFMS
     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
     printf( "built on " __DATE__ ", " );
 #ifdef __INTEL_COMPILER
     printf( "intel: %.2f (%d)\n", __INTEL_COMPILER / 100.f, __INTEL_COMPILER_BUILD_DATE );
+#elif defined(__clang__)
+    printf( "clang: " __clang_version__ "\n" );
 #elif defined(__GNUC__)
     printf( "gcc: " __VERSION__ "\n" );
 #elif defined(_MSC_FULL_VER)
@@ -393,6 +375,7 @@ REALIGN_STACK int main( int argc, char **argv )
     _setmode( _fileno( stderr ), _O_BINARY );
 #endif
 
+    x264_param_default( &param );
     /* Parse command line */
     if( parse( argc, argv, &param, &opt ) < 0 )
         ret = -1;
@@ -419,6 +402,7 @@ REALIGN_STACK int main( int argc, char **argv )
         fclose( opt.tcfile_out );
     if( opt.qpfile )
         fclose( opt.qpfile );
+    x264_param_cleanup( &param );
 
 #ifdef _WIN32
     SetConsoleTitleW( org_console_title );
@@ -1412,16 +1396,6 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
     char *preset = 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. */
     for( optind = 0;; )
     {
@@ -1439,9 +1413,19 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
     if( preset && !strcasecmp( preset, "placebo" ) )
         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;
 
+    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 */
     for( optind = 0;; )
     {


=====================================
x264.h
=====================================
@@ -45,7 +45,7 @@ extern "C" {
 
 #include "x264_config.h"
 
-#define X264_BUILD 160
+#define X264_BUILD 161
 
 #ifdef _WIN32
 #   define X264_DLL_IMPORT __declspec(dllimport)
@@ -583,6 +583,9 @@ typedef struct x264_param_t
      * e.g. if doing multiple encodes in one process.
      */
     void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque );
+
+    /* For internal use only */
+    void *opaque;
 } x264_param_t;
 
 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 * );
  *  note: BAD_VALUE occurs only if it can't even parse the value,
  *  numerical range is not checked until x264_encoder_open() or
  *  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_VALUE (-2)
+#define X264_PARAM_ALLOC_FAILED (-3)
 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
  ****************************************************************************/



View it on GitLab: https://code.videolan.org/videolan/x264/-/compare/cde9a93319bea766a92e306d69059c76de970190...d198931a63049db1f2c92d96c34904c69fde8117

-- 
View it on GitLab: https://code.videolan.org/videolan/x264/-/compare/cde9a93319bea766a92e306d69059c76de970190...d198931a63049db1f2c92d96c34904c69fde8117
You're receiving this email because of your account on code.videolan.org.




More information about the x264-devel mailing list