History

avformat/yuv4mpegenc: simplify writing the header

Actually write it in yuv4_write_header() instead of with the first packet.

James Almer committed 6 years ago

Commit f901d751 parent 2c0d6ac1 file · +14 −21Browse files

Unified · Split

libavformat/yuv4mpegenc.c+14−21
@@ -26,14 +26,16 @@ · 25 unmodified lines
26 26
27#define Y4M_LINE_MAX 25627#define Y4M_LINE_MAX 256
28 28
29static int yuv4_generate_header(AVFormatContext *s, char* buf)29static int yuv4_write_header(AVFormatContext *s)
30{30{
31 AVStream *st;31 AVStream *st;
32 AVIOContext *pb = s->pb;
32 int width, height;33 int width, height;
33 int raten, rated, aspectn, aspectd, n;34 int raten, rated, aspectn, aspectd, n;
34 char inter;35 char inter;
35 const char *colorspace = "";36 const char *colorspace = "";
36 const char *colorrange = "";37 const char *colorrange = "";
38 char buf[Y4M_LINE_MAX + 1];
37 int field_order;39 int field_order;
38 40
39 st = s->streams[0];41 st = s->streams[0];
@@ -173,7 +175,15 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf) · 133 unmodified lines
173 Y4M_MAGIC, width, height, raten, rated, inter,175 Y4M_MAGIC, width, height, raten, rated, inter,
174 aspectn, aspectd, colorspace, colorrange);176 aspectn, aspectd, colorspace, colorrange);
175 177
176 return n;178 if (n < 0) {
179 av_log(s, AV_LOG_ERROR,
180 "Error. YUV4MPEG stream header write failed.\n");
181 return AVERROR(EIO);
182 }
183
184 avio_write(pb, buf, strlen(buf));
185
186 return 0;
177}187}
178 188
179 189
@@ -182,26 +192,12 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) · 2 unmodified lines
182 AVStream *st = s->streams[pkt->stream_index];192 AVStream *st = s->streams[pkt->stream_index];
183 AVIOContext *pb = s->pb;193 AVIOContext *pb = s->pb;
184 AVFrame *frame;194 AVFrame *frame;
185 int* first_pkt = s->priv_data;
186 int width, height, h_chroma_shift, v_chroma_shift;195 int width, height, h_chroma_shift, v_chroma_shift;
187 int i;196 int i;
188 char buf2[Y4M_LINE_MAX + 1];
189 uint8_t *ptr, *ptr1, *ptr2;197 uint8_t *ptr, *ptr1, *ptr2;
190 198
191 frame = (AVFrame *)pkt->data;199 frame = (AVFrame *)pkt->data;
192 200
193 /* for the first packet we have to output the header as well */
194 if (*first_pkt) {
195 *first_pkt = 0;
196 if (yuv4_generate_header(s, buf2) < 0) {
197 av_log(s, AV_LOG_ERROR,
198 "Error. YUV4MPEG stream header write failed.\n");
199 return AVERROR(EIO);
200 } else {
201 avio_write(pb, buf2, strlen(buf2));
202 }
203 }
204
205 /* construct frame header */201 /* construct frame header */
206 202
207 avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);203 avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);
@@ -279,10 +275,8 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) · 71 unmodified lines
279 return 0;275 return 0;
280}276}
281 277
282static int yuv4_write_header(AVFormatContext *s)278static int yuv4_init(AVFormatContext *s)
283{279{
284 int *first_pkt = s->priv_data;
285
286 if (s->nb_streams != 1)280 if (s->nb_streams != 1)
287 return AVERROR(EIO);281 return AVERROR(EIO);
288 282
@@ -347,7 +341,6 @@ static int yuv4_write_header(AVFormatContext *s) · 58 unmodified lines
347 return AVERROR(EIO);341 return AVERROR(EIO);
348 }342 }
349 343
350 *first_pkt = 1;
351 return 0;344 return 0;
352}345}
353 346
@@ -355,9 +348,9 @@ AVOutputFormat ff_yuv4mpegpipe_muxer = { · 1 unmodified line
355 .name = "yuv4mpegpipe",348 .name = "yuv4mpegpipe",
356 .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),349 .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
357 .extensions = "y4m",350 .extensions = "y4m",
358 .priv_data_size = sizeof(int),
359 .audio_codec = AV_CODEC_ID_NONE,351 .audio_codec = AV_CODEC_ID_NONE,
360 .video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,352 .video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,
353 .init = yuv4_init,
361 .write_header = yuv4_write_header,354 .write_header = yuv4_write_header,
362 .write_packet = yuv4_write_packet,355 .write_packet = yuv4_write_packet,
363};356};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t