8
8
exactly the same encoding parameters (in the case of h264, the SPS/PPS have to be the same).
9
9
*/
10
10
11
+ function getRequestParams ()
12
+ {
13
+ $ scriptParts = explode ('/ ' , $ _SERVER ['SCRIPT_NAME ' ]);
14
+ $ pathParts = array ();
15
+ if (isset ($ _SERVER ['PHP_SELF ' ]))
16
+ $ pathParts = explode ('/ ' , $ _SERVER ['PHP_SELF ' ]);
17
+ $ pathParts = array_diff ($ pathParts , $ scriptParts );
18
+
19
+ $ params = array ();
20
+ reset ($ pathParts );
21
+ while (current ($ pathParts ))
22
+ {
23
+ $ key = each ($ pathParts );
24
+ $ value = each ($ pathParts );
25
+ if (!array_key_exists ($ key ['value ' ], $ params ))
26
+ {
27
+ $ params [$ key ['value ' ]] = $ value ['value ' ];
28
+ }
29
+ }
30
+ return $ params ;
31
+ }
32
+
33
+ $ params = getRequestParams ();
34
+ $ discontinuity = (isset ($ params ['disc ' ]) && $ params ['disc ' ]) ? true : false ;
35
+ $ playlistType = isset ($ params ['type ' ]) ? $ params ['type ' ] : "live " ;
36
+
11
37
// input params
12
- $ playlistType = "live " ; // live / vod
13
- $ discontinuity = true ;
14
38
$ filePaths = array (
15
39
"/path/to/video1.mp4 " ,
16
40
"/path/to/video2.mp4 " ,
17
41
"/path/to/video3.mp4 " ,
18
42
);
19
- $ ffprobeBin = '/path/to/ffprobe.sh ' ;
43
+ if (!$ discontinuity )
44
+ {
45
+ $ filePaths = array ($ filePaths [0 ], $ filePaths [0 ]);
46
+ }
47
+ $ ffprobeBin = '/web/content/shared/bin/ffmpeg-2.7.2-bin/ffprobe.sh ' ;
20
48
$ timeMargin = 10000 ; // a safety margin to compensate for clock differences
21
49
22
50
// nginx conf params
@@ -86,18 +114,19 @@ function getDurationMillis($filePath)
86
114
87
115
// start the playlist from now() - <dvr window size>
88
116
$ currentTime = time () * 1000 - $ timeMargin - $ dvrWindowSize ;
89
-
90
- // set the first clip time to now() rounded down to cycle duration
91
- $ result ["firstClipTime " ] = floor ($ currentTime / $ cycleDuration ) * $ cycleDuration ;
92
-
93
- // get the reference time (the first clip time of the first run)
117
+
118
+ // get the reference time (the time of the first run)
94
119
$ referenceTime = apc_fetch ('reference_time ' );
95
120
if (!$ referenceTime )
96
121
{
97
- $ referenceTime = $ result [ " firstClipTime " ] ;
122
+ $ referenceTime = $ currentTime ;
98
123
apc_store ('reference_time ' , $ referenceTime );
99
124
}
100
-
125
+
126
+ // set the first clip time to now() rounded down to cycle duration
127
+ $ cycleIndex = floor (($ currentTime - $ referenceTime ) / $ cycleDuration );
128
+ $ result ["firstClipTime " ] = $ referenceTime + $ cycleIndex * $ cycleDuration ;
129
+
101
130
if ($ discontinuity )
102
131
{
103
132
// find the total number of segments in each cycle
@@ -108,7 +137,6 @@ function getDurationMillis($filePath)
108
137
}
109
138
110
139
// find the initial clip index and initial segment index
111
- $ cycleIndex = floor (($ currentTime - $ referenceTime ) / $ cycleDuration );
112
140
$ result ["initialClipIndex " ] = $ cycleIndex * count ($ durations ) + 1 ;
113
141
$ result ["initialSegmentIndex " ] = $ cycleIndex * $ totalSegmentCount + 1 ;
114
142
}
0 commit comments