comparison libmpdemux/demux_mkv.c @ 27518:e54c9b7eb0d8

Revert bad changes to SSA/ASS subtitle packet format The following commits are reverted partially or completely: "a valid ASS line contains 9 ',' before actual text" "demux_mkv: output correctly formated ASS packets" "libass: add a new ass_process_data() to process demuxed subtitle packets" These commits converted the internal representation of SSA/ASS subtitle packets from the format used by Matroska to a custom format where each packet has contents exactly matching one line in complete SSA script files. AFAIK no files natively use such a format for muxed subtitles. The stated reason for this change was to use a format that could in principle be muxed into a maximal number of containers. SSA subtitles do not have an implicit duration so both start time and duration or end time need to be specified explicitly; the new format moved timing information inside the codec packet data so it could be muxed without modification into containers that can represent only start time at the container level. However such a change is wrong from the viewpoint of program architecture. Timing information belongs to the demuxer level, but these commits moved not only the duration but also the authoritative value of the start time to inside the codec data. Additionally the new format lost the value of the Matroska ReadOrder field which is used by MPlayer. This commit changes the internal packet format back to that used by Matroska and makes the internal Matroska demuxer output that format again. Libavformat still outputs the "new" format; it could be converted back to the Matroska format in demux_lavf.c, but I'm not adding that code at least yet. The current lavf code has similar problems as the reverted code in MPlayer, and it also currently fails to provide any way to access the value of the ReadOrder field. I hope that the lavf side will be improved; if it isn't conversion can be added later. For now I'll make MPlayer default to the internal Matroska demuxer instead of the lavf one in a separate commit.
author uau
date Mon, 08 Sep 2008 21:26:22 +0000
parents ed77f7dee121
children 3ac3d3a51934
comparison
equal deleted inserted replaced
27517:af91c1e34603 27518:e54c9b7eb0d8
2564 } 2564 }
2565 *all_lace_sizes = lace_size; 2565 *all_lace_sizes = lace_size;
2566 return 0; 2566 return 0;
2567 } 2567 }
2568 2568
2569 static void fix_ass_packet(char **block, int64_t *size,
2570 uint64_t block_duration, uint64_t timecode)
2571 {
2572 char *line, *layer, *ptr = *block, *end = ptr+*size;
2573 *end = 0;
2574 for (; *ptr!=',' && ptr<end-1; ptr++);
2575 if (*ptr == ',')
2576 layer = ++ptr;
2577 for (; *ptr!=',' && ptr<end-1; ptr++);
2578 if (*ptr == ',') {
2579 int64_t end_pts = timecode + block_duration;
2580 int sc = timecode / 10;
2581 int ec = end_pts / 10;
2582 int sh, sm, ss, eh, em, es, len;
2583 sh = sc/360000; sc -= 360000*sh;
2584 sm = sc/ 6000; sc -= 6000*sm;
2585 ss = sc/ 100; sc -= 100*ss;
2586 eh = ec/360000; ec -= 360000*eh;
2587 em = ec/ 6000; ec -= 6000*em;
2588 es = ec/ 100; ec -= 100*es;
2589 *ptr++ = '\0';
2590 len = 50 + end-ptr;
2591 if (!(line = malloc(len)))
2592 return;
2593 snprintf(line,len,"Dialogue: %s,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s",
2594 layer, sh, sm, ss, sc, eh, em, es, ec, ptr);
2595 *block = line;
2596 *size = strlen(line);
2597 }
2598 }
2599
2600 static void 2569 static void
2601 handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block, 2570 handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block,
2602 int64_t size, uint64_t block_duration, uint64_t timecode) 2571 int64_t size, uint64_t block_duration, uint64_t timecode)
2603 { 2572 {
2604 char *data = block;
2605 demux_packet_t *dp; 2573 demux_packet_t *dp;
2606 2574
2607 if (block_duration == 0) 2575 if (block_duration == 0)
2608 { 2576 {
2609 mp_msg (MSGT_DEMUX, MSGL_WARN, 2577 mp_msg (MSGT_DEMUX, MSGL_WARN,
2610 MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound); 2578 MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound);
2611 return; 2579 return;
2612 } 2580 }
2613 2581
2614 if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
2615 fix_ass_packet(&data, &size, block_duration, timecode);
2616
2617 sub_utf8 = 1; 2582 sub_utf8 = 1;
2618 dp = new_demux_packet(size); 2583 dp = new_demux_packet(size);
2619 memcpy(dp->buffer, data, size); 2584 memcpy(dp->buffer, block, size);
2620 dp->pts = timecode / 1000.0f; 2585 dp->pts = timecode / 1000.0f;
2621 dp->endpts = (timecode + block_duration) / 1000.0f; 2586 dp->endpts = (timecode + block_duration) / 1000.0f;
2622 ds_add_packet(demuxer->sub, dp); 2587 ds_add_packet(demuxer->sub, dp);
2623 if (data != block)
2624 free(data);
2625 } 2588 }
2626 2589
2627 // Taken from demux_real.c. Thanks to the original developpers :) 2590 // Taken from demux_real.c. Thanks to the original developpers :)
2628 #define SKIP_BITS(n) buffer <<= n 2591 #define SKIP_BITS(n) buffer <<= n
2629 #define SHOW_BITS(n) ((buffer) >> (32 - (n))) 2592 #define SHOW_BITS(n) ((buffer) >> (32 - (n)))