summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libhb/common.h1
-rw-r--r--libhb/muxcommon.c8
-rw-r--r--libhb/muxmkv.c67
-rw-r--r--libhb/muxmp4.c67
4 files changed, 101 insertions, 42 deletions
diff --git a/libhb/common.h b/libhb/common.h
index dfa1dcabd..f8921f654 100644
--- a/libhb/common.h
+++ b/libhb/common.h
@@ -458,6 +458,7 @@ struct hb_subtitle_s
hb_fifo_t * fifo_raw; /* Decoded SPU */
hb_fifo_t * fifo_sync;/* Synced */
hb_fifo_t * fifo_out; /* Correct Timestamps, ready to be muxed */
+ hb_mux_data_t * mux_data;
#endif
};
diff --git a/libhb/muxcommon.c b/libhb/muxcommon.c
index 813afc863..4d64b76f4 100644
--- a/libhb/muxcommon.c
+++ b/libhb/muxcommon.c
@@ -258,6 +258,14 @@ static void MuxerFunc( void * _mux )
add_mux_track( mux, audio->priv.fifo_out, audio->priv.mux_data, 1 );
}
+ for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
+ {
+ hb_subtitle_t *subtitle = hb_list_item( title->list_subtitle, i );
+
+ if (subtitle->dest != PASSTHRUSUB)
+ continue;
+ add_mux_track( mux, subtitle->fifo_out, subtitle->mux_data, 0 );
+ }
// The following 'while' is the main muxing loop.
diff --git a/libhb/muxmkv.c b/libhb/muxmkv.c
index fa9241fe6..c3d627979 100644
--- a/libhb/muxmkv.c
+++ b/libhb/muxmkv.c
@@ -30,6 +30,8 @@ struct hb_mux_data_s
uint64_t prev_chapter_tc;
uint16_t current_chapter;
int codec;
+ int subtitle;
+ int sub_format;
};
/**********************************************************************
@@ -158,7 +160,7 @@ static int MKVInit( hb_mux_object_t * m )
for( i = 0; i < hb_list_count( title->list_audio ); i++ )
{
audio = hb_list_item( title->list_audio, i );
- mux_data = malloc( sizeof( hb_mux_data_t ) );
+ mux_data = calloc(1, sizeof( hb_mux_data_t ) );
audio->priv.mux_data = mux_data;
mux_data->codec = audio->config.out.codec;
@@ -231,7 +233,7 @@ static int MKVInit( hb_mux_object_t * m )
{
track->extra.audio.channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(audio->config.in.channel_layout);
}
- else
+ else
{
track->extra.audio.channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
}
@@ -241,6 +243,57 @@ static int MKVInit( hb_mux_object_t * m )
free(track->codecPrivate);
}
+ char * subidx_fmt =
+ "size: %dx%d\n"
+ "org: %d, %d\n"
+ "scale: 100%%, 100%%\n"
+ "alpha: 100%%\n"
+ "smooth: OFF\n"
+ "fadein/out: 50, 50\n"
+ "align: OFF at LEFT TOP\n"
+ "time offset: 0\n"
+ "forced subs: %s\n"
+ "palette: %06x, %06x, %06x, %06x, %06x, %06x, "
+ "%06x, %06x, %06x, %06x, %06x, %06x, %06x, %06x, %06x, %06x\n"
+ "custom colors: OFF, tridx: 0000, "
+ "colors: 000000, 000000, 000000, 000000\n";
+
+ for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
+ {
+ hb_subtitle_t * subtitle;
+ uint32_t * palette;
+ char subidx[2048];
+ int len;
+
+ subtitle = hb_list_item( title->list_subtitle, i );
+ if (subtitle->dest != PASSTHRUSUB)
+ continue;
+
+ memset(track, 0, sizeof(mk_TrackConfig));
+
+ mux_data = calloc(1, sizeof( hb_mux_data_t ) );
+ subtitle->mux_data = mux_data;
+ mux_data->subtitle = 1;
+ mux_data->sub_format = subtitle->format;
+
+ palette = title->palette;
+ len = snprintf(subidx, 2048, subidx_fmt, title->width, title->height,
+ 0, 0, "OFF",
+ palette[0], palette[1], palette[2], palette[3],
+ palette[4], palette[5], palette[6], palette[7],
+ palette[8], palette[9], palette[10], palette[11],
+ palette[12], palette[13], palette[14], palette[15]);
+ track->codecPrivate = subidx;
+ track->codecPrivateSize = len + 1;
+ track->codecID = MK_SUBTITLE_VOBSUB;
+ track->flagEnabled = 1;
+ track->trackType = MK_TRACK_SUBTITLE;
+ track->language = subtitle->iso639_2;
+
+ mux_data->track = mk_createTrack(m->file, track);
+
+ }
+
if( mk_writeHeader( m->file, "HandBrake " HB_PROJECT_VERSION) < 0 )
{
hb_error( "Failed to write to output file, disk full?");
@@ -313,6 +366,16 @@ static int MKVMux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
return 0;
}
}
+ else if ( mux_data->subtitle )
+ {
+ timecode = buf->start * TIMECODE_SCALE;
+ if( mux_data->sub_format == TEXTSUB )
+ {
+ hb_log("MuxMKV: Text Sub:%lld: %s", buf->start, buf->data);
+ // TODO: add CC data to track
+ return 0;
+ }
+ }
else
{
/* Audio */
diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c
index 54045283f..b50795d8c 100644
--- a/libhb/muxmp4.c
+++ b/libhb/muxmp4.c
@@ -32,6 +32,8 @@ struct hb_mux_object_s
struct hb_mux_data_s
{
MP4TrackId track;
+ uint8_t subtitle;
+ int sub_format;
};
/* Tune video track chunk duration.
@@ -98,7 +100,7 @@ static int MP4Init( hb_mux_object_t * m )
}
/* Video track */
- mux_data = malloc( sizeof( hb_mux_data_t ) );
+ mux_data = calloc(1, sizeof( hb_mux_data_t ) );
job->mux_data = mux_data;
if (!(MP4SetTimeScale( m->file, 90000 )))
@@ -220,7 +222,7 @@ static int MP4Init( hb_mux_object_t * m )
for( i = 0; i < hb_list_count( title->list_audio ); i++ )
{
audio = hb_list_item( title->list_audio, i );
- mux_data = malloc( sizeof( hb_mux_data_t ) );
+ mux_data = calloc(1, sizeof( hb_mux_data_t ) );
audio->priv.mux_data = mux_data;
if( audio->config.out.codec == HB_ACODEC_AC3 )
@@ -399,6 +401,22 @@ static int MP4Init( hb_mux_object_t * m )
}
+ for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
+ {
+ hb_subtitle_t *subtitle = hb_list_item( job->list_subtitle, i );
+
+ if( subtitle && subtitle->format == TEXTSUB &&
+ subtitle->dest == PASSTHRUSUB )
+ {
+ mux_data = calloc(1, sizeof( hb_mux_data_t ) );
+ subtitle->mux_data = mux_data;
+ mux_data->subtitle = 1;
+ mux_data->sub_format = subtitle->format;
+ // TODO: add subtitle track
+ // mux_data->track = MP4AddSubtitleTrack(....);
+ }
+ }
+
if (job->chapter_markers)
{
/* add a text track for the chapters. We add the 'chap' atom to track
@@ -437,7 +455,6 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
hb_job_t * job = m->job;
int64_t duration;
int64_t offset = 0;
- int i;
if( mux_data == job->mux_data )
{
@@ -569,6 +586,13 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
*job->die = 1;
}
}
+ else if (mux_data->subtitle)
+ {
+ if( mux_data->sub_format == TEXTSUB )
+ {
+ hb_log("MuxMP4: Text Sub:%lld: %s", buf->start, buf->data);
+ }
+ }
else
{
if( !MP4WriteSample( m->file,
@@ -584,43 +608,6 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
}
}
- for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
- {
- hb_subtitle_t *subtitle = hb_list_item( job->list_subtitle, i );
-
- if( subtitle && subtitle->format == TEXTSUB &&
- subtitle->dest == PASSTHRUSUB )
- {
- /*
- * Should be adding this one if the timestamp is right.
- */
- hb_buffer_t *sub;
-
- while( ( sub = hb_fifo_see( subtitle->fifo_out )) != NULL )
- {
- if( sub->size == 0 )
- {
- /*
- * EOF
- */
- hb_log("MuxMP4: Text Sub: EOF");
- sub = hb_fifo_get( subtitle->fifo_out );
- hb_buffer_close( &sub );
- } else {
- if( sub->start < buf->start ) {
- sub = hb_fifo_get( subtitle->fifo_out );
- hb_log("MuxMP4: Text Sub:%lld:%lld: %s", sub->start, sub->stop, sub->data);
- hb_buffer_close( &sub );
- } else {
- /*
- * Not time yet
- */
- break;
- }
- }
- }
- }
- }
return 0;
}