-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_GXF_DAR.patch
126 lines (119 loc) · 4.94 KB
/
01_GXF_DAR.patch
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 12031f7..aae90b3 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -59,6 +59,7 @@ typedef struct GXFStreamContext {
int p_per_gop;
int b_per_i_or_p; ///< number of B frames per I frame or P frame
int first_gop_closed;
+ int aspect_ratio; ///< display aspect ratio: 0 => 4:3, 1 => 16:9
unsigned order; ///< interleaving order
} GXFStreamContext;
@@ -206,10 +207,10 @@ static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st)
starting_line = 23; // default PAL
size = snprintf(buffer, sizeof(buffer), "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n"
- "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n",
+ "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\nar %d\n",
(float)st->codec->bit_rate, sc->p_per_gop, sc->b_per_i_or_p,
st->codec->pix_fmt == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1,
- starting_line, (st->codec->height + 15) / 16);
+ starting_line, (st->codec->height + 15) / 16, sc->aspect_ratio);
av_assert0(size < sizeof(buffer));
avio_w8(pb, TRACK_MPG_AUX);
avio_w8(pb, size + 1);
@@ -219,12 +220,25 @@ static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st)
static int gxf_write_dv_auxiliary(AVIOContext *pb, AVStream *st)
{
+ GXFStreamContext *sc = st->priv_data;
int64_t track_aux_data = 0;
avio_w8(pb, TRACK_AUX);
avio_w8(pb, 8);
- if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P)
- track_aux_data |= 0x01; /* marks stream as DVCAM instead of DVPRO */
+
+ switch (sc->track_type) {
+ case 5:
+ if (sc->aspect_ratio)
+ track_aux_data |= 0x10; /* 16:9 */
+ if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P)
+ track_aux_data |= 0x01; /* marks stream as DVCAM instead of DVPRO */
+ break;
+ case 6:
+ if (sc->aspect_ratio)
+ track_aux_data |= 0x01; /* 16:9 (this bit flag's location is different than that used with track type 5) */
+ break;
+ }
+
track_aux_data |= 0x40000000; /* aux data is valid */
avio_wl64(pb, track_aux_data);
return 8;
@@ -521,6 +535,7 @@ static int gxf_write_umf_track_description(AVFormatContext *s)
static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st)
{
GXFStreamContext *sc = st->priv_data;
+ int mpeg_flags = 0;
if (st->codec->pix_fmt == AV_PIX_FMT_YUV422P)
avio_wl32(pb, 2);
@@ -531,12 +546,20 @@ static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st)
avio_wl32(pb, 1); /* I picture per GOP */
avio_wl32(pb, sc->p_per_gop);
avio_wl32(pb, sc->b_per_i_or_p);
+
if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO)
- avio_wl32(pb, 2);
+ mpeg_flags = 2;
else if (st->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO)
- avio_wl32(pb, 1);
+ mpeg_flags = 1;
else
- avio_wl32(pb, 0);
+ mpeg_flags = 0;
+
+ if (sc->aspect_ratio)
+ mpeg_flags |= 0x0080; /* 16:9 */
+ else
+ mpeg_flags |= 0x0040; /* 4:3 */
+
+ avio_wl32(pb, mpeg_flags);
avio_wl32(pb, 0); /* reserved */
return 32;
}
@@ -558,6 +581,11 @@ static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc, AVStrea
{
int dv_umf_data = 0;
+ if (sc->aspect_ratio)
+ dv_umf_data |= 0x80; /* 16:9 */
+ else
+ dv_umf_data |= 0x40; /* 4:3 */
+
if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P)
dv_umf_data |= 0x20; /* marks as DVCAM instead of DVPRO */
avio_wl32(pb, dv_umf_data);
@@ -706,8 +734,9 @@ static int gxf_write_header(AVFormatContext *s)
AVIOContext *pb = s->pb;
GXFContext *gxf = s->priv_data;
GXFStreamContext *vsc = NULL;
+ AVRational display_aspect_ratio;
uint8_t tracks[255] = {0};
- int i, media_info = 0;
+ int i, sans_vbi_height, media_info = 0;
int ret;
AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
@@ -753,6 +782,17 @@ static int gxf_write_header(AVFormatContext *s)
av_log(s, AV_LOG_ERROR, "video stream must be the first track\n");
return -1;
}
+
+ if (st->codec->height == 608 || st->codec->height == 512) /* VBI */
+ sans_vbi_height = st->codec->height - 32;
+ else
+ sans_vbi_height = st->codec->height;
+ av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
+ st->codec->width*st->sample_aspect_ratio.num,
+ sans_vbi_height*st->sample_aspect_ratio.den,
+ 1024*1024);
+ sc->aspect_ratio = (fabs(av_q2d(display_aspect_ratio)) >= 1.777);
+
/* FIXME check from time_base ? */
if (st->codec->height == 480 || st->codec->height == 512) { /* NTSC or NTSC+VBI */
sc->frame_rate_index = 5;