Skip to content

Commit

Permalink
Update muxers
Browse files Browse the repository at this point in the history
--colormatrix and --fullrange options now influence on real RGB->YUV conversion in encoder
Improve non Annex B detection (don't fail on Annex B with the first shortstart)

git-svn-id: svn+ssh://svn.code.sf.net/p/x264vfw/code/trunk@31 20192f6c-ba0a-41c8-b3a9-3ed24a2bdf33
  • Loading branch information
MasterNobody committed Mar 2, 2011
1 parent b215fd9 commit b3333e3
Show file tree
Hide file tree
Showing 24 changed files with 8,626 additions and 3,124 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -86,7 +86,7 @@ CFLAGS += "-DHAVE_FFMPEG"
CFLAGS += "-I$(FFMPEG_DIR)"
VFW_LDFLAGS += "-L$(FFMPEG_DIR)/libavformat" -lavformat
VFW_LDFLAGS += "-L$(FFMPEG_DIR)/libavcodec" -lavcodec
VFW_LDFLAGS += "-L$(FFMPEG_DIR)/libavcore" -lavcore
#VFW_LDFLAGS += "-L$(FFMPEG_DIR)/libavcore" -lavcore
VFW_LDFLAGS += "-L$(FFMPEG_DIR)/libavutil" -lavutil
VFW_LDFLAGS += "-L$(FFMPEG_DIR)/libswscale" -lswscale
endif
Expand Down
31 changes: 24 additions & 7 deletions codec.c
Expand Up @@ -1078,10 +1078,6 @@ LRESULT compress_begin(CODEC *codec, BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutp
param.i_fps_den = codec->i_fps_den;
}

/* Colorspace conversion */
x264vfw_csp_init(&codec->csp, param.i_csp);
x264_picture_alloc(&codec->conv_pic, param.i_csp, param.i_width, param.i_height);

/* Basic */
param.i_level_idc = config->i_level >= 0 && config->i_level < COUNT_LEVEL
? level_table[config->i_level].value
Expand Down Expand Up @@ -1264,6 +1260,14 @@ LRESULT compress_begin(CODEC *codec, BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutp
codec->b_warn_frame_loss = !codec->b_cli_output;
#endif

/* Colorspace conversion */
x264vfw_csp_init(&codec->csp, param.i_csp, param.vui.i_colmatrix, param.vui.b_fullrange);
if (x264_picture_alloc(&codec->conv_pic, param.i_csp, param.i_width, param.i_height) < 0)
{
x264vfw_log(codec, X264_LOG_ERROR, "x264_picture_alloc failed\n");
goto fail;
}

return ICERR_OK;
fail:
codec->b_encoder_error = TRUE;
Expand Down Expand Up @@ -1685,16 +1689,29 @@ LRESULT decompress(CODEC *codec, ICDECOMPRESS *icd)
uint32_t buf_size = inhdr->biSizeImage;
uint32_t nal_size = endian_fix32(*(uint32_t *)buf);
/* Check startcode */
if ((nal_size & 0x00ffffff) != 0x00000001)
if (nal_size != 0x00000001)
{
/* Convert to Annex B */
*(uint32_t *)buf = endian_fix32(0x00000001);
/* Check that this is correct size prefixed format */
while ((uint64_t)buf_size >= (uint64_t)nal_size + 8)
{
buf += nal_size + 4;
buf_size -= nal_size + 4;
nal_size = endian_fix32(*(uint32_t *)buf);
}
if ((uint64_t)buf_size == (uint64_t)nal_size + 4)
{
/* Convert to Annex B */
buf = codec->decoder_buf;
buf_size = inhdr->biSizeImage;
nal_size = endian_fix32(*(uint32_t *)buf);
*(uint32_t *)buf = endian_fix32(0x00000001);
while ((uint64_t)buf_size >= (uint64_t)nal_size + 8)
{
buf += nal_size + 4;
buf_size -= nal_size + 4;
nal_size = endian_fix32(*(uint32_t *)buf);
*(uint32_t *)buf = endian_fix32(0x00000001);
}
}
}
}
Expand Down
314 changes: 181 additions & 133 deletions csp.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion csp.h
Expand Up @@ -49,6 +49,6 @@ typedef struct
x264vfw_csp_t convert[X264VFW_CSP_MAX];
} x264vfw_csp_function_t;

void x264vfw_csp_init( x264vfw_csp_function_t *pf, int i_csp );
void x264vfw_csp_init( x264vfw_csp_function_t *pf, int i_x264_csp, int i_colmatrix, int b_fullrange );

#endif
4 changes: 2 additions & 2 deletions output/avi.c
Expand Up @@ -58,7 +58,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest

if( h->mux_fc && h->mux_fc->pb )
{
url_fclose( h->mux_fc->pb );
avio_close( h->mux_fc->pb );
h->mux_fc->pb = NULL;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt
h->mux_fc->oformat = mux_fmt;
snprintf( h->mux_fc->filename, sizeof(h->mux_fc->filename), "%s", psz_filename );

if( url_fopen( &h->mux_fc->pb, psz_filename, URL_WRONLY ) < 0 )
if( avio_open( &h->mux_fc->pb, psz_filename, URL_WRONLY ) < 0 )
{
close_file( h, 0, 0 );
return -1;
Expand Down
8 changes: 4 additions & 4 deletions output/flv.c
Expand Up @@ -308,12 +308,12 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest

double total_duration;
/* duration algorithm fails with one frame */
if( p_flv->i_framenum > 1 )
total_duration = (2 * largest_pts - second_largest_pts) * p_flv->d_timebase;
if( p_flv->i_framenum == 1 )
total_duration = p_flv->i_fps_num ? (double)p_flv->i_fps_den / p_flv->i_fps_num : 0;
else
total_duration = (double)p_flv->i_fps_den / p_flv->i_fps_num;
total_duration = (2 * largest_pts - second_largest_pts) * p_flv->d_timebase;

if( x264_is_regular_file( c->fp ) )
if( x264_is_regular_file( c->fp ) && total_duration > 0 )
{
double framerate;
uint64_t filesize = ftell( c->fp );
Expand Down
2 changes: 1 addition & 1 deletion output/matroska.c
Expand Up @@ -203,7 +203,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
int ret;
int64_t i_last_delta;

i_last_delta = (int64_t)(((largest_pts - second_largest_pts) * p_mkv->i_timebase_num / p_mkv->i_timebase_den) + 0.5);
i_last_delta = p_mkv->i_timebase_den ? (int64_t)(((largest_pts - second_largest_pts) * p_mkv->i_timebase_num / p_mkv->i_timebase_den) + 0.5) : 0;

ret = mk_close( p_mkv->w, i_last_delta );

Expand Down

0 comments on commit b3333e3

Please sign in to comment.