summaryrefslogtreecommitdiffstats
path: root/libhb/decutf8sub.c
diff options
context:
space:
mode:
authordynaflash <[email protected]>2010-05-04 16:56:43 +0000
committerdynaflash <[email protected]>2010-05-04 16:56:43 +0000
commit15aa5c37af71153316adcd7d56dbe7d12ad895c2 (patch)
tree87a38102ec17ffbc9af3329a5641417c5c379474 /libhb/decutf8sub.c
parent5a0738fc0c12c7ce73346b8e7c06d67a28fdcbfa (diff)
Universal Text Subtitle Support Initial Implementation
- Patch by davidfstr ... Thanks! - Adds support for reading TEXT subtitle tracks from file inputs - Tested combinations: -- MKV UTF-8 -> MKV UTF-8 (passthru) -- MKV UTF-8 -> MP4 TX3G (upconvert) -- MP4 TX3G -> MKV UTF-8 (downconvert) -- MP4 TX3G -> MP4 TX3G (downconvert to UTF-8 then upconvert) - Further explained here http://forum.handbrake.fr/viewtopic.php?f=4&t=16099 git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3283 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/decutf8sub.c')
-rw-r--r--libhb/decutf8sub.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libhb/decutf8sub.c b/libhb/decutf8sub.c
new file mode 100644
index 000000000..dcd05d4fc
--- /dev/null
+++ b/libhb/decutf8sub.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License. */
+
+/*
+ * Decoder for UTF-8 subtitles obtained from file input-sources.
+ *
+ * Input and output packet format is UTF-8 encoded text,
+ * with limited HTML-style markup (only <b>, <i>, and <u>).
+ *
+ * @author David Foster (davidfstr)
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "hb.h"
+
+static int decutf8Init( hb_work_object_t * w, hb_job_t * job )
+{
+ return 0;
+}
+
+static int decutf8Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
+ hb_buffer_t ** buf_out )
+{
+ hb_buffer_t * in = *buf_in;
+ hb_buffer_t * out = NULL;
+
+ // Pass the packets through without modification
+ out = in;
+
+ // Warn if the subtitle's duration has not been passed through by the demuxer,
+ // which will prevent the subtitle from displaying at all
+ if ( out->stop == 0 ) {
+ hb_log( "decutf8sub: subtitle packet lacks duration" );
+ }
+
+ // We shouldn't be storing the extra NULL character,
+ // but the MP4 muxer expects this, unfortunately.
+ if ( out->size > 0 && out->data[out->size - 1] != '\0' ) {
+ // NOTE: out->size remains unchanged
+ hb_buffer_realloc( out, out->size + 1 );
+ out->data[out->size] = '\0';
+ }
+
+ *buf_in = NULL;
+ *buf_out = out;
+ return HB_WORK_OK;
+}
+
+static void decutf8Close( hb_work_object_t * w )
+{
+ // nothing
+}
+
+hb_work_object_t hb_decutf8sub =
+{
+ WORK_DECUTF8SUB,
+ "UTF-8 Subtitle Decoder",
+ decutf8Init,
+ decutf8Work,
+ decutf8Close
+};