26 #define Y4M_MAGIC "YUV4MPEG2"
27 #define Y4M_FRAME_MAGIC "FRAME"
28 #define Y4M_LINE_MAX 256
35 #if CONFIG_YUV4MPEGPIPE_MUXER
40 int raten, rated, aspectn, aspectd, n;
54 if (aspectn == 0 && aspectd == 1)
63 colorspace =
" Cmono";
66 colorspace =
" C411 XYSCSS=411";
72 default: colorspace =
" C420jpeg XYSCSS=420JPEG";
break;
76 colorspace =
" C422 XYSCSS=422";
79 colorspace =
" C444 XYSCSS=444";
84 n = snprintf(buf,
Y4M_LINE_MAX,
"%s W%d H%d F%d:%d I%c A%d:%d%s\n",
85 Y4M_MAGIC, width, height, raten, rated, inter,
86 aspectn, aspectd, colorspace);
108 if (yuv4_generate_header(s, buf2) < 0) {
110 "Error. YUV4MPEG stream header write failed.\n");
125 ptr = picture->
data[0];
126 for (i = 0; i <
height; i++) {
136 width = -(-width >> h_chroma_shift);
137 height = -(-height >> v_chroma_shift);
139 ptr1 = picture->
data[1];
140 ptr2 = picture->
data[2];
141 for (i = 0; i <
height; i++) {
145 for (i = 0; i <
height; i++) {
167 "stream, some mjpegtools might not work.\n");
173 "yuv422p, yuv420p, yuv411p and gray pixel formats. "
174 "Use -pix_fmt to select one.\n");
183 .
name =
"yuv4mpegpipe",
187 .priv_data_size =
sizeof(int),
197 #define MAX_YUV4_HEADER 80
198 #define MAX_FRAME_HEADER 80
204 char *tokstart, *tokend, *header_end;
207 int width = -1, height = -1, raten = 0,
208 rated = 0, aspectn = 0, aspectd = 0;
216 if (header[i] ==
'\n') {
217 header[i + 1] = 0x20;
223 if (i == MAX_YUV4_HEADER)
230 header_end = &header[i + 1];
231 for (tokstart = &header[strlen(
Y4M_MAGIC) + 1];
232 tokstart < header_end; tokstart++) {
233 if (*tokstart == 0x20)
235 switch (*tokstart++) {
237 width = strtol(tokstart, &tokend, 10);
241 height = strtol(tokstart, &tokend, 10);
245 if (strncmp(
"420jpeg", tokstart, 7) == 0) {
248 }
else if (strncmp(
"420mpeg2", tokstart, 8) == 0) {
251 }
else if (strncmp(
"420paldv", tokstart, 8) == 0) {
254 }
else if (strncmp(
"420", tokstart, 3) == 0) {
257 }
else if (strncmp(
"411", tokstart, 3) == 0)
259 else if (strncmp(
"422", tokstart, 3) == 0)
261 else if (strncmp(
"444alpha", tokstart, 8) == 0 ) {
263 "YUV4MPEG stream.\n");
265 }
else if (strncmp(
"444", tokstart, 3) == 0)
267 else if (strncmp(
"mono", tokstart, 4) == 0) {
274 while (tokstart < header_end && *tokstart != 0x20)
278 switch (*tokstart++){
294 "interlaced and non-interlaced frames.\n");
302 sscanf(tokstart,
"%d:%d", &raten, &rated);
303 while (tokstart < header_end && *tokstart != 0x20)
307 sscanf(tokstart,
"%d:%d", &aspectn, &aspectd);
308 while (tokstart < header_end && *tokstart != 0x20)
312 if (strncmp(
"YSCSS=", tokstart, 6) == 0) {
315 if (strncmp(
"420JPEG", tokstart, 7) == 0)
317 else if (strncmp(
"420MPEG2", tokstart, 8) == 0)
319 else if (strncmp(
"420PALDV", tokstart, 8) == 0)
321 else if (strncmp(
"411", tokstart, 3) == 0)
323 else if (strncmp(
"422", tokstart, 3) == 0)
325 else if (strncmp(
"444", tokstart, 3) == 0)
328 while (tokstart < header_end && *tokstart != 0x20)
334 if (width == -1 || height == -1) {
343 pix_fmt = alt_pix_fmt;
346 if (raten <= 0 || rated <= 0) {
352 if (aspectn == 0 && aspectd == 0) {
362 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
384 if (header[i] ==
'\n') {
393 else if (i == MAX_FRAME_HEADER)
409 else if (ret != packet_size)
430 #if CONFIG_YUV4MPEGPIPE_DEMUXER
432 .
name =
"yuv4mpegpipe",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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)
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]
AVStream ** streams
A list of all streams in the file.
#define AVERROR_EOF
End of file.
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 AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#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.
AVRational avg_frame_rate
Average framerate.
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
Number of elements in AVFormatContext.streams.
int width
picture width / height.
enum AVPixelFormat pix_fmt
if(ac->has_optimized_func)
enum AVMediaType codec_type
AVIOContext * pb
I/O context.
static int yuv4_read_header(AVFormatContext *s)
rational number numerator/denominator
int error
contains the error code or 0 if no error happened
This structure contains the data a format has to probe a file.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
FF_ENABLE_DEPRECATION_WARNINGS int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
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
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
AVPixelFormat
Pixel format.
This structure stores compressed data.