summaryrefslogtreecommitdiffstats
path: root/libhb/muxmkv.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhb/muxmkv.c')
-rw-r--r--libhb/muxmkv.c58
1 files changed, 16 insertions, 42 deletions
diff --git a/libhb/muxmkv.c b/libhb/muxmkv.c
index a170eb557..ca72a7be8 100644
--- a/libhb/muxmkv.c
+++ b/libhb/muxmkv.c
@@ -8,6 +8,9 @@
*/
/* libmkv header */
+
+#if defined(USE_LIBMKV)
+
#include "libmkv.h"
#include <ogg/ogg.h>
@@ -17,15 +20,16 @@
/* Scale factor to apply to timecodes to convert from HandBrake's
* 1/90000s to nanoseconds as expected by libmkv */
-#define TIMECODE_SCALE 1000000000 / 90000
+#define NANOSECOND_SCALE 1000000000L
+#define TIMECODE_SCALE 1000000000L / 90000
struct hb_mux_object_s
{
HB_MUX_COMMON;
- hb_job_t * job;
-
+ hb_job_t * job;
mk_Writer * file;
+ int delay;
};
struct hb_mux_data_s
@@ -202,6 +206,9 @@ static int MKVInit( hb_mux_object_t * m )
mux_data = calloc(1, sizeof( hb_mux_data_t ) );
audio->priv.mux_data = mux_data;
+ if (audio->config.out.delay > m->delay)
+ m->delay = audio->config.out.delay;
+
mux_data->codec = audio->config.out.codec;
memset(track, 0, sizeof(mk_TrackConfig));
@@ -440,14 +447,13 @@ static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf)
char chapter_name[1024];
hb_chapter_t *chapter_data;
uint64_t timecode = 0;
- ogg_packet *op = NULL;
hb_job_t *job = m->job;
+ // Adjust for audio preroll and scale units
+ timecode = (buf->s.start + m->delay) * TIMECODE_SCALE;
if (mux_data == job->mux_data)
{
/* Video */
- timecode = buf->s.start * TIMECODE_SCALE;
-
if (job->chapter_markers && buf->s.new_chap)
{
// reached chapter N, write marker for chapter N-1
@@ -475,22 +481,6 @@ static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf)
}
mux_data->prev_chapter_tc = timecode;
}
-
- if (job->vcodec == HB_VCODEC_THEORA)
- {
- /* ughhh, theora is a pain :( */
- op = (ogg_packet *)buf->data;
- op->packet = buf->data + sizeof( ogg_packet );
- if (mk_startFrame(m->file, mux_data->track) < 0)
- {
- hb_error( "Failed to write frame to output file, Disk Full?" );
- *job->die = 1;
- }
- mk_addFrameData(m->file, mux_data->track, op->packet, op->bytes);
- mk_setFrameFlags(m->file, mux_data->track, timecode, 1, 0);
- hb_buffer_close( &buf );
- return 0;
- }
}
else if (mux_data->subtitle)
{
@@ -500,14 +490,13 @@ static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf)
*job->die = 1;
}
uint64_t duration;
- timecode = buf->s.start * TIMECODE_SCALE;
- if (buf->s.stop <= buf->s.start)
+ if (buf->s.duration < 0)
{
- duration = 0;
+ duration = 10 * NANOSECOND_SCALE;
}
else
{
- duration = buf->s.stop * TIMECODE_SCALE - timecode;
+ duration = buf->s.duration * TIMECODE_SCALE;
}
mk_addFrameData(m->file, mux_data->track, buf->data, buf->size);
mk_setFrameFlags(m->file, mux_data->track, timecode, 1, duration);
@@ -518,22 +507,6 @@ static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf)
else
{
/* Audio */
- timecode = buf->s.start * TIMECODE_SCALE;
- if (mux_data->codec == HB_ACODEC_VORBIS)
- {
- /* ughhh, vorbis is a pain :( */
- op = (ogg_packet *)buf->data;
- op->packet = buf->data + sizeof( ogg_packet );
- if (mk_startFrame(m->file, mux_data->track))
- {
- hb_error( "Failed to write frame to output file, Disk Full?" );
- *job->die = 1;
- }
- mk_addFrameData(m->file, mux_data->track, op->packet, op->bytes);
- mk_setFrameFlags(m->file, mux_data->track, timecode, 1, 0);
- hb_buffer_close( &buf );
- return 0;
- }
}
if( mk_startFrame(m->file, mux_data->track) < 0)
@@ -690,3 +663,4 @@ hb_mux_object_t * hb_mux_mkv_init( hb_job_t * job )
m->job = job;
return m;
}
+#endif // USE_LIBMKV