[xiph-commits] r16862 - trunk/ffmpeg2theora/src
j at svn.xiph.org
j at svn.xiph.org
Sun Jan 31 22:30:43 PST 2010
Author: j
Date: 2010-01-31 22:30:42 -0800 (Sun, 31 Jan 2010)
New Revision: 16862
Modified:
trunk/ffmpeg2theora/src/ffmpeg2theora.c
trunk/ffmpeg2theora/src/theorautils.c
trunk/ffmpeg2theora/src/theorautils.h
Log:
add kate index support, thanks ogg.k
Modified: trunk/ffmpeg2theora/src/ffmpeg2theora.c
===================================================================
--- trunk/ffmpeg2theora/src/ffmpeg2theora.c 2010-01-31 11:35:13 UTC (rev 16861)
+++ trunk/ffmpeg2theora/src/ffmpeg2theora.c 2010-02-01 06:30:42 UTC (rev 16862)
@@ -89,6 +89,7 @@
INDEX_INTERVAL,
THEORA_INDEX_RESERVE,
VORBIS_INDEX_RESERVE,
+ KATE_INDEX_RESERVE,
INFO_FLAG
} F2T_FLAGS;
@@ -1955,7 +1956,8 @@
" --index-interval <n> set minimum distance between indexed keyframes\n"
" to <n> ms (default: 2000)\n"
" --theora-index-reserve <n> reserve <n> bytes for theora keyframe index\n"
- " --vorbis-index-reserve <n> reserve <n> bytes for vorbis keyframe indes\n"
+ " --vorbis-index-reserve <n> reserve <n> bytes for vorbis keyframe index\n"
+ " --kate-index-reserve <n> reserve <n> bytes for kate keyframe index\n"
"\n"
"Other options:\n"
#ifndef _WIN32
@@ -2017,6 +2019,7 @@
{"index-interval",required_argument,&flag,INDEX_INTERVAL},
{"theora-index-reserve",required_argument,&flag,THEORA_INDEX_RESERVE},
{"vorbis-index-reserve",required_argument,&flag,VORBIS_INDEX_RESERVE},
+ {"kate-index-reserve",required_argument,&flag,KATE_INDEX_RESERVE},
{"format",required_argument,NULL,'f'},
{"width",required_argument,NULL,'x'},
{"height",required_argument,NULL,'y'},
@@ -2290,6 +2293,10 @@
info.vorbis_index_reserve = atoi(optarg);
flag = -1;
break;
+ case KATE_INDEX_RESERVE:
+ info.kate_index_reserve = atoi(optarg);
+ flag = -1;
+ break;
case INFO_FLAG:
output_json = 1;
break;
Modified: trunk/ffmpeg2theora/src/theorautils.c
===================================================================
--- trunk/ffmpeg2theora/src/theorautils.c 2010-01-31 11:35:13 UTC (rev 16861)
+++ trunk/ffmpeg2theora/src/theorautils.c 2010-02-01 06:30:42 UTC (rev 16862)
@@ -68,6 +68,7 @@
info->index_interval = 2000;
info->theora_index_reserve = -1;
info->vorbis_index_reserve = -1;
+ info->kate_index_reserve = -1;
info->indexing_complete = 0;
info->frontend = NULL; /*frontend mode*/
info->videotime = 0;
@@ -121,6 +122,7 @@
ks->katepage_buffer_length = 0;
ks->katepage = NULL;
ks->katetime = 0;
+ ks->last_end_time = -1;
}
}
@@ -203,18 +205,37 @@
static ogg_int64_t index_start_time(oggmux_info* info)
{
+ ogg_int64_t start_time;
+ int n;
+
if (!info->with_seek_index || !info->indexing_complete) {
return -1;
}
- return MIN(info->theora_index.start_time, info->vorbis_index.start_time);
+
+ start_time = MIN(info->theora_index.start_time, info->vorbis_index.start_time);
+ for (n=0; n<info->n_kate_streams; ++n) {
+ oggmux_kate_stream *ks=info->kate_streams+n;
+ if (ks->index.start_time < start_time)
+ start_time = ks->index.start_time;
+ }
+ return start_time;
}
static ogg_int64_t index_end_time(oggmux_info* info)
{
+ ogg_int64_t end_time;
+ int n;
+
if (!info->with_seek_index || !info->indexing_complete) {
return -1;
}
- return MAX(info->theora_index.end_time, info->vorbis_index.end_time);
+ end_time = MAX(info->theora_index.end_time, info->vorbis_index.end_time);
+ for (n=0; n<info->n_kate_streams; ++n) {
+ oggmux_kate_stream *ks=info->kate_streams+n;
+ if (ks->index.end_time > end_time)
+ end_time = ks->index.end_time;
+ }
+ return end_time;
}
static ogg_int64_t output_file_length(oggmux_info* info)
@@ -516,7 +537,8 @@
const char* name,
oggmux_info *info,
ogg_uint32_t serialno,
- int target_packet)
+ int target_packet,
+ int num_headers)
{
ogg_packet op;
ogg_page og;
@@ -525,7 +547,7 @@
int result;
int num_keypoints;
int packetno;
- int last_packetno = 2; /* Take into account header packets... */
+ int last_packetno = num_headers-1; /* Take into account header packets... */
keypoint* keypoints = 0;
int pageno = 0;
int prev_keyframe_pageno = -INT_MAX;
@@ -722,7 +744,8 @@
"theora",
info,
info->to.serialno,
- 1) == -1)
+ 1,
+ 3) == -1)
{
return -1;
}
@@ -731,14 +754,22 @@
"vorbis",
info,
info->vo.serialno,
- 2) == -1)
+ 2,
+ 3) == -1)
{
return -1;
}
#ifdef HAVE_KATE
if (info->with_kate) {
- /* TODO: Add indexing for Kate. */
+ int n;
+ for (n=0; n<info->n_kate_streams; ++n) {
+ oggmux_kate_stream *ks=info->kate_streams+n;
+ if (write_index_pages(&ks->index, "kate", info, ks->ko.serialno, 1, ks->ki.num_headers) == -1)
+ {
+ return -1;
+ }
+ }
}
#endif
@@ -774,7 +805,19 @@
#ifdef HAVE_KATE
if (info->with_kate) {
- /* TODO: Add indexing for Kate. */
+ int n;
+ for (n=0; n<info->n_kate_streams; ++n) {
+ oggmux_kate_stream *ks=info->kate_streams+n;
+ if (info->kate_index_reserve != -1) {
+ ks->index.packet_size = info->kate_index_reserve;
+ }
+ if (write_index_placeholder_for_stream(info,
+ &ks->index,
+ ks->ko.serialno) == -1)
+ {
+ return -1;
+ }
+ }
}
#endif
@@ -847,6 +890,8 @@
exit(1);
}
kate_comment_add_tag (&ks->kc, "ENCODER",PACKAGE_STRING);
+
+ seek_index_init(&ks->index, info->index_interval);
}
#endif
}
@@ -1258,6 +1303,15 @@
}
+static void oggmux_record_kate_index(oggmux_info *info, oggmux_kate_stream *ks, const ogg_packet *op, ogg_int64_t start_time, ogg_int64_t end_time)
+{
+ if (ks->last_end_time >= 0)
+ start_time = ks->last_end_time;
+
+ seek_index_record_sample(&ks->index, op->packetno, start_time, end_time, 1);
+ ks->last_end_time = end_time;
+}
+
/**
* adds a subtitles text to the encoding sink
* if e_o_s is 1 the end of the logical bitstream will be marked.
@@ -1275,13 +1329,15 @@
int ret;
ret = kate_ogg_encode_text(&ks->k, t0, t1, text, len, &op);
if (ret>=0) {
+ if (info->with_seek_index && info->passno != 1) {
+ ogg_int64_t start_time = (int)(t0 * 1000.0f + 0.5f);
+ ogg_int64_t end_time = (int)(t1 * 1000.0f + 0.5f);
+ oggmux_record_kate_index(info, ks, &op, start_time, end_time);
+ }
+
ogg_stream_packetin (&ks->ko, &op);
ogg_packet_clear (&op);
info->k_pkg++;
-
-#ifdef HAVE_KATE
- /* TODO: Add indexing for Kate. */
-#endif
}
else {
fprintf(stderr, "Failed to encode kate data packet (%f --> %f, [%s]): %d\n",
@@ -1303,6 +1359,11 @@
int ret;
ret = kate_ogg_encode_finish(&ks->k, t, &op);
if (ret>=0) {
+ if (info->with_seek_index && info->passno != 1) {
+ ogg_int64_t start_time = floorf(t * 1000.0f + 0.5f);
+ ogg_int64_t end_time = start_time;
+ oggmux_record_kate_index(info, ks, &op, start_time, end_time);
+ }
ogg_stream_packetin (&ks->ko, &op);
ogg_packet_clear (&op);
info->k_pkg++;
@@ -1490,6 +1551,8 @@
{
int ret;
oggmux_kate_stream *ks=info->kate_streams+idx;
+ ogg_int64_t page_offset = ftello(info->outfile);
+ int packet_start_num = ogg_page_start_packets(ks->katepage);
ret = fwrite(ks->katepage, 1, ks->katepage_len, info->outfile);
if (ret < ks->katepage_len) {
@@ -1500,6 +1563,12 @@
}
ks->katepage_valid = 0;
info->k_pkg -= ogg_page_packets((ogg_page *)&ks->katepage);
+
+ ret = seek_index_record_page(&ks->index,
+ page_offset,
+ packet_start_num);
+ assert(ret == 0);
+
#ifdef OGGMUX_DEBUG
info->k_page++;
fprintf(stderr,"\nkate page %d (%d pkgs) | pkg remaining %d\n",info->k_page,ogg_page_packets((ogg_page *)&ks->katepage),info->k_pkg);
Modified: trunk/ffmpeg2theora/src/theorautils.h
===================================================================
--- trunk/ffmpeg2theora/src/theorautils.h 2010-01-31 11:35:13 UTC (rev 16861)
+++ trunk/ffmpeg2theora/src/theorautils.h 2010-02-01 06:30:42 UTC (rev 16862)
@@ -53,6 +53,8 @@
int katepage_len;
int katepage_buffer_length;
double katetime;
+ seek_index index;
+ ogg_int64_t last_end_time;
}
oggmux_kate_stream;
@@ -78,6 +80,7 @@
int index_interval;
int theora_index_reserve;
int vorbis_index_reserve;
+ int kate_index_reserve;
int indexing_complete;
FILE *frontend;
/* vorbis settings */
More information about the commits
mailing list