/* CPU autodetect */
param->cpu = x264_cpu_detect();
+ param->i_threads = 1;
/* Video properties */
param->i_csp = X264_CSP_I420;
int i_type;
int i_first_mb;
+ int i_last_mb;
int i_pps_id;
*/
#define X264_BFRAME_MAX 16
+#define X264_SLICE_MAX 4
+#define X264_NAL_MAX (4 + X264_SLICE_MAX)
typedef struct x264_ratecontrol_t x264_ratecontrol_t;
typedef struct x264_vlc_table_t x264_vlc_table_t;
/* encoder parameters */
x264_param_t param;
+ x264_t *thread[X264_SLICE_MAX];
+
/* bitstream output */
struct
{
int i_nal;
- x264_nal_t nal[5]; /* for now 5 is enough */
+ x264_nal_t nal[X264_NAL_MAX];
int i_bitstream; /* size of p_bitstream */
uint8_t *p_bitstream; /* will hold data for all nal */
bs_t bs;
int i_poc_lsb; /* decoding only */
int i_poc; /* decoding only */
+ int i_thread_num; /* threads only */
+ int i_nal_type; /* threads only */
+ int i_nal_ref_idc; /* threads only */
+
/* We use only one SPS and one PPS */
x264_sps_t sps_array[32];
x264_sps_t *sps;
int mv_min_fpel[2];
int mv_max_fpel[2];
+ /* neighboring MBs */
unsigned int i_neighbour;
+ int i_mb_type_top;
+ int i_mb_type_left;
/* mb table */
int8_t *type; /* mb type */
}
/* spatial */
- if( h->mb.i_mb_x > 0 )
+ if( h->mb.i_neighbour & MB_LEFT )
{
int i_mb_l = h->mb.i_mb_xy - 1;
/* skip MBs didn't go through the whole search process, so mvr is undefined */
i++;
}
}
- if( h->mb.i_mb_y > 0 )
+ if( h->mb.i_neighbour & MB_TOP )
{
int i_mb_t = h->mb.i_mb_xy - h->mb.i_mb_stride;
if( !IS_SKIP( h->mb.type[i_mb_t] ) )
i++;
}
- if( h->mb.i_mb_x > 0 && !IS_SKIP( h->mb.type[i_mb_t - 1] ) )
+ if( h->mb.i_neighbour & MB_TOPLEFT && !IS_SKIP( h->mb.type[i_mb_t - 1] ) )
{
mvc[i][0] = mvr[i_mb_t - 1][0];
mvc[i][1] = mvr[i_mb_t - 1][1];
h->mb.pic.i_stride[i] = i_stride;
h->mb.pic.p_fenc[i] = &h->fenc->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
-
h->mb.pic.p_fdec[i] = &h->fdec->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
for( j = 0; j < h->i_ref0; j++ )
}
/* load cache */
- if( i_mb_y > 0 )
+ if( h->mb.i_mb_xy >= h->sh.i_first_mb + h->mb.i_mb_stride )
{
i_top_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ h->mb.i_mb_type_top =
i_top_type= h->mb.type[i_top_xy];
h->mb.i_neighbour |= MB_TOP;
}
else
{
+ h->mb.i_mb_type_top = -1;
+
/* load intra4x4 */
h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] =
h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] =
}
- if( i_mb_x > 0 )
+ if( i_mb_x > 0 && h->mb.i_mb_xy > h->sh.i_first_mb )
{
i_left_xy = h->mb.i_mb_xy - 1;
+ h->mb.i_mb_type_left =
i_left_type= h->mb.type[i_left_xy];
h->mb.i_neighbour |= MB_LEFT;
}
else
{
+ h->mb.i_mb_type_left = -1;
+
h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] =
h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] =
h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] =
h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = 0x80;
}
- if( i_mb_y > 0 && i_mb_x < h->sps->i_mb_width - 1 )
- {
+ if( i_mb_x < h->sps->i_mb_width - 1 && h->mb.i_mb_xy >= h->sh.i_first_mb + h->mb.i_mb_stride - 1 )
h->mb.i_neighbour |= MB_TOPRIGHT;
- }
+ if( i_mb_x > 0 && h->mb.i_mb_xy >= h->sh.i_first_mb + h->mb.i_mb_stride + 1 )
+ h->mb.i_neighbour |= MB_TOPLEFT;
/* load ref/mv/mvd */
if( h->sh.i_type != SLICE_TYPE_I )
const int s8x8 = h->mb.i_b8_stride;
const int s4x4 = h->mb.i_b4_stride;
- int i_top_left_xy = -1;
- int i_top_right_xy = -1;
-
int i_list;
- if( h->mb.i_mb_y > 0 && h->mb.i_mb_x > 0 )
- {
- i_top_left_xy = i_top_xy - 1;
- }
- if( h->mb.i_mb_y > 0 && h->mb.i_mb_x < h->sps->i_mb_width - 1 )
- {
- i_top_right_xy = i_top_xy + 1;
- }
-
for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2 : 1 ); i_list++ )
{
/*
h->mb.cache.ref[i_list][x264_scan8[13]+1] = -2;
*/
- if( i_top_left_xy >= 0 )
+ if( h->mb.i_neighbour & MB_TOPLEFT )
{
const int i8 = x264_scan8[0] - 1 - 1*8;
const int ir = i_mb_8x8 - s8x8 - 1;
}
}
- if( i_top_right_xy >= 0 )
+ if( h->mb.i_neighbour & MB_TOPRIGHT )
{
const int i8 = x264_scan8[0] + 4 - 1*8;
const int ir = i_mb_8x8 - s8x8 + 2;
MB_LEFT = 0x01,
MB_TOP = 0x02,
MB_TOPRIGHT = 0x04,
+ MB_TOPLEFT = 0x08,
MB_PRIVATE = 0x10,
};
echo " --enable-avis-input enables avisynth input (win32 only)"
echo " --enable-mp4-output enables mp4 output (using gpac)"
echo " --enable-vfw compiles the VfW frontend"
+echo " --enable-pthread enables multithreaded encoding"
echo " --enable-debug adds -g, doesn't strip"
echo " --enable-visualize enables visualization (X11 only)"
echo " --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS"
avis_input="no"
mp4_output="no"
+pthread="no"
debug="no"
vfw="no"
vis="no"
LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
VFW_LDFLAGS="${opt#--extra-ldflags=}"
;;
+ --enable-pthread)
+ CFLAGS="$CFLAGS -DHAVE_PTHREAD=1"
+ pthread="yes"
+ if [ $SYS = MINGW ]; then
+ LDFLAGS="$LDFLAGS -lpthreadGC2"
+ else
+ LDFLAGS="$LDFLAGS -lpthread"
+ fi
+ ;;
--enable-debug)
CFLAGS="$CFLAGS -g"
debug="yes"
echo "System: $SYS"
echo "avis input: $avis_input"
echo "mp4 output: $mp4_output"
+echo "pthread: $pthread"
echo "vfw: $vfw"
echo "debug: $debug"
echo "visualize: $vis"
}
/* Fast intra decision */
- if( h->mb.i_mb_xy > 4 )
+ if( h->mb.i_mb_xy - h->sh.i_first_mb > 4 )
{
const unsigned int i_neighbour = h->mb.i_neighbour;
if( ((i_neighbour&MB_LEFT) && IS_INTRA( h->mb.type[h->mb.i_mb_xy - 1] ))
|| (((i_neighbour&(MB_TOP|MB_LEFT)) == (MB_TOP|MB_LEFT)) && IS_INTRA( h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride-1 ] ))
|| ((i_neighbour&MB_TOPRIGHT) && IS_INTRA( h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride+1 ] ))
|| (h->sh.i_type == SLICE_TYPE_P && IS_INTRA( h->fref0[0]->mb_type[h->mb.i_mb_xy] ))
- || (h->mb.i_mb_xy < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_16x16])) )
+ || (h->mb.i_mb_xy - h->sh.i_first_mb < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_16x16])) )
{ /* intra is likely */ }
else
{
if( h->sh.i_type == SLICE_TYPE_I )
{
int ctx = 0;
- if( h->mb.i_mb_x > 0 && h->mb.type[h->mb.i_mb_xy - 1] != I_4x4 )
+ if( h->mb.i_mb_type_left >= 0 && h->mb.i_mb_type_left != I_4x4 )
{
ctx++;
}
- if( h->mb.i_mb_y > 0 && h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride] != I_4x4 )
+ if( h->mb.i_mb_type_top >= 0 && h->mb.i_mb_type_top != I_4x4 )
{
ctx++;
}
else if( h->sh.i_type == SLICE_TYPE_B )
{
int ctx = 0;
- if( h->mb.i_mb_x > 0 && h->mb.type[h->mb.i_mb_xy - 1] != B_SKIP && h->mb.type[h->mb.i_mb_xy - 1] != B_DIRECT )
+ if( h->mb.i_mb_type_left >= 0 && h->mb.i_mb_type_left != B_SKIP && h->mb.i_mb_type_left != B_DIRECT )
{
ctx++;
}
- if( h->mb.i_mb_y > 0 && h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride] != B_SKIP && h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride] != B_DIRECT )
+ if( h->mb.i_mb_type_top >= 0 && h->mb.i_mb_type_top != B_SKIP && h->mb.i_mb_type_top != B_DIRECT )
{
ctx++;
}
int ctx = 0;
/* No need to test for I4x4 or I_16x16 as cache_save handle that */
- if( h->mb.i_mb_x > 0 && h->mb.chroma_pred_mode[h->mb.i_mb_xy - 1] != 0 )
+ if( (h->mb.i_neighbour & MB_LEFT) && h->mb.chroma_pred_mode[h->mb.i_mb_xy - 1] != 0 )
{
ctx++;
}
- if( h->mb.i_mb_y > 0 && h->mb.chroma_pred_mode[h->mb.i_mb_xy - h->mb.i_mb_stride] != 0 )
+ if( (h->mb.i_neighbour & MB_TOP) && h->mb.chroma_pred_mode[h->mb.i_mb_xy - h->mb.i_mb_stride] != 0 )
{
ctx++;
}
if( x > 0 )
i_mba_xy = h->mb.i_mb_xy;
- else if( h->mb.i_mb_x > 0 )
+ else if( h->mb.i_neighbour & MB_LEFT )
i_mba_xy = h->mb.i_mb_xy - 1;
if( y > 0 )
i_mbb_xy = h->mb.i_mb_xy;
- else if( h->mb.i_mb_y > 0 )
+ else if( h->mb.i_neighbour & MB_TOP )
i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
int ctx;
/* No need to test for SKIP/PCM */
- if( h->mb.i_mb_x > 0 )
+ if( h->mb.i_neighbour & MB_LEFT )
{
cbp_a = (h->mb.cbp[h->mb.i_mb_xy - 1] >> 4)&0x3;
}
- if( h->mb.i_mb_y > 0 )
+ if( h->mb.i_neighbour & MB_TOP )
{
cbp_b = (h->mb.cbp[h->mb.i_mb_xy - h->mb.i_mb_stride] >> 4)&0x3;
}
int ctx;
/* No need to test for PCM / SKIP */
- if( i_mbn_xy >= 0 && h->mb.i_last_dqp != 0 &&
+ if( i_mbn_xy >= h->sh.i_first_mb && h->mb.i_last_dqp != 0 &&
( h->mb.type[i_mbn_xy] == I_16x16 || (h->mb.cbp[i_mbn_xy]&0x3f) ) )
ctx = 1;
else
{
int ctx = 0;
- if( h->mb.i_mb_x > 0 && !IS_SKIP( h->mb.type[h->mb.i_mb_xy -1]) )
+ if( h->mb.i_mb_type_left >= 0 && !IS_SKIP( h->mb.i_mb_type_left ) )
{
ctx++;
}
- if( h->mb.i_mb_y > 0 && !IS_SKIP( h->mb.type[h->mb.i_mb_xy -h->mb.i_mb_stride]) )
+ if( h->mb.i_mb_type_top >= 0 && !IS_SKIP( h->mb.i_mb_type_top ) )
{
ctx++;
}
if( i_cat == 0 )
{
- if( h->mb.i_mb_x > 0 )
+ if( h->mb.i_neighbour & MB_LEFT )
{
i_mba_xy = h->mb.i_mb_xy -1;
if( h->mb.type[i_mba_xy] == I_16x16 )
i_nza = h->mb.cbp[i_mba_xy]&0x100;
}
}
- if( h->mb.i_mb_y > 0 )
+ if( h->mb.i_neighbour & MB_TOP )
{
i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
if( h->mb.type[i_mbb_xy] == I_16x16 )
if( x > 0 )
i_mba_xy = h->mb.i_mb_xy;
- else if( h->mb.i_mb_x > 0 )
+ else if( h->mb.i_neighbour & MB_LEFT )
i_mba_xy = h->mb.i_mb_xy -1;
if( y > 0 )
i_mbb_xy = h->mb.i_mb_xy;
- else if( h->mb.i_mb_y > 0 )
+ else if( h->mb.i_neighbour & MB_TOP )
i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
/* no need to test for skip/pcm */
else if( i_cat == 3 )
{
/* no need to test skip/pcm */
- if( h->mb.i_mb_x > 0 )
+ if( h->mb.i_neighbour & MB_LEFT )
{
i_mba_xy = h->mb.i_mb_xy -1;
if( h->mb.cbp[i_mba_xy]&0x30 )
i_nza = h->mb.cbp[i_mba_xy]&( 0x02 << ( 8 + i_idx) );
}
}
- if( h->mb.i_mb_y > 0 )
+ if( h->mb.i_neighbour & MB_TOP )
{
i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
if( h->mb.cbp[i_mbb_xy]&0x30 )
if( idxc == 1 || idxc == 3 )
i_mba_xy = h->mb.i_mb_xy;
- else if( h->mb.i_mb_x > 0 )
+ else if( h->mb.i_neighbour & MB_LEFT )
i_mba_xy = h->mb.i_mb_xy - 1;
if( idxc == 2 || idxc == 3 )
i_mbb_xy = h->mb.i_mb_xy;
- else if( h->mb.i_mb_y > 0 )
+ else if( h->mb.i_neighbour & MB_TOP )
i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
/* no need to test skip/pcm */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-
#include <math.h>
+#if HAVE_PTHREAD
+#include <pthread.h>
+#endif
+
#include "common/common.h"
#include "common/cpu.h"
sh->i_type = i_type;
sh->i_first_mb = 0;
+ sh->i_last_mb = h->sps->i_mb_width * h->sps->i_mb_height;
sh->i_pps_id = pps->i_id;
sh->i_frame_num = i_frame;
return -1;
}
+ h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_SLICE_MAX );
+ h->param.i_threads = X264_MIN( h->param.i_threads, h->param.i_height / 16 );
+#if !(HAVE_PTHREAD)
+ if( h->param.i_threads > 1 )
+ {
+ x264_log( h, X264_LOG_WARNING, "not compiled with pthread support!\n");
+ x264_log( h, X264_LOG_WARNING, "multislicing anyway, but you won't see any speed gain.\n" );
+ }
+#endif
+
h->param.i_frame_reference = x264_clip3( h->param.i_frame_reference, 1, 16 );
if( h->param.i_keyint_max <= 0 )
h->param.i_keyint_max = 1;
h->param.i_deblocking_filter_beta = x264_clip3( h->param.i_deblocking_filter_beta, -6, 6 );
h->param.i_cabac_init_idc = x264_clip3( h->param.i_cabac_init_idc, -1, 2 );
+ /* don't yet support merging of cabac stats */
+ if( h->param.i_threads > 1 && h->param.i_cabac_init_idc == -1 )
+ h->param.i_cabac_init_idc = 0;
if( h->param.analyse.i_me_method < X264_ME_DIA ||
h->param.analyse.i_me_method > X264_ME_ESA )
if( x264_ratecontrol_new( h ) < 0 )
return NULL;
- h->i_last_intra_size = 0;
- h->i_last_inter_size = 0;
-
/* stat */
for( i_slice = 0; i_slice < 5; i_slice++ )
{
param->cpu&X264_CPU_3DNOW ? "3DNow! " : "",
param->cpu&X264_CPU_ALTIVEC ? "Altivec " : "" );
+ h->thread[0] = h;
+ for( i = 1; i < param->i_threads; i++ )
+ h->thread[i] = x264_malloc( sizeof(x264_t) );
+
return h;
}
x264_macroblock_slice_init( h );
}
-static inline void x264_slice_write( x264_t *h, int i_nal_type, int i_nal_ref_idc )
+static int x264_slice_write( x264_t *h )
{
int i_skip;
int mb_xy;
- int i;
- /* Init stats */
- h->stat.frame.i_hdr_bits =
- h->stat.frame.i_itex_bits =
- h->stat.frame.i_ptex_bits =
- h->stat.frame.i_misc_bits =
- h->stat.frame.i_intra_cost =
- h->stat.frame.i_inter_cost = 0;
- for( i = 0; i < 18; i++ )
- h->stat.frame.i_mb_count[i] = 0;
+ memset( &h->stat.frame, 0, sizeof(h->stat.frame) );
/* Slice */
- x264_nal_start( h, i_nal_type, i_nal_ref_idc );
+ x264_nal_start( h, h->i_nal_type, h->i_nal_ref_idc );
/* Slice header */
- x264_slice_header_write( &h->out.bs, &h->sh, i_nal_ref_idc );
+ x264_slice_header_write( &h->out.bs, &h->sh, h->i_nal_ref_idc );
if( h->param.b_cabac )
{
/* alignment needed */
x264_visualize_init( h );
#endif
- for( mb_xy = 0, i_skip = 0; mb_xy < h->sps->i_mb_width * h->sps->i_mb_height; mb_xy++ )
+ for( mb_xy = h->sh.i_first_mb, i_skip = 0; mb_xy < h->sh.i_last_mb; mb_xy++ )
{
const int i_mb_y = mb_xy / h->sps->i_mb_width;
const int i_mb_x = mb_xy % h->sps->i_mb_width;
TIMER_STOP( i_mtime_encode );
TIMER_START( i_mtime_write );
- if( IS_SKIP( h->mb.i_type ) )
+ if( h->param.b_cabac )
{
- if( h->param.b_cabac )
- {
- if( mb_xy > 0 )
- {
- /* not end_of_slice_flag */
- x264_cabac_encode_terminal( &h->cabac, 0 );
- }
+ if( mb_xy > h->sh.i_first_mb )
+ x264_cabac_encode_terminal( &h->cabac, 0 );
+ if( IS_SKIP( h->mb.i_type ) )
x264_cabac_mb_skip( h, 1 );
- }
else
{
- i_skip++;
- }
- }
- else
- {
- if( h->param.b_cabac )
- {
- if( mb_xy > 0 )
- {
- /* not end_of_slice_flag */
- x264_cabac_encode_terminal( &h->cabac, 0 );
- }
if( h->sh.i_type != SLICE_TYPE_I )
- {
x264_cabac_mb_skip( h, 0 );
- }
x264_macroblock_write_cabac( h, &h->out.bs );
}
+ }
+ else
+ {
+ if( IS_SKIP( h->mb.i_type ) )
+ i_skip++;
else
{
if( h->sh.i_type != SLICE_TYPE_I )
- h->stat.frame.i_itex_bits
- h->stat.frame.i_ptex_bits
- h->stat.frame.i_hdr_bits;
+
+ return 0;
+}
+
+static inline int x264_slices_write( x264_t *h )
+{
+ if( h->param.i_threads == 1 )
+ {
+ x264_slice_write( h );
+ return h->out.nal[h->out.i_nal-1].i_payload;
+ }
+ else
+ {
+ int i_nal = h->out.i_nal;
+ int i_bs_size = h->out.i_bitstream / h->param.i_threads;
+ int i_frame_size;
+ int i;
+ /* duplicate contexts */
+ for( i = 0; i < h->param.i_threads; i++ )
+ {
+ x264_t *t = h->thread[i];
+ if( i > 0 )
+ {
+ memcpy( t, h, sizeof(x264_t) );
+ t->out.p_bitstream += i*i_bs_size;
+ bs_init( &t->out.bs, t->out.p_bitstream, i_bs_size );
+ }
+ t->sh.i_first_mb = (i * h->sps->i_mb_height / h->param.i_threads) * h->sps->i_mb_width;
+ t->sh.i_last_mb = ((i+1) * h->sps->i_mb_height / h->param.i_threads) * h->sps->i_mb_width;
+ t->out.i_nal = i_nal + i;
+ }
+
+ /* dispatch */
+#if HAVE_PTHREAD
+ {
+ pthread_t handles[X264_SLICE_MAX];
+ void *status;
+ for( i = 0; i < h->param.i_threads; i++ )
+ pthread_create( &handles[i], NULL, (void*)x264_slice_write, (void*)h->thread[i] );
+ for( i = 0; i < h->param.i_threads; i++ )
+ pthread_join( handles[i], &status );
+ }
+#else
+ for( i = 0; i < h->param.i_threads; i++ )
+ x264_slice_write( h->thread[i] );
+#endif
+
+ /* merge contexts */
+ i_frame_size = h->out.nal[i_nal].i_payload;
+ for( i = 1; i < h->param.i_threads; i++ )
+ {
+ int j;
+ x264_t *t = h->thread[i];
+ h->out.nal[i_nal+i] = t->out.nal[i_nal+i];
+ i_frame_size += t->out.nal[i_nal+i].i_payload;
+ // all entries in stat.frame are ints
+ for( j = 0; j < sizeof(h->stat.frame) / sizeof(int); j++ )
+ ((int*)&h->stat.frame)[j] += ((int*)&t->stat.frame)[j];
+ }
+ h->out.i_nal = i_nal + h->param.i_threads;
+ return i_frame_size;
+ }
}
/****************************************************************************
int i_nal_type;
int i_nal_ref_idc;
int i_slice_type;
+ int i_frame_size;
int i;
x264_nal_end(h);
}
+ h->i_nal_type = i_nal_type;
+ h->i_nal_ref_idc = i_nal_ref_idc;
+
/* Write SPS and PPS */
if( i_nal_type == NAL_SLICE_IDR )
{
x264_nal_end( h );
}
- /* Write the slice */
- x264_slice_write( h, i_nal_type, i_nal_ref_idc );
+ /* Write frame */
+ i_frame_size = x264_slices_write( h );
/* restore CPU state (before using float again) */
x264_cpu_restore( h->param.cpu );
float f_bias;
int i_gop_size = h->fenc->i_frame - h->frames.i_last_idr;
float f_thresh_max = h->param.i_scenecut_threshold / 100.0;
- /* ratio of 10 pulled out of thin air */
+ /* magic numbers pulled out of thin air */
float f_thresh_min = f_thresh_max * h->param.i_keyint_min
/ ( h->param.i_keyint_max * 4 );
if( h->param.i_keyint_min == h->param.i_keyint_max )
/* Bad P will be reencoded as I */
if( i_mb_s < i_mb &&
i_inter_cost >= (1.0 - f_bias) * i_intra_cost )
- /* i_mb_i >= (1.0 - f_bias) * i_mb ) */
- /*
- h->out.nal[h->out.i_nal-1].i_payload > h->i_last_intra_size +
- h->i_last_intra_size * (3+h->i_last_intra_qp - i_global_qp) / 16 &&
- i_mb_count[I_4x4] + i_mb_count[I_16x16] > i_mb_count[P_SKIP] + i_mb_count[P_L0]/2 &&
- h->out.nal[h->out.i_nal-1].i_payload > 2 * h->i_last_inter_size &&
- h->frames.i_last_i > 4)*/
{
int b;
x264_log( h, X264_LOG_DEBUG, "scene cut at %d size=%d Icost:%.0f Pcost:%.0f ratio:%.3f bias=%.3f lastIDR:%d (I:%d P:%d Skip:%d)\n",
- h->fenc->i_frame,
- h->out.nal[h->out.i_nal-1].i_payload,
+ h->fenc->i_frame, i_frame_size,
(double)i_intra_cost, (double)i_inter_cost,
(double)i_inter_cost / i_intra_cost,
f_bias, i_gop_size,
}
goto do_encode;
}
- h->i_last_inter_size = h->out.nal[h->out.i_nal-1].i_payload;
- }
- else
- {
- h->i_last_intra_size = h->out.nal[h->out.i_nal-1].i_payload;
- h->i_last_intra_qp = i_global_qp;
}
/* End bitstream, set output */
*pi_nal = h->out.i_nal;
- *pp_nal = &h->out.nal[0];
+ *pp_nal = h->out.nal;
/* Set output picture properties */
if( i_slice_type == SLICE_TYPE_I )
/* ---------------------- Update encoder state ------------------------- */
/* update cabac */
- if( h->param.b_cabac )
+ if( h->param.b_cabac && h->param.i_cabac_init_idc == -1 )
{
x264_cabac_model_update( &h->cabac, i_slice_type, h->sh.pps->i_pic_init_qp + h->sh.i_qp_delta );
}
x264_cpu_restore( h->param.cpu );
/* update rc */
- x264_ratecontrol_end( h, h->out.nal[h->out.i_nal-1].i_payload * 8 );
+ x264_ratecontrol_end( h, i_frame_size * 8 );
x264_frame_put( h->frames.unused, h->fenc );
/* ---------------------- Compute/Print statistics --------------------- */
/* Slice stat */
h->stat.i_slice_count[i_slice_type]++;
- h->stat.i_slice_size[i_slice_type] += bs_pos( &h->out.bs ) / 8 + NALU_OVERHEAD;
+ h->stat.i_slice_size[i_slice_type] += i_frame_size + NALU_OVERHEAD;
h->stat.i_slice_qp[i_slice_type] += i_global_qp;
for( i = 0; i < 18; i++ )
h->stat.frame.i_mb_count[I_16x16],
h->stat.frame.i_mb_count_p,
h->stat.frame.i_mb_count_skip,
- h->out.nal[h->out.i_nal-1].i_payload,
+ i_frame_size,
psz_message );
x264_macroblock_cache_end( h );
x264_free( h->out.p_bitstream );
+ for( i = 1; i < h->param.i_threads; i++ )
+ x264_free( h->thread[i] );
x264_free( h );
}
" --frames <integer> Maximum number of frames to encode\n"
" -o, --output Specify output file\n"
"\n"
+ " --threads <integer> Parallel encoding (uses slices)\n"
" --no-asm Disable all CPU optimizations\n"
" --no-psnr Disable PSNR computation\n"
" --quiet Quiet Mode\n"
#define OPT_VISUALIZE 290
#define OPT_SEEK 291
#define OPT_ZONES 292
+#define OPT_THREADS 293
static struct option long_options[] =
{
{ "qblur", required_argument, NULL, OPT_QBLUR },
{ "cplxblur",required_argument, NULL, OPT_CPLXBLUR },
{ "zones", required_argument, NULL, OPT_ZONES },
+ { "threads", required_argument, NULL, OPT_THREADS },
{ "no-psnr", no_argument, NULL, OPT_NOPSNR },
{ "quiet", no_argument, NULL, OPT_QUIET },
{ "verbose", no_argument, NULL, 'v' },
case OPT_ZONES:
param->rc.psz_zones = optarg;
break;
+ case OPT_THREADS:
+ param->i_threads = atoi(optarg);
+ break;
case OPT_NOPSNR:
param->analyse.b_psnr = 0;
break;
#include <stdarg.h>
-#define X264_BUILD 27
+#define X264_BUILD 28
/* x264_t:
* opaque handler for decoder and encoder */
{
/* CPU flags */
unsigned int cpu;
+ int i_threads; /* divide each frame into multiple slices, encode in parallel */
/* Video Properties */
int i_width;