FFmpeg
Loading...
Searching...
No Matches
mlvdec.c
Go to the documentation of this file.
1/*
2 * Magic Lantern Video (MLV) demuxer
3 * Copyright (c) 2014 Peter Ross
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * Magic Lantern Video (MLV) demuxer
25 */
26
27#include <time.h>
28
30#include "libavcodec/tiff.h"
32#include "libavutil/imgutils.h"
34#include "libavutil/mem.h"
35#include "libavutil/rational.h"
36#include "avformat.h"
37#include "demux.h"
38#include "internal.h"
39#include "avio_internal.h"
40#include "riff.h"
41
42#define MLV_VERSION "v2.0"
43
44#define MLV_VIDEO_CLASS_RAW 1
45#define MLV_VIDEO_CLASS_YUV 2
46#define MLV_VIDEO_CLASS_JPEG 3
47#define MLV_VIDEO_CLASS_H264 4
48
49#define MLV_AUDIO_CLASS_WAV 1
50
51#define MLV_CLASS_FLAG_LJ92 0x20
52#define MLV_CLASS_FLAG_DELTA 0x40
53#define MLV_CLASS_FLAG_LZMA 0x80
54
55typedef struct {
57 int class[2];
59 uint64_t pts;
62 int color_matrix1[9][2];
64
65static int probe(const AVProbeData *p)
66{
67 if (AV_RL32(p->buf) == MKTAG('M','L','V','I') &&
68 AV_RL32(p->buf + 4) >= 52 &&
69 !memcmp(p->buf + 8, MLV_VERSION, 5))
70 return AVPROBE_SCORE_MAX;
71 return 0;
72}
73
74static int check_file_header(AVIOContext *pb, uint64_t guid)
75{
76 unsigned int size;
77 uint8_t version[8];
78 int ret;
79
80 avio_skip(pb, 4);
81 size = avio_rl32(pb);
82 if (size < 52)
84 ret = ffio_read_size(pb, version, 8);
85 if (ret < 0)
86 return ret;
87 if (memcmp(version, MLV_VERSION, 5) || avio_rl64(pb) != guid)
89 avio_skip(pb, size - 24);
90 return 0;
91}
92
93static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag, unsigned size)
94{
95 char * value = av_malloc(size + 1);
96 int ret;
97
98 if (!value) {
99 avio_skip(pb, size);
100 return;
101 }
102
103 ret = avio_read(pb, value, size);
104 if (ret != size || !size || !value[0]) {
105 av_free(value);
106 return;
107 }
108
109 value[size] = 0;
111}
112
113static void read_uint8(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
114{
115 av_dict_set_int(&avctx->metadata, tag, avio_r8(pb), 0);
116}
117
118static void read_uint16(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
119{
120 av_dict_set_int(&avctx->metadata, tag, avio_rl16(pb), 0);
121}
122
123static void read_uint32(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
124{
125 av_dict_set_int(&avctx->metadata, tag, avio_rl32(pb), 0);
126}
127
128static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
129{
130 av_dict_set_int(&avctx->metadata, tag, avio_rl64(pb), 0);
131}
132
133static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file)
134{
135 FFStream *const vsti = ffstream(vst), *const asti = ffstream(ast);
136 MlvContext *mlv = avctx->priv_data;
137 AVIOContext *pb = mlv->pb[file];
138 int ret;
139 while (!avio_feof(pb)) {
140 int type;
141 unsigned int size;
142 type = avio_rl32(pb);
143 size = avio_rl32(pb);
144 avio_skip(pb, 8); //timestamp
145 if (size < 16)
146 break;
147 size -= 16;
148 if (vst && type == MKTAG('R','A','W','I') && size >= 164) {
149 unsigned width = avio_rl16(pb);
150 unsigned height = avio_rl16(pb);
151 unsigned bits_per_coded_sample;
152 ret = av_image_check_size(width, height, 0, avctx);
153 if (ret < 0)
154 return ret;
155 if (avio_rl32(pb) != 1)
156 avpriv_request_sample(avctx, "raw api version");
157 avio_skip(pb, 20); // pointer, width, height, pitch, frame_size
158 bits_per_coded_sample = avio_rl32(pb);
159 if (bits_per_coded_sample > (INT_MAX - 7) / (width * height)) {
160 av_log(avctx, AV_LOG_ERROR,
161 "invalid bits_per_coded_sample %u (size: %ux%u)\n",
162 bits_per_coded_sample, width, height);
163 return AVERROR_INVALIDDATA;
164 }
165 vst->codecpar->width = width;
166 vst->codecpar->height = height;
167 vst->codecpar->bits_per_coded_sample = bits_per_coded_sample;
168 mlv->black_level = avio_rl32(pb);
169 mlv->white_level = avio_rl32(pb);
170 avio_skip(pb, 16 + 24); // xywh, active_area, exposure_bias
171 if (avio_rl32(pb) != 0x2010100) /* RGGB */
172 avpriv_request_sample(avctx, "cfa_pattern");
173 avio_skip(pb, 4); // calibration_illuminant1,
174 for (int i = 0; i < 9; i++) {
175 mlv->color_matrix1[i][0] = avio_rl32(pb);
176 mlv->color_matrix1[i][1] = avio_rl32(pb);
177 }
178 avio_skip(pb, 4); // dynamic_range
180 vst->codecpar->codec_tag = MKTAG('B', 'I', 'T', 16);
181 size -= 164;
182 } else if (ast && type == MKTAG('W', 'A', 'V', 'I') && size >= 16) {
183 ret = ff_get_wav_header(avctx, pb, ast->codecpar, 16, 0);
184 if (ret < 0)
185 return ret;
186 size -= 16;
187 } else if (type == MKTAG('I','N','F','O')) {
188 if (size > 0)
189 read_string(avctx, pb, "info", size);
190 continue;
191 } else if (type == MKTAG('I','D','N','T') && size >= 36) {
192 read_string(avctx, pb, "cameraName", 32);
193 read_uint32(avctx, pb, "cameraModel", "0x%"PRIx32);
194 size -= 36;
195 if (size >= 32) {
196 read_string(avctx, pb, "cameraSerial", 32);
197 size -= 32;
198 }
199 } else if (type == MKTAG('L','E','N','S') && size >= 48) {
200 read_uint16(avctx, pb, "focalLength", "%i");
201 read_uint16(avctx, pb, "focalDist", "%i");
202 read_uint16(avctx, pb, "aperture", "%i");
203 read_uint8(avctx, pb, "stabilizerMode", "%i");
204 read_uint8(avctx, pb, "autofocusMode", "%i");
205 read_uint32(avctx, pb, "flags", "0x%"PRIx32);
206 read_uint32(avctx, pb, "lensID", "%"PRIi32);
207 read_string(avctx, pb, "lensName", 32);
208 size -= 48;
209 if (size >= 32) {
210 read_string(avctx, pb, "lensSerial", 32);
211 size -= 32;
212 }
213 } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) {
214 uint64_t pts = avio_rl32(pb);
217 avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
218 size -= 4;
219 } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) {
220 uint64_t pts = avio_rl32(pb);
221 ff_add_index_entry(&asti->index_entries, &asti->nb_index_entries,
222 &asti->index_entries_allocated_size,
223 avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
224 size -= 4;
225 } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) {
226 read_uint32(avctx, pb, "wb_mode", "%"PRIi32);
227 read_uint32(avctx, pb, "kelvin", "%"PRIi32);
228 read_uint32(avctx, pb, "wbgain_r", "%"PRIi32);
229 read_uint32(avctx, pb, "wbgain_g", "%"PRIi32);
230 read_uint32(avctx, pb, "wbgain_b", "%"PRIi32);
231 read_uint32(avctx, pb, "wbs_gm", "%"PRIi32);
232 read_uint32(avctx, pb, "wbs_ba", "%"PRIi32);
233 size -= 28;
234 } else if (type == MKTAG('R','T','C','I') && size >= 20) {
235 char str[32];
236 struct tm time = { 0 };
237 time.tm_sec = avio_rl16(pb);
238 time.tm_min = avio_rl16(pb);
239 time.tm_hour = avio_rl16(pb);
240 time.tm_mday = avio_rl16(pb);
241 time.tm_mon = avio_rl16(pb);
242 time.tm_year = avio_rl16(pb);
243 time.tm_wday = avio_rl16(pb);
244 time.tm_yday = avio_rl16(pb);
245 time.tm_isdst = avio_rl16(pb);
246 avio_skip(pb, 2);
247 if (strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", &time))
248 av_dict_set(&avctx->metadata, "time", str, 0);
249 size -= 20;
250 } else if (type == MKTAG('E','X','P','O') && size >= 16) {
251 av_dict_set(&avctx->metadata, "isoMode", avio_rl32(pb) ? "auto" : "manual", 0);
252 read_uint32(avctx, pb, "isoValue", "%"PRIi32);
253 read_uint32(avctx, pb, "isoAnalog", "%"PRIi32);
254 read_uint32(avctx, pb, "digitalGain", "%"PRIi32);
255 size -= 16;
256 if (size >= 8) {
257 read_uint64(avctx, pb, "shutterValue", "%"PRIi64);
258 size -= 8;
259 }
260 } else if (type == MKTAG('S','T','Y','L') && size >= 36) {
261 read_uint32(avctx, pb, "picStyleId", "%"PRIi32);
262 read_uint32(avctx, pb, "contrast", "%"PRIi32);
263 read_uint32(avctx, pb, "sharpness", "%"PRIi32);
264 read_uint32(avctx, pb, "saturation", "%"PRIi32);
265 read_uint32(avctx, pb, "colortone", "%"PRIi32);
266 read_string(avctx, pb, "picStyleName", 16);
267 size -= 36;
268 } else if (type == MKTAG('V','E','R','S') && size >= 4) {
269 unsigned int length = avio_rl32(pb);
270 read_string(avctx, pb, "version", length);
271 size -= length + 4;
272 } else if (type == MKTAG('D','A','R','K')) {
273 } else if (type == MKTAG('D','I','S','O')) {
274 } else if (type == MKTAG('M','A','R','K')) {
275 } else if (type == MKTAG('N','U','L','L')) {
276 } else if (type == MKTAG('M','L','V','I')) { /* occurs when MLV and Mnn files are concatenated */
277 } else if (type == MKTAG('R','A','W','C')) {
278 } else {
279 av_log(avctx, AV_LOG_INFO, "unsupported tag %s, size %u\n",
281 }
282 avio_skip(pb, size);
283 }
284 return 0;
285}
286
287static int read_header(AVFormatContext *avctx)
288{
289 MlvContext *mlv = avctx->priv_data;
290 AVIOContext *pb = avctx->pb;
291 AVStream *vst = NULL, *ast = NULL;
292 FFStream *vsti = NULL, *asti = NULL;
293 int size, ret;
294 unsigned nb_video_frames, nb_audio_frames;
295 uint64_t guid;
296 char guidstr[32];
297
298 avio_skip(pb, 4);
299 size = avio_rl32(pb);
300 if (size < 52)
301 return AVERROR_INVALIDDATA;
302
303 avio_skip(pb, 8);
304
305 guid = avio_rl64(pb);
306 snprintf(guidstr, sizeof(guidstr), "0x%"PRIx64, guid);
307 av_dict_set(&avctx->metadata, "guid", guidstr, 0);
308
309 avio_skip(pb, 8); //fileNum, fileCount, fileFlags
310
311 mlv->class[0] = avio_rl16(pb);
312 mlv->class[1] = avio_rl16(pb);
313
314 nb_video_frames = avio_rl32(pb);
315 nb_audio_frames = avio_rl32(pb);
316
317 if (nb_video_frames && mlv->class[0]) {
318 vst = avformat_new_stream(avctx, NULL);
319 if (!vst)
320 return AVERROR(ENOMEM);
321 vsti = ffstream(vst);
322
323 vst->id = 0;
324 vst->nb_frames = nb_video_frames;
326 avpriv_request_sample(avctx, "compression");
328 switch (mlv->class[0] & ~(MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA)) {
331 break;
335 vst->codecpar->codec_tag = 0;
336 break;
339 break;
342 vst->codecpar->codec_tag = 0;
343 break;
346 vst->codecpar->codec_tag = 0;
347 break;
348 default:
349 avpriv_request_sample(avctx, "unknown video class");
350 }
351 }
352
353 if (nb_audio_frames && mlv->class[1]) {
354 ast = avformat_new_stream(avctx, NULL);
355 if (!ast)
356 return AVERROR(ENOMEM);
357 asti = ffstream(ast);
358 ast->id = 1;
359 ast->nb_frames = nb_audio_frames;
360 if ((mlv->class[1] & MLV_CLASS_FLAG_LZMA))
361 avpriv_request_sample(avctx, "compression");
363 avpriv_request_sample(avctx, "unknown audio class");
364
365 ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
366 avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate);
367 }
368
369 if (vst) {
371 framerate.num = avio_rl32(pb);
372 framerate.den = avio_rl32(pb);
373 avpriv_set_pts_info(vst, 64, framerate.den, framerate.num);
374 } else
375 avio_skip(pb, 8);
376
377 avio_skip(pb, size - 52);
378
379 /* scan primary file */
380 mlv->pb[100] = avctx->pb;
381 ret = scan_file(avctx, vst, ast, 100);
382 if (ret < 0)
383 return ret;
384
385 /* scan secondary files */
386 if (strlen(avctx->url) > 2) {
387 int i;
388 char *filename = av_strdup(avctx->url);
389
390 if (!filename)
391 return AVERROR(ENOMEM);
392
393 for (i = 0; i < 100; i++) {
394 snprintf(filename + strlen(filename) - 2, 3, "%02d", i);
395 if (avctx->io_open(avctx, &mlv->pb[i], filename, AVIO_FLAG_READ, NULL) < 0)
396 break;
397 if (check_file_header(mlv->pb[i], guid) < 0) {
398 av_log(avctx, AV_LOG_WARNING, "ignoring %s; bad format or guid mismatch\n", filename);
399 ff_format_io_close(avctx, &mlv->pb[i]);
400 continue;
401 }
402 av_log(avctx, AV_LOG_INFO, "scanning %s\n", filename);
403 ret = scan_file(avctx, vst, ast, i);
404 if (ret < 0) {
405 av_log(avctx, AV_LOG_WARNING, "ignoring %s; %s\n", filename, av_err2str(ret));
406 ff_format_io_close(avctx, &mlv->pb[i]);
407 continue;
408 }
409 }
410 av_free(filename);
411 }
412
413 if (vst)
414 vst->duration = vsti->nb_index_entries;
415 if (ast)
416 ast->duration = asti->nb_index_entries;
417
418 if ((vst && !vsti->nb_index_entries) || (ast && !asti->nb_index_entries)) {
419 av_log(avctx, AV_LOG_ERROR, "no index entries found\n");
420 return AVERROR_INVALIDDATA;
421 }
422
423 if (vst && ast)
424 avio_seek(pb, FFMIN(vsti->index_entries[0].pos, asti->index_entries[0].pos), SEEK_SET);
425 else if (vst)
426 avio_seek(pb, vsti->index_entries[0].pos, SEEK_SET);
427 else if (ast)
428 avio_seek(pb, asti->index_entries[0].pos, SEEK_SET);
429
430 return 0;
431}
432
433static void write_tiff_short(PutByteContext *pb, int tag, int value)
434{
435 bytestream2_put_le16(pb, tag);
436 bytestream2_put_le16(pb, AV_TIFF_SHORT);
437 bytestream2_put_le32(pb, 1);
438 bytestream2_put_le16(pb, value);
439 bytestream2_put_le16(pb, 0);
440}
441
442static void write_tiff_short2(PutByteContext *pb, int tag, int v1, int v2)
443{
444 bytestream2_put_le16(pb, tag);
445 bytestream2_put_le16(pb, AV_TIFF_SHORT);
446 bytestream2_put_le32(pb, 2);
447 bytestream2_put_le16(pb, v1);
448 bytestream2_put_le16(pb, v2);
449}
450
451static void write_tiff_long(PutByteContext *pb, int tag, int value)
452{
453 bytestream2_put_le16(pb, tag);
454 bytestream2_put_le16(pb, AV_TIFF_LONG);
455 bytestream2_put_le32(pb, 1);
456 bytestream2_put_le32(pb, value);
457}
458
459static void write_tiff_byte4(PutByteContext *pb, int tag, int v1, int v2, int v3, int v4)
460{
461 bytestream2_put_le16(pb, tag);
462 bytestream2_put_le16(pb, AV_TIFF_BYTE);
463 bytestream2_put_le32(pb, 4);
464 bytestream2_put_byte(pb, v1);
465 bytestream2_put_byte(pb, v2);
466 bytestream2_put_byte(pb, v3);
467 bytestream2_put_byte(pb, v4);
468}
469
471{
472 MlvContext *mlv = avctx->priv_data;
473 PutByteContext pbctx, *pb = &pbctx;
474 int ret, header_size;
475 uint8_t *stripofs, *matrixofs;
476
477#define MAX_HEADER_SIZE 2048
478 if ((uint64_t)size > INT32_MAX - MAX_HEADER_SIZE)
480
481 if ((ret = av_new_packet(pkt, size + MAX_HEADER_SIZE)) < 0)
482 return ret;
483
485
486 bytestream2_put_le16(pb, 0x4949);
487 bytestream2_put_le16(pb, 42);
488 bytestream2_put_le32(pb, 8);
489
490 bytestream2_put_le16(pb, 18); /* nb_entries */
491
499 write_tiff_long(pb, TIFF_STRIP_OFFS, 0); /* stripofs */
500 stripofs = pb->buffer - 4;
501
507 write_tiff_byte4(pb, TIFF_CFA_PATTERN, 0, 1, 1, 2);
508 write_tiff_byte4(pb, DNG_VERSION, 1, 4, 0, 0);
511
512 bytestream2_put_le16(pb, DNG_COLOR_MATRIX1);
513 bytestream2_put_le16(pb, AV_TIFF_SRATIONAL);
514 bytestream2_put_le32(pb, 9);
515 bytestream2_put_le32(pb, 0); /* matrixofs */
516 matrixofs = pb->buffer - 4;
517 bytestream2_put_le32(pb, 0);
518
519 AV_WL32(matrixofs, bytestream2_tell_p(pb));
520 for (int i = 0; i < 9; i++) {
521 bytestream2_put_le32(pb, mlv->color_matrix1[i][0]);
522 bytestream2_put_le32(pb, mlv->color_matrix1[i][1]);
523 }
524
525 header_size = bytestream2_tell_p(pb);
526
527 AV_WL32(stripofs, header_size);
528 ret = avio_read(pbio, pkt->data + header_size, size);
529 if (ret < 0)
530 return ret;
531 av_shrink_packet(pkt, header_size + ret);
532
533 return 0;
534}
535
537{
538 MlvContext *mlv = avctx->priv_data;
539 AVIOContext *pb;
540 AVStream *st;
541 FFStream *sti;
542 int index, ret;
543 unsigned int size, space;
544
545 if (!avctx->nb_streams)
546 return AVERROR_EOF;
547
548 st = avctx->streams[mlv->stream_index];
549 sti = ffstream(st);
550 if (mlv->pts >= st->duration)
551 return AVERROR_EOF;
552
554 if (index < 0) {
555 av_log(avctx, AV_LOG_ERROR, "could not find index entry for frame %"PRId64"\n", mlv->pts);
556 return AVERROR_INVALIDDATA;
557 }
558
559 pb = mlv->pb[sti->index_entries[index].size];
560 if (!pb) {
561 ret = FFERROR_REDO;
562 goto next_packet;
563 }
564 avio_seek(pb, sti->index_entries[index].pos, SEEK_SET);
565
566 avio_skip(pb, 4); // blockType
567 size = avio_rl32(pb);
568 if (size < 16)
569 return AVERROR_INVALIDDATA;
570 avio_skip(pb, 12); //timestamp, frameNumber
571 size -= 12;
573 if (size < 8)
574 return AVERROR_INVALIDDATA;
575 avio_skip(pb, 8); // cropPosX, cropPosY, panPosX, panPosY
576 size -= 8;
577 }
578 space = avio_rl32(pb);
579 if (size < space + 4LL)
580 return AVERROR_INVALIDDATA;
581 avio_skip(pb, space);
582 size -= space;
583
584 if ((mlv->class[st->id] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) {
586 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
588 ret = get_packet_lj92(avctx, st, pb, pkt, size);
589 else
590 ret = av_get_packet(pb, pkt, (st->codecpar->width * st->codecpar->height * st->codecpar->bits_per_coded_sample + 7) >> 3);
591 } else { // AVMEDIA_TYPE_AUDIO
592 ret = av_get_packet(pb, pkt, size - 4);
593 }
594
595 if (ret < 0)
596 return ret;
597
598 pkt->stream_index = mlv->stream_index;
599 pkt->pts = mlv->pts;
600
601 ret = 0;
602next_packet:
603 mlv->stream_index++;
604 if (mlv->stream_index == avctx->nb_streams) {
605 mlv->stream_index = 0;
606 mlv->pts++;
607 }
608 return ret;
609}
610
611static int read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
612{
613 MlvContext *mlv = avctx->priv_data;
614
616 return AVERROR(ENOSYS);
617
618 if (!(avctx->pb->seekable & AVIO_SEEKABLE_NORMAL))
619 return AVERROR(ENOSYS);
620
621 mlv->pts = timestamp;
622 return 0;
623}
624
626{
627 MlvContext *mlv = s->priv_data;
628 int i;
629 for (i = 0; i < 100; i++)
630 ff_format_io_close(s, &mlv->pb[i]);
631 return 0;
632}
633
635 .p.name = "mlv",
636 .p.long_name = NULL_IF_CONFIG_SMALL("Magic Lantern Video (MLV)"),
637 .priv_data_size = sizeof(MlvContext),
638 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
639 .read_probe = probe,
644};
static int probe(const AVProbeData *p)
Definition act.c:39
const FFInputFormat ff_mlv_demuxer
Definition mlvdec.c:634
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition avformat.c:961
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVINDEX_KEYFRAME
Definition avformat.h:628
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition avformat.h:2617
#define AVSEEK_FLAG_ANY
seek to any frame, even non-keyframes
Definition avformat.h:2618
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
#define AVSEEK_FLAG_FRAME
seeking based on frame number
Definition avformat.h:2619
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition avio.h:41
#define AVIO_FLAG_READ
read-only
Definition avio.h:617
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:615
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
uint64_t avio_rl64(AVIOContext *s)
Definition aviobuf.c:741
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:665
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
Definition bytestream.h:197
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition bytestream.h:147
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition demux.h:35
int ff_add_index_entry(AVIndexEntry **index_entries, int *nb_index_entries, unsigned int *index_entries_allocated_size, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Internal version of av_add_index_entry.
Definition seek.c:64
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition demux.h:224
static AVPacket * pkt
double value
Definition eval.c:102
@ AV_TIFF_SHORT
Definition exif.h:44
@ AV_TIFF_SRATIONAL
Definition exif.h:51
@ AV_TIFF_LONG
Definition exif.h:45
@ AV_TIFF_BYTE
Definition exif.h:42
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_TIFF
Definition codec_id.h:146
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition seek.c:245
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition dict.h:79
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition dict.c:177
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define av_fourcc2str(fourcc)
Definition avutil.h:323
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition imgutils.c:318
int index
Definition gxfenc.c:90
cl_device_type type
misc image utilities
#define AV_WL32(p, v)
#define AV_RL32(p)
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:365
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition libcdio.c:151
version
Definition libkvazaar.c:313
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
enum AVColorSpace space
Memory handling functions.
static int get_packet_lj92(AVFormatContext *avctx, AVStream *st, AVIOContext *pbio, AVPacket *pkt, int64_t size)
Definition mlvdec.c:470
static void read_uint8(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition mlvdec.c:113
#define MLV_AUDIO_CLASS_WAV
Definition mlvdec.c:49
static int read_header(AVFormatContext *avctx)
Definition mlvdec.c:287
#define MLV_VIDEO_CLASS_RAW
Definition mlvdec.c:44
static int read_close(AVFormatContext *s)
Definition mlvdec.c:625
#define MLV_CLASS_FLAG_LJ92
Definition mlvdec.c:51
#define MLV_VIDEO_CLASS_YUV
Definition mlvdec.c:45
static int check_file_header(AVIOContext *pb, uint64_t guid)
Definition mlvdec.c:74
#define MLV_VERSION
Definition mlvdec.c:42
#define MLV_VIDEO_CLASS_JPEG
Definition mlvdec.c:46
static void read_uint32(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition mlvdec.c:123
static void write_tiff_short2(PutByteContext *pb, int tag, int v1, int v2)
Definition mlvdec.c:442
static void write_tiff_short(PutByteContext *pb, int tag, int value)
Definition mlvdec.c:433
static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag, unsigned size)
Definition mlvdec.c:93
static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition mlvdec.c:536
#define MLV_CLASS_FLAG_LZMA
Definition mlvdec.c:53
#define MLV_VIDEO_CLASS_H264
Definition mlvdec.c:47
static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file)
Definition mlvdec.c:133
#define MAX_HEADER_SIZE
static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition mlvdec.c:128
static void read_uint16(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition mlvdec.c:118
static void write_tiff_byte4(PutByteContext *pb, int tag, int v1, int v2, int v3, int v4)
Definition mlvdec.c:459
static void write_tiff_long(PutByteContext *pb, int tag, int value)
Definition mlvdec.c:451
#define MLV_CLASS_FLAG_DELTA
Definition mlvdec.c:52
static int read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
Definition mlvdec.c:611
static int probe(const AVProbeData *p)
Definition mlvdec.c:65
uint32_t tag
Definition movenc.c:2073
#define av_strdup(s)
Definition ops_static.c:55
#define av_malloc(s)
Definition ops_static.c:52
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_BAYER_RGGB16LE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian
Definition pixfmt.h:291
Utilities for rational number calculation.
internal header for RIFF based (de)muxers do NOT include this in end user applications
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition riffdec.c:141
#define snprintf
Definition snprintf.h:34
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1389
AVIOContext * pb
I/O context.
Definition avformat.h:1375
AVDictionary * metadata
Metadata that applies to the whole file.
Definition avformat.h:1580
char * url
input or output URL.
Definition avformat.h:1449
void * priv_data
Format private data.
Definition avformat.h:1361
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Definition avformat.h:1953
Bytestream IO Context.
Definition avio.h:160
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition avio.h:261
int64_t pos
position in the file of the current buffer
Definition avio.h:237
int64_t pos
Definition avformat.h:621
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Rational number (pair of numerator and denominator).
Definition rational.h:58
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t nb_frames
number of frames in this stream if known or 0
Definition avformat.h:827
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:825
int id
Format-specific stream ID.
Definition avformat.h:778
int nb_index_entries
Definition internal.h:193
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition internal.h:191
unsigned int index_entries_allocated_size
Definition internal.h:194
int color_matrix1[9][2]
Definition mlvdec.c:62
int class[2]
Definition mlvdec.c:57
int white_level
Definition mlvdec.c:61
uint64_t pts
Definition mlvdec.c:59
int stream_index
Definition mlvdec.c:58
int black_level
Definition mlvdec.c:60
AVIOContext * pb[101]
Definition mlvdec.c:56
uint8_t * buffer
Definition bytestream.h:38
#define av_free(p)
#define avpriv_request_sample(...)
#define av_log(a,...)
float framerate
Definition av1_levels.c:29
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
TIFF constants & data structures.
@ TIFF_NEWJPEG
Definition tiff.h:133
@ TIFF_WIDTH
Definition tiff.h:46
@ TIFF_PLANAR
Definition tiff.h:63
@ TIFF_COMPR
Definition tiff.h:49
@ TIFF_ROWSPERSTRIP
Definition tiff.h:59
@ TIFF_PHOTOMETRIC
Definition tiff.h:50
@ TIFF_SAMPLES_PER_PIXEL
Definition tiff.h:58
@ TIFF_STRIP_SIZE
Definition tiff.h:60
@ TIFF_CFA_PATTERN
Definition tiff.h:89
@ TIFF_CFA_PATTERN_DIM
Definition tiff.h:88
@ TIFF_HEIGHT
Definition tiff.h:47
@ TIFF_SUBFILE
Definition tiff.h:45
@ TIFF_BPP
Definition tiff.h:48
@ TIFF_FILL_ORDER
Definition tiff.h:51
@ TIFF_STRIP_OFFS
Definition tiff.h:56
@ TIFF_PHOTOMETRIC_CFA
Definition tiff.h:201
@ DNG_VERSION
Definition tiff.h:102
@ DNG_COLOR_MATRIX1
Definition tiff.h:107
@ DNG_WHITE_LEVEL
Definition tiff.h:106
@ DNG_BLACK_LEVEL
Definition tiff.h:105
TIFF Common Routines.
static int64_t pts
int size