This repository was archived by the owner on Apr 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpeg-bugfix.diff
More file actions
86 lines (80 loc) · 2.82 KB
/
Copy pathffmpeg-bugfix.diff
File metadata and controls
86 lines (80 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Index: libavformat/ogg2.c
===================================================================
--- libavformat/ogg2.c (revision 10293)
+++ libavformat/ogg2.c (working copy)
@@ -466,8 +466,9 @@
ogg_get_length (AVFormatContext * s)
{
ogg_t *ogg = s->priv_data;
- int idx = -1, i;
- offset_t size, end;
+ int i, streams_found;
+ offset_t size, search_start, search_end;
+ int64_t duration;
if(s->pb.is_streamed)
return 0;
@@ -479,33 +480,49 @@
size = url_fsize(&s->pb);
if(size < 0)
return 0;
- end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size;
+ search_start = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size;
+ search_end = size;
ogg_save (s);
- url_fseek (&s->pb, end, SEEK_SET);
- while (!ogg_read_page (s, &i)){
- if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
- ogg->streams[i].codec)
- idx = i;
- }
+ /* Seek back from the end of the file until we find the duration of all of the streams */
+ streams_found = 0;
+ while (streams_found < ogg->nstreams && search_start > 0) {
+ url_fseek (&s->pb, search_start, SEEK_SET);
+ while (!ogg_read_page (s, &i) && url_ftell (&s->pb) < search_end) {
+ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
+ ogg->streams[i].codec)
+ {
+ duration = ogg_gptopts (s, i, ogg->streams[i].granule);
+ if (s->streams[i]->duration == AV_NOPTS_VALUE) {
+ s->streams[i]->duration = duration;
+ streams_found++;
+ } else if (duration > s->streams[i]->duration) {
+ s->streams[i]->duration = duration;
+ }
+ }
+ }
+ search_start -= MAX_PAGE_SIZE;
+ search_end -= MAX_PAGE_SIZE;
+ }
- if (idx != -1){
- s->streams[idx]->duration =
- ogg_gptopts (s, idx, ogg->streams[idx].granule);
- }
+ ogg->size = size;
- ogg->size = size;
+ /* Go back to the start and find the start time for each stream */
ogg_restore (s, 0);
ogg_save (s);
- while (!ogg_read_page (s, &i)) {
- if (i == idx && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0)
- break;
- }
- if (i == idx) {
- s->streams[idx]->start_time = ogg_gptopts (s, idx, ogg->streams[idx].granule);
- s->streams[idx]->duration -= s->streams[idx]->start_time;
- }
+ streams_found = 0;
+ /* Reset the start time to AV_NOPTS_VALUE, just in case it isn't already */
+ for (i = 0; i < ogg->nstreams; i++) {
+ s->streams[i]->start_time = AV_NOPTS_VALUE;
+ }
+ while (!ogg_read_page (s, &i) && streams_found < ogg->nstreams) {
+ if (s->streams[i]->start_time == AV_NOPTS_VALUE && ogg->streams[i].granule != -1) {
+ streams_found++;
+ s->streams[i]->start_time = ogg_gptopts (s, i, ogg->streams[i].granule);
+ s->streams[i]->duration -= s->streams[i]->start_time;
+ }
+ }
ogg_restore (s, 0);
return 0;