-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmediacastsegmenter_patch_1_0_2.diff
More file actions
86 lines (78 loc) · 3.2 KB
/
mediacastsegmenter_patch_1_0_2.diff
File metadata and controls
86 lines (78 loc) · 3.2 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: segmenter.c
===================================================================
--- segmenter.c (revision 50)
+++ segmenter.c (working copy)
@@ -239,7 +239,7 @@
exit(1);
}
- ofmt = guess_format("mpegts", NULL, NULL);
+ ofmt = av_guess_format("mpegts", NULL, NULL);
if (!ofmt) {
fprintf(stderr, "Could not find MPEG-TS muxer\n");
exit(1);
@@ -251,6 +251,9 @@
exit(1);
}
oc->oformat = ofmt;
+
+ // Don't print warnings when PTS and DTS are identical.
+ ic->flags |= AVFMT_FLAG_IGNDTS;
video_index = -1;
audio_index = -1;
@@ -289,6 +292,12 @@
fprintf(stderr, "Could not open video decoder, key frames will not be honored\n");
}
+ if (video_st->codec->ticks_per_frame > 1) {
+ // h264 sets the ticks_per_frame and time_base.den but not time_base.num
+ // since we don't use ticks_per_frame, adjust time_base.num accordingly.
+ video_st->codec->time_base.num *= video_st->codec->ticks_per_frame;
+ }
+
snprintf(output_filename, strlen(output_prefix) + 15, "%s-%u.ts", output_prefix, output_index++);
if (url_fopen(&oc->pb, output_filename, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", output_filename);
@@ -302,6 +311,10 @@
write_index = !write_index_file(index, tmp_index, segment_duration, output_prefix, http_prefix, first_segment, last_segment, 0, max_tsfiles);
+ // Track initial PTS values so we can subtract them out (removing aduio/video delay, since they seem incorrect).
+ int64_t initial_audio_pts = -1;
+ int64_t initial_video_pts = -1;
+
do {
double segment_time;
AVPacket packet;
@@ -317,14 +330,22 @@
break;
}
- if (packet.stream_index == video_index && (packet.flags & PKT_FLAG_KEY)) {
- segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
- }
- else if (video_index < 0) {
- segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
- }
- else {
+ if (packet.stream_index == video_index) {
+ if (initial_video_pts < 0) initial_video_pts = packet.pts;
+ packet.pts -= initial_video_pts;
+ packet.dts = packet.pts;
+ if (packet.flags & AV_PKT_FLAG_KEY) {
+ segment_time = (double)packet.pts * video_st->time_base.num / video_st->time_base.den;
+ } else {
+ segment_time = prev_segment_time;
+ }
+ } else if (packet.stream_index == audio_index) {
+ if (initial_audio_pts < 0) initial_audio_pts = packet.pts;
+ packet.pts -= initial_audio_pts;
+ packet.dts = packet.pts;
segment_time = prev_segment_time;
+ } else {
+ segment_time = prev_segment_time;
}
if (segment_time - prev_segment_time >= segment_duration) {
@@ -357,7 +378,7 @@
prev_segment_time = segment_time;
}
- ret = av_interleaved_write_frame(oc, &packet);
+ ret = av_write_frame(oc, &packet);
if (ret < 0) {
fprintf(stderr, "Warning: Could not write frame of stream\n");
}