summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2020-09-03 15:39:32 -0300
committerJames Almer <jamrial@gmail.com>2020-09-03 17:08:23 -0300
commitf901d75bf18c866933f90c052fb990736aee7c47 (patch)
tree92d5932da9e6779df71e4277a262bb19f86d49ec
parent2c0d6ac9aeb3d67941b8f30c50e766f936d24db1 (diff)
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>
-rw-r--r--libavformat/yuv4mpegenc.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
index e84dbf9568..c4781042bd 100644
--- a/libavformat/yuv4mpegenc.c
+++ b/libavformat/yuv4mpegenc.c
@@ -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,
};