forked from datarhei/ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FFmpeg-devel-06-13-avformat-flvenc-refactor-fourcc-writing.diff
147 lines (138 loc) · 6.3 KB
/
FFmpeg-devel-06-13-avformat-flvenc-refactor-fourcc-writing.diff
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 13e06aedbb..94d633fbca 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -492,6 +492,45 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
avio_wb32(pb, flv->metadata_totalsize + 11);
}
+static void write_codec_fourcc(AVIOContext *pb, enum AVCodecID codec_id)
+{
+ switch (codec_id) {
+ case AV_CODEC_ID_AAC:
+ avio_write(pb, "mp4a", 4);
+ return;
+ case AV_CODEC_ID_OPUS:
+ avio_write(pb, "Opus", 4);
+ return;
+ case AV_CODEC_ID_FLAC:
+ avio_write(pb, "fLaC", 4);
+ return;
+ case AV_CODEC_ID_MP3:
+ avio_write(pb, ".mp3", 4);
+ return;
+ case AV_CODEC_ID_AC3:
+ avio_write(pb, "ac-3", 4);
+ return;
+ case AV_CODEC_ID_EAC3:
+ avio_write(pb, "ec-3", 4);
+ return;
+ case AV_CODEC_ID_H264:
+ avio_write(pb, "avc1", 4);
+ return;
+ case AV_CODEC_ID_HEVC:
+ avio_write(pb, "hvc1", 4);
+ return;
+ case AV_CODEC_ID_AV1:
+ avio_write(pb, "av01", 4);
+ return;
+ case AV_CODEC_ID_VP9:
+ avio_write(pb, "vp09", 4);
+ return;
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Invalid codec FourCC write requested.\n");
+ av_assert0(0);
+ }
+}
+
static void flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par, unsigned int ts, int stream_idx)
{
AVIOContext *pb = s->pb;
@@ -528,13 +567,8 @@ static void flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par
put_timestamp(pb, ts); //ts = pkt->dts, gen
avio_wb24(pb, flv->reserved);
- if (par->codec_id == AV_CODEC_ID_HEVC) {
- avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata| FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with PacketTypeMetadata
- avio_write(pb, "hvc1", 4);
- } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) {
- avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata| FLV_FRAME_VIDEO_INFO_CMD);
- avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01" : "vp09", 4);
- }
+ avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata | FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with PacketTypeMetadata
+ write_codec_fourcc(pb, par->codec_id);
avio_w8(pb, AMF_DATA_TYPE_STRING);
put_amf_string(pb, "colorInfo");
@@ -703,24 +737,14 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
if (extended_flv) {
avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeSequenceStart);
+ write_codec_fourcc(pb, par->codec_id);
if (par->codec_id == AV_CODEC_ID_AAC) {
- avio_write(pb, "mp4a", 4);
flv_write_aac_header(s, par);
- } else if (par->codec_id == AV_CODEC_ID_OPUS) {
- avio_write(pb, "Opus", 4);
+ } else if (par->codec_id == AV_CODEC_ID_OPUS || par->codec_id == AV_CODEC_ID_FLAC) {
av_assert0(par->extradata_size);
avio_write(pb, par->extradata, par->extradata_size);
- } else if (par->codec_id == AV_CODEC_ID_FLAC) {
- avio_write(pb, "fLaC", 4);
- av_assert0(par->extradata_size);
- avio_write(pb, par->extradata, par->extradata_size);
- } else if (par->codec_id == AV_CODEC_ID_MP3)
- avio_write(pb, ".mp3", 4);
- else if (par->codec_id == AV_CODEC_ID_AC3)
- avio_write(pb, "ac-3", 4);
- else if (par->codec_id == AV_CODEC_ID_EAC3)
- avio_write(pb, "ec-3", 4);
+ }
} else if (par->codec_id == AV_CODEC_ID_AAC) {
avio_w8(pb, get_audio_flags(s, par));
avio_w8(pb, 0); // AAC sequence header
@@ -743,14 +767,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart | FLV_FRAME_KEY);
}
- if (par->codec_id == AV_CODEC_ID_H264)
- avio_write(pb, "avc1", 4);
- else if (par->codec_id == AV_CODEC_ID_HEVC)
- avio_write(pb, "hvc1", 4);
- else if (par->codec_id == AV_CODEC_ID_AV1)
- avio_write(pb, "av01", 4);
- else if (par->codec_id == AV_CODEC_ID_VP9)
- avio_write(pb, "vp09", 4);
+ write_codec_fourcc(pb, par->codec_id);
if (track_idx)
avio_w8(pb, track_idx);
@@ -1240,14 +1257,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_w8(pb, FLV_IS_EX_HEADER | pkttype | frametype);
}
- if (par->codec_id == AV_CODEC_ID_H264)
- avio_write(pb, "avc1", 4);
- else if (par->codec_id == AV_CODEC_ID_HEVC)
- avio_write(pb, "hvc1", 4);
- else if (par->codec_id == AV_CODEC_ID_AV1)
- avio_write(pb, "av01", 4);
- else if (par->codec_id == AV_CODEC_ID_VP9)
- avio_write(pb, "vp09", 4);
+ write_codec_fourcc(pb, par->codec_id);
if (track_idx)
avio_w8(pb, track_idx);
@@ -1255,19 +1265,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_wb24(pb, pkt->pts - pkt->dts);
} else if (extended_audio) {
avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeCodedFrames);
-
- if (par->codec_id == AV_CODEC_ID_AAC)
- avio_write(pb, "mp4a", 4);
- else if (par->codec_id == AV_CODEC_ID_OPUS)
- avio_write(pb, "Opus", 4);
- else if (par->codec_id == AV_CODEC_ID_FLAC)
- avio_write(pb, "fLaC", 4);
- else if (par->codec_id == AV_CODEC_ID_MP3)
- avio_write(pb, ".mp3", 4);
- else if (par->codec_id == AV_CODEC_ID_AC3)
- avio_write(pb, "ac-3", 4);
- else if (par->codec_id == AV_CODEC_ID_EAC3)
- avio_write(pb, "ec-3", 4);
+ write_codec_fourcc(pb, par->codec_id);
} else {
av_assert1(flags>=0);
avio_w8(pb, flags);