mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-13 10:51:38 +00:00
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>
This commit is contained in:
parent
2c0d6ac9ae
commit
f901d75bf1
@ -26,14 +26,16 @@
|
|||||||
|
|
||||||
#define Y4M_LINE_MAX 256
|
#define Y4M_LINE_MAX 256
|
||||||
|
|
||||||
static int yuv4_generate_header(AVFormatContext *s, char* buf)
|
static int yuv4_write_header(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
|
AVIOContext *pb = s->pb;
|
||||||
int width, height;
|
int width, height;
|
||||||
int raten, rated, aspectn, aspectd, n;
|
int raten, rated, aspectn, aspectd, n;
|
||||||
char inter;
|
char inter;
|
||||||
const char *colorspace = "";
|
const char *colorspace = "";
|
||||||
const char *colorrange = "";
|
const char *colorrange = "";
|
||||||
|
char buf[Y4M_LINE_MAX + 1];
|
||||||
int field_order;
|
int field_order;
|
||||||
|
|
||||||
st = s->streams[0];
|
st = s->streams[0];
|
||||||
@ -173,7 +175,15 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
|
|||||||
Y4M_MAGIC, width, height, raten, rated, inter,
|
Y4M_MAGIC, width, height, raten, rated, inter,
|
||||||
aspectn, aspectd, colorspace, colorrange);
|
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];
|
AVStream *st = s->streams[pkt->stream_index];
|
||||||
AVIOContext *pb = s->pb;
|
AVIOContext *pb = s->pb;
|
||||||
AVFrame *frame;
|
AVFrame *frame;
|
||||||
int* first_pkt = s->priv_data;
|
|
||||||
int width, height, h_chroma_shift, v_chroma_shift;
|
int width, height, h_chroma_shift, v_chroma_shift;
|
||||||
int i;
|
int i;
|
||||||
char buf2[Y4M_LINE_MAX + 1];
|
|
||||||
uint8_t *ptr, *ptr1, *ptr2;
|
uint8_t *ptr, *ptr1, *ptr2;
|
||||||
|
|
||||||
frame = (AVFrame *)pkt->data;
|
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 */
|
/* construct frame header */
|
||||||
|
|
||||||
avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);
|
avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);
|
||||||
@ -279,10 +275,8 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
return 0;
|
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)
|
if (s->nb_streams != 1)
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
|
|
||||||
@ -347,7 +341,6 @@ static int yuv4_write_header(AVFormatContext *s)
|
|||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
*first_pkt = 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,9 +348,9 @@ AVOutputFormat ff_yuv4mpegpipe_muxer = {
|
|||||||
.name = "yuv4mpegpipe",
|
.name = "yuv4mpegpipe",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
|
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
|
||||||
.extensions = "y4m",
|
.extensions = "y4m",
|
||||||
.priv_data_size = sizeof(int),
|
|
||||||
.audio_codec = AV_CODEC_ID_NONE,
|
.audio_codec = AV_CODEC_ID_NONE,
|
||||||
.video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,
|
.video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,
|
||||||
|
.init = yuv4_init,
|
||||||
.write_header = yuv4_write_header,
|
.write_header = yuv4_write_header,
|
||||||
.write_packet = yuv4_write_packet,
|
.write_packet = yuv4_write_packet,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user