Commit c4fa64d3 authored by Ilkka Ollakka's avatar Ilkka Ollakka

x264: place SEI in start of first block, also copy all nals at once

libavcodec seems to do the same and didn't actually found a reaso earlier
patch did what it did. Copying nals helps if you do slices, so it doesn't
do one nal at a time.
parent e21127bf
...@@ -1366,28 +1366,24 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict ) ...@@ -1366,28 +1366,24 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
/* Get size of block we need */ /* Get size of block we need */
i_out = p_sys->i_sei_size;
for( i = 0; i < i_nal; i++ ) for( i = 0; i < i_nal; i++ )
i_out += nal[i].i_payload; i_out += nal[i].i_payload;
p_block = block_New( p_enc, i_out ); p_block = block_New( p_enc, i_out + p_sys->i_sei_size );
if( !p_block ) return NULL; if( !p_block ) return NULL;
/* copy encoded data directly to block */ unsigned int i_offset = 0;
for( i = 0, i_out = 0; i < i_nal; i++ ) if( unlikely( p_sys->i_sei_size && ( i_nal > 1 ) ) )
{
if( p_sys->i_sei_size && nal[i].i_type == NAL_SLICE )
{ {
/* insert x264 headers SEI nal before first SLICE nal */ /* insert x264 headers SEI nal into the first picture block at the start */
memcpy( p_block->p_buffer, p_sys->p_sei, p_sys->i_sei_size ); memcpy( p_block->p_buffer, p_sys->p_sei, p_sys->i_sei_size );
i_out += p_sys->i_sei_size; i_offset = p_sys->i_sei_size;
p_sys->i_sei_size = 0; p_sys->i_sei_size = 0;
free( p_sys->p_sei ); free( p_sys->p_sei );
p_sys->p_sei = NULL; p_sys->p_sei = NULL;
} }
memcpy( p_block->p_buffer + i_out, nal[i].p_payload, nal[i].i_payload ); /* copy encoded data directly to block */
i_out += nal[i].i_payload; memcpy( p_block->p_buffer + i_offset, nal[0].p_payload, i_out );
}
if( pic.b_keyframe ) if( pic.b_keyframe )
p_block->i_flags |= BLOCK_FLAG_TYPE_I; p_block->i_flags |= BLOCK_FLAG_TYPE_I;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment