[x264-devel] Patch from Capella Systems
Fiona Glaser
florinaglaser at gmail.com
Thu Sep 25 23:13:35 CEST 2014
Thoughts on this? This is a patch to add support for user-specifiable timecodes.
Fiona
-------------- next part --------------
commit 4b863eccd439cdc0202b9b4eca5fdf5c5b0f1028
Author: Martin Belleau <mbelleau at capellasystems.net>
Date: Wed Sep 24 14:17:55 2014 -0700
Add support for user-specified timecodes in SEI pic_timing (from Capella Systems)
diff --git a/common/frame.c b/common/frame.c
index a845181..fb8db21 100644
--- a/common/frame.c
+++ b/common/frame.c
@@ -123,6 +123,7 @@ static x264_frame_t *x264_frame_new( x264_t *h, int b_fdec )
frame->i_width_lowres = frame->i_width[0]/2;
frame->i_lines_lowres = frame->i_lines[0]/2;
frame->i_stride_lowres = align_stride( frame->i_width_lowres + 2*PADH, align, disalign<<1 );
+ frame->timecode.is_valid = 0;
for( int i = 0; i < h->param.i_bframe + 2; i++ )
for( int j = 0; j < h->param.i_bframe + 2; j++ )
@@ -393,6 +394,7 @@ int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
dst->param = src->param;
dst->i_pic_struct = src->i_pic_struct;
dst->extra_sei = src->extra_sei;
+ dst->timecode = src->timecode;
dst->opaque = src->opaque;
dst->mb_info = h->param.analyse.b_mb_info ? src->prop.mb_info : NULL;
dst->mb_info_free = h->param.analyse.b_mb_info ? src->prop.mb_info_free : NULL;
diff --git a/common/frame.h b/common/frame.h
index f95ffa9..e8e319c 100644
--- a/common/frame.h
+++ b/common/frame.h
@@ -167,6 +167,8 @@ typedef struct x264_frame
/* user sei */
x264_sei_t extra_sei;
+ x264_timecode_t timecode;
+
/* user data */
void *opaque;
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 1ea341b..ac75635 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -3600,7 +3600,7 @@ int x264_encoder_encode( x264_t *h,
}
/* generate sei pic timing */
- if( h->sps->vui.b_pic_struct_present || h->sps->vui.b_nal_hrd_parameters_present )
+ if( h->sps->vui.b_pic_struct_present || h->sps->vui.b_nal_hrd_parameters_present || h->fenc->timecode.is_valid)
{
x264_nal_start( h, NAL_SEI, NAL_PRIORITY_DISPOSABLE );
x264_sei_pic_timing_write( h, &h->out.bs );
diff --git a/encoder/set.c b/encoder/set.c
index 1a40b71..f7b6499 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -632,10 +632,31 @@ void x264_sei_pic_timing_write( x264_t *h, bs_t *s )
{
bs_write( &q, 4, h->fenc->i_pic_struct-1 ); // We use index 0 for "Auto"
- // These clock timestamps are not standardised so we don't set them
- // They could be time of origin, capture or alternative ideal display
for( int i = 0; i < num_clock_ts[h->fenc->i_pic_struct]; i++ )
- bs_write1( &q, 0 ); // clock_timestamp_flag
+ {
+ if(h->fenc->timecode.is_valid)
+ {
+ bs_write1( &q, 1 ); // clock_timestamp_flag
+ bs_write( &q, 2, 0 ); // ct_type
+ bs_write1( &q, 0 ); // nuit_field_based_flag
+ bs_write( &q, 5, h->fenc->timecode.counting_type );
+ bs_write1( &q, 1 ); // full_timestamp_flag
+ bs_write1( &q, h->fenc->timecode.discontinuity_flag );
+ bs_write1( &q, h->fenc->timecode.cnt_dropped_flag );
+ bs_write( &q, 8, h->fenc->timecode.frames );
+ bs_write( &q, 6, h->fenc->timecode.sec );
+ bs_write( &q, 6, h->fenc->timecode.min );
+ bs_write( &q, 5, h->fenc->timecode.hour );
+
+ if( sps->vui.b_nal_hrd_parameters_present || sps->vui.b_vcl_hrd_parameters_present )
+ {
+ if(sps->vui.hrd.i_time_offset_length > 0)
+ bs_write( &q, sps->vui.hrd.i_time_offset_length, 0 );
+ }
+ }
+ else
+ bs_write1( &q, 0 ); // clock_timestamp_flag
+ }
}
bs_align_10( &q );
diff --git a/x264.h b/x264.h
index 50aefc5..31c025d 100644
--- a/x264.h
+++ b/x264.h
@@ -721,6 +721,18 @@ typedef struct
typedef struct
{
+ int is_valid;
+ int hour;
+ int min;
+ int sec;
+ int frames;
+ int counting_type;
+ int discontinuity_flag;
+ int cnt_dropped_flag;
+} x264_timecode_t;
+
+typedef struct
+{
int i_csp; /* Colorspace */
int i_plane; /* Number of image planes */
int i_stride[4]; /* Strides for each plane */
@@ -825,6 +837,10 @@ typedef struct
x264_hrd_t hrd_timing;
/* In: arbitrary user SEI (e.g subtitles, AFDs) */
x264_sei_t extra_sei;
+
+ /* In: user-provided timecode, written into SEI pic_timing */
+ x264_timecode_t timecode;
+
/* private user data. copied from input to output frames. */
void *opaque;
} x264_picture_t;
More information about the x264-devel
mailing list