All pastes #1614318 Raw Edit

Stuff

public diff v1 · immutable
#1614318 ·published 2009-10-12 03:52 UTC
rendered paste body
diff --git a/configure b/configureindex d26ace1..673ec6a 100755--- a/configure+++ b/configure@@ -8,6 +8,7 @@ echo "available options:" echo "" echo "  --help                   print this message" echo "  --disable-avis-input     disables avisynth input (win32 only)"+echo "  --disable-ffms-input     disables ffmpegsource input" echo "  --disable-mp4-output     disables mp4 output (using gpac)" echo "  --disable-pthread        disables multithreaded encoding" echo "  --disable-asm            disables assembly optimizations on x86 and arm"@@ -52,6 +53,7 @@ includedir='${prefix}/include' DEVNULL='/dev/null'  avis_input="auto"+ffms_input="auto" mp4_output="auto" pthread="auto" asm="yes"@@ -101,6 +103,12 @@ for opt do         --disable-avis-input)             avis_input="no"             ;;+        --enable-ffms-input)+            ffms_input="yes"+            ;;+        --disable-ffms-input)+            ffms_input="no"+            ;;         --enable-mp4-output)             mp4_output="yes"             ;;@@ -423,6 +431,15 @@ if [ "$avis_input" = "yes" ] ; then     fi fi +if [ "$ffms_input" = "auto" ] ; then+	ffms_input="no"+	cc_check "ffms.h" "-lFFMS2" && ffms_input="yes"+fi+if [ "$ffms_input" = "yes" ] ; then+    echo "#define FFMS_INPUT" >> config.h+    LDFLAGS="$LDFLAGS -lFFMS2"+fi+ if [ "$pic" = "yes" ] ; then     CFLAGS="$CFLAGS -fPIC"     ASFLAGS="$ASFLAGS -DPIC"@@ -478,6 +495,7 @@ EXE=$EXE VIS=$vis HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG DEVNULL=$DEVNULL+FFMS=$ffms_input EOF  if [ "$shared" = "yes" ]; then@@ -524,6 +542,7 @@ echo "Platform:   $ARCH" echo "System:     $SYS" echo "asm:        $asm" echo "avis input: $avis_input"+echo "ffms input: $ffms_input" echo "mp4 output: $mp4_output" echo "pthread:    $pthread" echo "debug:      $debug"diff --git a/muxers.c b/muxers.cindex c9b8dfa..aa85d64 100644--- a/muxers.c+++ b/muxers.c@@ -38,6 +38,10 @@ #include <gpac/isomedia.h> #endif +#ifdef FFMS_INPUT+#include "ffms.h"+#endif+ static int64_t gcd( int64_t a, int64_t b ) {     while( 1 )@@ -328,6 +332,68 @@ int close_file_y4m(hnd_t handle)     return 0; } +/* ffmpegsource input file support */++#ifdef FFMS_INPUT+typedef struct+{+    FFMS_VideoSource *video_source;+    int total_frames;+} ffms_input_t;++int open_file_ffms( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )+{    +    ffms_input_t *h = malloc( sizeof(ffms_input_t) );+    *p_handle = (hnd_t)h;+    FFMS_Init( 0 );+    FFMS_ErrorInfo e;+    FFMS_Index *index = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, NULL, NULL, &e );+    int trackno = FFMS_GetFirstTrackOfType( index, FFMS_TYPE_VIDEO, &e );+    h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, index, 1, FFMS_SEEK_NORMAL, &e );+    FFMS_DestroyIndex( index );+    FFMS_VideoProperties *videop = FFMS_GetVideoProperties( h->video_source );+    h->total_frames = videop->NumFrames;+    // int64_t pixfmt = (int64_t)1 << FFMS_GetPixFmt("yuv420p");+    const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, 0, &e );+    // FFMS_SetOutputFormatV( h->video_source, pixfmt, frame->EncodedWidth, frame->EncodedHeight, FFMS_RESIZER_BICUBIC, &e );+    p_param->i_width = frame->EncodedWidth;+    p_param->i_height = frame->EncodedHeight;+    p_param->i_fps_den = videop->FPSDenominator;+    p_param->i_fps_num = videop->FPSNumerator;+    p_param->vui.i_sar_height = videop->SARDen;+    p_param->vui.i_sar_width = videop->SARNum;+    return 0;+}++int get_frame_total_ffms( hnd_t handle )+{+    return ((ffms_input_t *)handle)->total_frames;+}++int read_frame_ffms( x264_picture_t *p_pic, hnd_t handle, int i_frame )+{+    ffms_input_t *h = handle;+    FFMS_ErrorInfo e;+    e.BufferSize = 0;+    FFMS_Frame *frame = FFMS_GetFrame( h->video_source, i_frame, &e );+    int i;+    for( i = 0; i < 3; i ++ )+    {+        p_pic->img.plane[i] = frame->Data[i];+        p_pic->img.i_stride[i] = frame->Linesize[i];+    }+    return 0;+}++int close_file_ffms( hnd_t handle )+{+    ffms_input_t *h = handle;+    FFMS_DestroyVideoSource( h->video_source );+    free( h );+    return 0;+}+#endif+ /* avs/avi input file support under cygwin */  #ifdef AVIS_INPUT@@ -523,7 +589,10 @@ int close_file_thread( hnd_t handle )     if( h->in_progress )         x264_pthread_join( h->tid, NULL );     h->p_close_infile( h->p_handle );-    x264_picture_clean( &h->pic );+#ifdef FFMS_INPUT+    if( h->p_read_frame != read_frame_ffms )+#endif+        x264_picture_clean( &h->pic );     free( h->next_args );     free( h );     return 0;@@ -1045,4 +1114,3 @@ int close_file_mkv( hnd_t handle )      return ret; }-diff --git a/muxers.h b/muxers.hindex aaede1c..1ed60a8 100644--- a/muxers.h+++ b/muxers.h@@ -36,6 +36,11 @@ int get_frame_total_y4m( hnd_t handle ); int read_frame_y4m( x264_picture_t *p_pic, hnd_t handle, int i_frame ); int close_file_y4m( hnd_t handle ); +int open_file_ffms( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param );+int get_frame_total_ffms( hnd_t handle );+int read_frame_ffms( x264_picture_t *p_pic, hnd_t handle, int i_frame );+int close_file_ffms( hnd_t handle );+ int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); int get_frame_total_avis( hnd_t handle ); int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame );diff --git a/x264.c b/x264.cindex ab76a93..a1e8df4 100644--- a/x264.c+++ b/x264.c@@ -40,6 +40,10 @@ #define SetConsoleTitle(t) #endif +#ifdef FFMS_INPUT+#include "ffms_input.h"+#endif+ uint8_t *mux_buffer = NULL; int mux_buffer_size = 0; @@ -59,6 +63,9 @@ typedef struct {     hnd_t hin;     hnd_t hout;     FILE *qpfile;+#ifdef FFMS_INPUT+    int b_ffms;+#endif } cli_opt_t;  /* input file operation function pointers */@@ -399,6 +406,7 @@ static void Help( x264_param_t *defaults, int longhelp ) #define OPT_SLOWFIRSTPASS 267 #define OPT_FULLHELP 268 #define OPT_FPS 269+#define OPT_FFMS_INPUT 270  static char short_options[] = "8A:B:b:f:hI:i:m:o:p:q:r:t:Vvw"; static struct option long_options[] =@@ -522,6 +530,7 @@ static struct option long_options[] =     { "transfer",    required_argument, NULL, 0 },     { "colormatrix", required_argument, NULL, 0 },     { "chromaloc",   required_argument, NULL, 0 },+    { "ffms-input",        no_argument, NULL, OPT_FFMS_INPUT },     {0, 0, 0, 0} }; @@ -537,6 +546,7 @@ static int  Parse( int argc, char **argv,     char *profile = NULL;     int b_avis = 0;     int b_y4m = 0;+    int b_ffms = 0;     int b_thread_input = 0;     int b_turbo = 1;     int b_pass1 = 0;@@ -845,6 +855,9 @@ static int  Parse( int argc, char **argv,                 fprintf( stderr, "x264 [warning]: not compiled with visualization support\n" ); #endif                 break;+            case OPT_FFMS_INPUT:+                b_ffms = 1;+                break;             case OPT_TUNE:             case OPT_PRESET:                 break;@@ -960,7 +973,7 @@ generic_option:     if( !strncasecmp( psz, ".y4m", 4 ) )         b_y4m = 1; -    if( !(b_avis || b_y4m) ) // raw yuv+    if( !(b_avis || b_y4m || b_ffms) ) // raw yuv     {         if( optind > argc - 1 )         {@@ -984,7 +997,7 @@ generic_option:         }     } -    if( !(b_avis || b_y4m) && ( !param->i_width || !param->i_height ) )+    if( !(b_avis || b_y4m || b_ffms) && ( !param->i_width || !param->i_height ) )     {         fprintf( stderr, "x264 [error]: Rawyuv input requires a resolution.\n" );         return -1;@@ -1013,6 +1026,19 @@ generic_option:             p_read_frame = read_frame_y4m;             p_close_infile = close_file_y4m;         }+#ifdef FFMS_INPUT+        if( b_ffms )+        {+            opt->b_ffms = 1;+            p_open_infile = open_file_ffms;+            p_get_frame_total = get_frame_total_ffms;+            p_read_frame = read_frame_ffms;+            p_close_infile = close_file_ffms;+        }+#else+        fprintf( stderr, "x264 [error]: not compiled with FFMS input support\n" );+        return -1;+#endif          if( p_open_infile( psz_filename, &opt->hin, param ) )         {@@ -1168,6 +1194,10 @@ static int  Encode( x264_param_t *param, cli_opt_t *opt )     int64_t i_file;     int     i_frame_size;     int     i_update_interval;+    int     b_ffms = 0;+#ifdef FFMS_INPUT+    b_ffms = opt->b_ffms;+#endif      opt->b_progress &= param->i_log_level < X264_LOG_DEBUG;     i_frame_total = p_get_frame_total( opt->hin );@@ -1246,7 +1276,8 @@ static int  Encode( x264_param_t *param, cli_opt_t *opt )     }      i_end = x264_mdate();-    x264_picture_clean( &pic );+    if( !b_ffms )+        x264_picture_clean( &pic );     /* Erase progress indicator before printing encoding stats. */     if( opt->b_progress )         fprintf( stderr, "                                                                               \r" );