Commit 5d34933a authored by Ilkka Ollakka's avatar Ilkka Ollakka

transcode: refactor littlebit video-encoding

parent 4e866088
......@@ -285,6 +285,65 @@ int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_t *id )
}
return VLC_SUCCESS;
}
static void transcode_video_filter_init( sout_stream_t *p_stream,
sout_stream_id_t *id )
{
id->p_f_chain = filter_chain_New( p_stream, "video filter2",
false,
transcode_video_filter_allocation_init,
transcode_video_filter_allocation_clear,
p_stream->p_sys );
/* Deinterlace */
if( p_stream->p_sys->b_deinterlace )
{
filter_chain_AppendFilter( id->p_f_chain,
p_stream->p_sys->psz_deinterlace,
p_stream->p_sys->p_deinterlace_cfg,
&id->p_decoder->fmt_out,
&id->p_decoder->fmt_out );
}
/* Take care of the scaling and chroma conversions */
if( ( id->p_decoder->fmt_out.video.i_chroma !=
id->p_encoder->fmt_in.video.i_chroma ) ||
( id->p_decoder->fmt_out.video.i_width !=
id->p_encoder->fmt_in.video.i_width ) ||
( id->p_decoder->fmt_out.video.i_height !=
id->p_encoder->fmt_in.video.i_height ) )
{
filter_chain_AppendFilter( id->p_f_chain,
NULL, NULL,
&id->p_decoder->fmt_out,
&id->p_encoder->fmt_in );
}
if( p_stream->p_sys->psz_vf2 )
{
const es_format_t *p_fmt_out;
id->p_uf_chain = filter_chain_New( p_stream, "video filter2",
true,
transcode_video_filter_allocation_init,
transcode_video_filter_allocation_clear,
p_stream->p_sys );
filter_chain_Reset( id->p_uf_chain, &id->p_encoder->fmt_in,
&id->p_encoder->fmt_in );
filter_chain_AppendFromString( id->p_uf_chain, p_stream->p_sys->psz_vf2 );
p_fmt_out = filter_chain_GetFmtOut( id->p_uf_chain );
es_format_Copy( &id->p_encoder->fmt_in, p_fmt_out );
id->p_encoder->fmt_out.video.i_width =
id->p_encoder->fmt_in.video.i_width;
id->p_encoder->fmt_out.video.i_height =
id->p_encoder->fmt_in.video.i_height;
id->p_encoder->fmt_out.video.i_sar_num =
id->p_encoder->fmt_in.video.i_sar_num;
id->p_encoder->fmt_out.video.i_sar_den =
id->p_encoder->fmt_in.video.i_sar_den;
}
}
static void transcode_video_encoder_init( sout_stream_t *p_stream,
sout_stream_id_t *id )
{
......@@ -605,61 +664,11 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
}
}
if( !id->p_encoder->p_module )
if( unlikely( !id->p_encoder->p_module ) )
{
transcode_video_encoder_init( p_stream, id );
id->p_f_chain = filter_chain_New( p_stream, "video filter2",
false,
transcode_video_filter_allocation_init,
transcode_video_filter_allocation_clear,
p_stream->p_sys );
/* Deinterlace */
if( p_stream->p_sys->b_deinterlace )
{
filter_chain_AppendFilter( id->p_f_chain,
p_sys->psz_deinterlace,
p_sys->p_deinterlace_cfg,
&id->p_decoder->fmt_out,
&id->p_decoder->fmt_out );
}
/* Take care of the scaling and chroma conversions */
if( ( id->p_decoder->fmt_out.video.i_chroma !=
id->p_encoder->fmt_in.video.i_chroma ) ||
( id->p_decoder->fmt_out.video.i_width !=
id->p_encoder->fmt_in.video.i_width ) ||
( id->p_decoder->fmt_out.video.i_height !=
id->p_encoder->fmt_in.video.i_height ) )
{
filter_chain_AppendFilter( id->p_f_chain,
NULL, NULL,
&id->p_decoder->fmt_out,
&id->p_encoder->fmt_in );
}
if( p_sys->psz_vf2 )
{
const es_format_t *p_fmt_out;
id->p_uf_chain = filter_chain_New( p_stream, "video filter2",
true,
transcode_video_filter_allocation_init,
transcode_video_filter_allocation_clear,
p_stream->p_sys );
filter_chain_Reset( id->p_uf_chain, &id->p_encoder->fmt_in,
&id->p_encoder->fmt_in );
filter_chain_AppendFromString( id->p_uf_chain, p_sys->psz_vf2 );
p_fmt_out = filter_chain_GetFmtOut( id->p_uf_chain );
es_format_Copy( &id->p_encoder->fmt_in, p_fmt_out );
id->p_encoder->fmt_out.video.i_width =
id->p_encoder->fmt_in.video.i_width;
id->p_encoder->fmt_out.video.i_height =
id->p_encoder->fmt_in.video.i_height;
id->p_encoder->fmt_out.video.i_sar_num =
id->p_encoder->fmt_in.video.i_sar_num;
id->p_encoder->fmt_out.video.i_sar_den =
id->p_encoder->fmt_in.video.i_sar_den;
}
transcode_video_filter_init( p_stream, id );
if( transcode_video_encoder_open( p_stream, id ) != VLC_SUCCESS )
{
......@@ -738,19 +747,9 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
i_pts = p_pic->date + 1;
}
date_Increment( &id->interpolated_pts, 1 );
}
if( p_sys->b_master_sync && i_duplicate > 1 )
{
mtime_t i_pts = date_Get( &id->interpolated_pts ) + 1;
if( (p_pic->date - i_pts > MASTER_SYNC_MAX_DRIFT)
|| ((p_pic->date - i_pts) < -MASTER_SYNC_MAX_DRIFT) )
if( i_duplicate > 1 )
{
msg_Dbg( p_stream, "drift is too high, resetting master sync" );
date_Set( &id->interpolated_pts, p_pic->date );
i_pts = p_pic->date + 1;
}
date_Increment( &id->interpolated_pts, 1 );
if( p_sys->i_threads >= 1 )
{
......@@ -759,7 +758,7 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
if( p_pic2 != NULL )
{
picture_Copy( p_pic2, p_pic );
p_pic2->date = i_pts;
p_pic2->date = i_pts + 1;
}
}
else
......@@ -772,6 +771,7 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
block_ChainAppend( out, p_block );
}
}
}
if( p_sys->i_threads == 0 )
{
......
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