Browse Source

avformat/yuv4mpegenc: simplify writing the header

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

Signed-off-by: James Almer <jamrial@gmail.com>
tags/n4.4
James Almer 5 years ago
parent
commit
f901d75bf1
1 changed files with 14 additions and 21 deletions
  1. +14
    -21
      libavformat/yuv4mpegenc.c

+ 14
- 21
libavformat/yuv4mpegenc.c View File

@@ -26,14 +26,16 @@

#define Y4M_LINE_MAX 256

static int yuv4_generate_header(AVFormatContext *s, char* buf)
static int yuv4_write_header(AVFormatContext *s)
{
AVStream *st;
AVIOContext *pb = s->pb;
int width, height;
int raten, rated, aspectn, aspectd, n;
char inter;
const char *colorspace = "";
const char *colorrange = "";
char buf[Y4M_LINE_MAX + 1];
int field_order;

st = s->streams[0];
@@ -173,7 +175,15 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
Y4M_MAGIC, width, height, raten, rated, inter,
aspectn, aspectd, colorspace, colorrange);

return n;
if (n < 0) {
av_log(s, AV_LOG_ERROR,
"Error. YUV4MPEG stream header write failed.\n");
return AVERROR(EIO);
}

avio_write(pb, buf, strlen(buf));

return 0;
}


@@ -182,26 +192,12 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
AVStream *st = s->streams[pkt->stream_index];
AVIOContext *pb = s->pb;
AVFrame *frame;
int* first_pkt = s->priv_data;
int width, height, h_chroma_shift, v_chroma_shift;
int i;
char buf2[Y4M_LINE_MAX + 1];
uint8_t *ptr, *ptr1, *ptr2;

frame = (AVFrame *)pkt->data;

/* for the first packet we have to output the header as well */
if (*first_pkt) {
*first_pkt = 0;
if (yuv4_generate_header(s, buf2) < 0) {
av_log(s, AV_LOG_ERROR,
"Error. YUV4MPEG stream header write failed.\n");
return AVERROR(EIO);
} else {
avio_write(pb, buf2, strlen(buf2));
}
}

/* construct frame header */

avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);
@@ -279,10 +275,8 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
return 0;
}

static int yuv4_write_header(AVFormatContext *s)
static int yuv4_init(AVFormatContext *s)
{
int *first_pkt = s->priv_data;

if (s->nb_streams != 1)
return AVERROR(EIO);

@@ -347,7 +341,6 @@ static int yuv4_write_header(AVFormatContext *s)
return AVERROR(EIO);
}

*first_pkt = 1;
return 0;
}

@@ -355,9 +348,9 @@ AVOutputFormat ff_yuv4mpegpipe_muxer = {
.name = "yuv4mpegpipe",
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
.extensions = "y4m",
.priv_data_size = sizeof(int),
.audio_codec = AV_CODEC_ID_NONE,
.video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,
.init = yuv4_init,
.write_header = yuv4_write_header,
.write_packet = yuv4_write_packet,
};

Loading…
Cancel
Save