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
2626
2727 #define Y4M_LINE_MAX 256
2828
29−static int yuv4_generate_header(AVFormatContext *s, char* buf)
29+static int yuv4_write_header(AVFormatContext *s)
3030 {
3131 AVStream *st;
32+ AVIOContext *pb = s->pb;
3233 int width, height;
3334 int raten, rated, aspectn, aspectd, n;
3435 char inter;
3536 const char *colorspace = "";
3637 const char *colorrange = "";
38+ char buf[Y4M_LINE_MAX + 1];
3739 int field_order;
3840
3941 st = s->streams[0];
@@ -173,7 +175,15 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf) · 133 unmodified lines
173175 Y4M_MAGIC, width, height, raten, rated, inter,
174176 aspectn, aspectd, colorspace, colorrange);
175177
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;
177187 }
178188
179189
@@ -182,26 +192,12 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) · 2 unmodified lines
182192 AVStream *st = s->streams[pkt->stream_index];
183193 AVIOContext *pb = s->pb;
184194 AVFrame *frame;
185− int* first_pkt = s->priv_data;
186195 int width, height, h_chroma_shift, v_chroma_shift;
187196 int i;
188− char buf2[Y4M_LINE_MAX + 1];
189197 uint8_t *ptr, *ptr1, *ptr2;
190198
191199 frame = (AVFrame *)pkt->data;
192200
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−
205201 /* construct frame header */
206202
207203 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
279275 return 0;
280276 }
281277
282−static int yuv4_write_header(AVFormatContext *s)
278+static int yuv4_init(AVFormatContext *s)
283279 {
284− int *first_pkt = s->priv_data;
285−
286280 if (s->nb_streams != 1)
287281 return AVERROR(EIO);
288282
@@ -347,7 +341,6 @@ static int yuv4_write_header(AVFormatContext *s) · 58 unmodified lines
347341 return AVERROR(EIO);
348342 }
349343
350− *first_pkt = 1;
351344 return 0;
352345 }
353346
@@ -355,9 +348,9 @@ AVOutputFormat ff_yuv4mpegpipe_muxer = { · 1 unmodified line
355348 .name = "yuv4mpegpipe",
356349 .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
357350 .extensions = "y4m",
358− .priv_data_size = sizeof(int),
359351 .audio_codec = AV_CODEC_ID_NONE,
360352 .video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,
353+ .init = yuv4_init,
361354 .write_header = yuv4_write_header,
362355 .write_packet = yuv4_write_packet,
363356 };

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