24 #define Y4M_MAGIC "YUV4MPEG2"
25 #define Y4M_FRAME_MAGIC "FRAME"
26 #define Y4M_LINE_MAX 256
33 #if CONFIG_YUV4MPEGPIPE_MUXER
38 int raten, rated, aspectn, aspectd, n;
52 if (aspectn == 0 && aspectd == 1)
61 colorspace =
" Cmono";
64 colorspace =
" C411 XYSCSS=411";
70 default: colorspace =
" C420jpeg XYSCSS=420JPEG";
break;
74 colorspace =
" C422 XYSCSS=422";
77 colorspace =
" C444 XYSCSS=444";
82 n = snprintf(buf,
Y4M_LINE_MAX,
"%s W%d H%d F%d:%d I%c A%d:%d%s\n",
83 Y4M_MAGIC, width, height, raten, rated, inter,
84 aspectn, aspectd, colorspace);
106 if (yuv4_generate_header(s, buf2) < 0) {
108 "Error. YUV4MPEG stream header write failed.\n");
123 ptr = picture->
data[0];
124 for (i = 0; i <
height; i++) {
133 width >>= h_chroma_shift;
134 height >>= v_chroma_shift;
136 ptr1 = picture->
data[1];
137 ptr2 = picture->
data[2];
138 for (i = 0; i <
height; i++) {
142 for (i = 0; i <
height; i++) {
165 "stream, some mjpegtools might not work.\n");
171 "yuv422p, yuv420p, yuv411p and gray pixel formats. "
172 "Use -pix_fmt to select one.\n");
181 .
name =
"yuv4mpegpipe",
185 .priv_data_size =
sizeof(int),
195 #define MAX_YUV4_HEADER 80
196 #define MAX_FRAME_HEADER 80
202 char *tokstart, *tokend, *header_end;
205 int width = -1, height = -1, raten = 0,
206 rated = 0, aspectn = 0, aspectd = 0;
214 if (header[i] ==
'\n') {
215 header[i + 1] = 0x20;
221 if (i == MAX_YUV4_HEADER)
228 header_end = &header[i + 1];
229 for (tokstart = &header[strlen(
Y4M_MAGIC) + 1];
230 tokstart < header_end; tokstart++) {
231 if (*tokstart == 0x20)
233 switch (*tokstart++) {
235 width = strtol(tokstart, &tokend, 10);
239 height = strtol(tokstart, &tokend, 10);
243 if (strncmp(
"420jpeg", tokstart, 7) == 0) {
246 }
else if (strncmp(
"420mpeg2", tokstart, 8) == 0) {
249 }
else if (strncmp(
"420paldv", tokstart, 8) == 0) {
252 }
else if (strncmp(
"420", tokstart, 3) == 0) {
255 }
else if (strncmp(
"411", tokstart, 3) == 0)
257 else if (strncmp(
"422", tokstart, 3) == 0)
259 else if (strncmp(
"444alpha", tokstart, 8) == 0 ) {
261 "YUV4MPEG stream.\n");
263 }
else if (strncmp(
"444", tokstart, 3) == 0)
265 else if (strncmp(
"mono", tokstart, 4) == 0) {
272 while (tokstart < header_end && *tokstart != 0x20)
276 switch (*tokstart++){
292 "interlaced and non-interlaced frames.\n");
300 sscanf(tokstart,
"%d:%d", &raten, &rated);
301 while (tokstart < header_end && *tokstart != 0x20)
305 sscanf(tokstart,
"%d:%d", &aspectn, &aspectd);
306 while (tokstart < header_end && *tokstart != 0x20)
310 if (strncmp(
"YSCSS=", tokstart, 6) == 0) {
313 if (strncmp(
"420JPEG", tokstart, 7) == 0)
315 else if (strncmp(
"420MPEG2", tokstart, 8) == 0)
317 else if (strncmp(
"420PALDV", tokstart, 8) == 0)
319 else if (strncmp(
"411", tokstart, 3) == 0)
321 else if (strncmp(
"422", tokstart, 3) == 0)
323 else if (strncmp(
"444", tokstart, 3) == 0)
326 while (tokstart < header_end && *tokstart != 0x20)
332 if (width == -1 || height == -1) {
341 pix_fmt = alt_pix_fmt;
344 if (raten <= 0 || rated <= 0) {
350 if (aspectn == 0 && aspectd == 0) {
360 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
381 if (header[i] ==
'\n') {
390 else if (i == MAX_FRAME_HEADER)
406 else if (ret != packet_size)
427 #if CONFIG_YUV4MPEGPIPE_DEMUXER
429 .
name =
"yuv4mpegpipe",
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
AVFrame * coded_frame
the picture in the bitstream
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
void attribute_deprecated avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
AVChromaLocation
X X 3 4 X X are luma samples, 1 2 1-6 are possible chroma positions X X 5 6 X 0 is undefined/unknown ...
four components are given, that's all.
static int yuv4_probe(AVProbeData *pd)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
uint8_t * data[AV_NUM_DATA_POINTERS]
int interlaced_frame
The content of the picture is interlaced.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
A list of all streams in the file.
struct AVRational AVRational
rational number numerator/denominator
int void avio_flush(AVIOContext *s)
int width
picture width / height.
enum AVPixelFormat pix_fmt
enum AVMediaType codec_type
AVIOContext * pb
I/O context.
static int yuv4_read_header(AVFormatContext *s)
int error
contains the error code or 0 if no error happened
This structure contains the data a format has to probe a file.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define AVERROR_INVALIDDATA
#define AVPROBE_SCORE_MAX
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int eof_reached
true if eof reached
int top_field_first
If the content is interlaced, is top field displayed first.
void * priv_data
Format private data.
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
static void write_header(FFV1Context *f)
static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
enum AVColorSpace colorspace
AVPixelFormat
Pixel format.
This structure stores compressed data.
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)