FFmpeg
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 
29 #include "libavcodec/bytestream.h"
30 #include "libavcodec/tiff.h"
31 #include "libavcodec/tiff_common.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/intreadwrite.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 "riff.h"
40 
41 #define MLV_VERSION "v2.0"
42 
43 #define MLV_VIDEO_CLASS_RAW 1
44 #define MLV_VIDEO_CLASS_YUV 2
45 #define MLV_VIDEO_CLASS_JPEG 3
46 #define MLV_VIDEO_CLASS_H264 4
47 
48 #define MLV_AUDIO_CLASS_WAV 1
49 
50 #define MLV_CLASS_FLAG_LJ92 0x20
51 #define MLV_CLASS_FLAG_DELTA 0x40
52 #define MLV_CLASS_FLAG_LZMA 0x80
53 
54 typedef struct {
55  AVIOContext *pb[101];
56  int class[2];
58  uint64_t pts;
61  int color_matrix1[9][2];
62 } MlvContext;
63 
64 static int probe(const AVProbeData *p)
65 {
66  if (AV_RL32(p->buf) == MKTAG('M','L','V','I') &&
67  AV_RL32(p->buf + 4) >= 52 &&
68  !memcmp(p->buf + 8, MLV_VERSION, 5))
69  return AVPROBE_SCORE_MAX;
70  return 0;
71 }
72 
73 static int check_file_header(AVIOContext *pb, uint64_t guid)
74 {
75  unsigned int size;
76  uint8_t version[8];
77 
78  avio_skip(pb, 4);
79  size = avio_rl32(pb);
80  if (size < 52)
81  return AVERROR_INVALIDDATA;
82  avio_read(pb, version, 8);
83  if (memcmp(version, MLV_VERSION, 5) || avio_rl64(pb) != guid)
84  return AVERROR_INVALIDDATA;
85  avio_skip(pb, size - 24);
86  return 0;
87 }
88 
89 static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag, unsigned size)
90 {
91  char * value = av_malloc(size + 1);
92  int ret;
93 
94  if (!value) {
95  avio_skip(pb, size);
96  return;
97  }
98 
99  ret = avio_read(pb, value, size);
100  if (ret != size || !value[0]) {
101  av_free(value);
102  return;
103  }
104 
105  value[size] = 0;
107 }
108 
109 static void read_uint8(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
110 {
111  av_dict_set_int(&avctx->metadata, tag, avio_r8(pb), 0);
112 }
113 
114 static void read_uint16(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
115 {
116  av_dict_set_int(&avctx->metadata, tag, avio_rl16(pb), 0);
117 }
118 
119 static void read_uint32(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
120 {
121  av_dict_set_int(&avctx->metadata, tag, avio_rl32(pb), 0);
122 }
123 
124 static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
125 {
126  av_dict_set_int(&avctx->metadata, tag, avio_rl64(pb), 0);
127 }
128 
129 static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file)
130 {
131  FFStream *const vsti = ffstream(vst), *const asti = ffstream(ast);
132  MlvContext *mlv = avctx->priv_data;
133  AVIOContext *pb = mlv->pb[file];
134  int ret;
135  while (!avio_feof(pb)) {
136  int type;
137  unsigned int size;
138  type = avio_rl32(pb);
139  size = avio_rl32(pb);
140  avio_skip(pb, 8); //timestamp
141  if (size < 16)
142  break;
143  size -= 16;
144  if (vst && type == MKTAG('R','A','W','I') && size >= 164) {
145  unsigned width = avio_rl16(pb);
146  unsigned height = avio_rl16(pb);
147  unsigned bits_per_coded_sample;
148  ret = av_image_check_size(width, height, 0, avctx);
149  if (ret < 0)
150  return ret;
151  if (avio_rl32(pb) != 1)
152  avpriv_request_sample(avctx, "raw api version");
153  avio_skip(pb, 20); // pointer, width, height, pitch, frame_size
154  bits_per_coded_sample = avio_rl32(pb);
155  if (bits_per_coded_sample > (INT_MAX - 7) / (width * height)) {
156  av_log(avctx, AV_LOG_ERROR,
157  "invalid bits_per_coded_sample %u (size: %ux%u)\n",
158  bits_per_coded_sample, width, height);
159  return AVERROR_INVALIDDATA;
160  }
161  vst->codecpar->width = width;
162  vst->codecpar->height = height;
163  vst->codecpar->bits_per_coded_sample = bits_per_coded_sample;
164  mlv->black_level = avio_rl32(pb);
165  mlv->white_level = avio_rl32(pb);
166  avio_skip(pb, 16 + 24); // xywh, active_area, exposure_bias
167  if (avio_rl32(pb) != 0x2010100) /* RGGB */
168  avpriv_request_sample(avctx, "cfa_pattern");
169  avio_skip(pb, 4); // calibration_illuminant1,
170  for (int i = 0; i < 9; i++) {
171  mlv->color_matrix1[i][0] = avio_rl32(pb);
172  mlv->color_matrix1[i][1] = avio_rl32(pb);
173  }
174  avio_skip(pb, 4); // dynamic_range
176  vst->codecpar->codec_tag = MKTAG('B', 'I', 'T', 16);
177  size -= 164;
178  } else if (ast && type == MKTAG('W', 'A', 'V', 'I') && size >= 16) {
179  ret = ff_get_wav_header(avctx, pb, ast->codecpar, 16, 0);
180  if (ret < 0)
181  return ret;
182  size -= 16;
183  } else if (type == MKTAG('I','N','F','O')) {
184  if (size > 0)
185  read_string(avctx, pb, "info", size);
186  continue;
187  } else if (type == MKTAG('I','D','N','T') && size >= 36) {
188  read_string(avctx, pb, "cameraName", 32);
189  read_uint32(avctx, pb, "cameraModel", "0x%"PRIx32);
190  size -= 36;
191  if (size >= 32) {
192  read_string(avctx, pb, "cameraSerial", 32);
193  size -= 32;
194  }
195  } else if (type == MKTAG('L','E','N','S') && size >= 48) {
196  read_uint16(avctx, pb, "focalLength", "%i");
197  read_uint16(avctx, pb, "focalDist", "%i");
198  read_uint16(avctx, pb, "aperture", "%i");
199  read_uint8(avctx, pb, "stabilizerMode", "%i");
200  read_uint8(avctx, pb, "autofocusMode", "%i");
201  read_uint32(avctx, pb, "flags", "0x%"PRIx32);
202  read_uint32(avctx, pb, "lensID", "%"PRIi32);
203  read_string(avctx, pb, "lensName", 32);
204  size -= 48;
205  if (size >= 32) {
206  read_string(avctx, pb, "lensSerial", 32);
207  size -= 32;
208  }
209  } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) {
210  uint64_t pts = avio_rl32(pb);
213  avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
214  size -= 4;
215  } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) {
216  uint64_t pts = avio_rl32(pb);
217  ff_add_index_entry(&asti->index_entries, &asti->nb_index_entries,
218  &asti->index_entries_allocated_size,
219  avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
220  size -= 4;
221  } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) {
222  read_uint32(avctx, pb, "wb_mode", "%"PRIi32);
223  read_uint32(avctx, pb, "kelvin", "%"PRIi32);
224  read_uint32(avctx, pb, "wbgain_r", "%"PRIi32);
225  read_uint32(avctx, pb, "wbgain_g", "%"PRIi32);
226  read_uint32(avctx, pb, "wbgain_b", "%"PRIi32);
227  read_uint32(avctx, pb, "wbs_gm", "%"PRIi32);
228  read_uint32(avctx, pb, "wbs_ba", "%"PRIi32);
229  size -= 28;
230  } else if (type == MKTAG('R','T','C','I') && size >= 20) {
231  char str[32];
232  struct tm time = { 0 };
233  time.tm_sec = avio_rl16(pb);
234  time.tm_min = avio_rl16(pb);
235  time.tm_hour = avio_rl16(pb);
236  time.tm_mday = avio_rl16(pb);
237  time.tm_mon = avio_rl16(pb);
238  time.tm_year = avio_rl16(pb);
239  time.tm_wday = avio_rl16(pb);
240  time.tm_yday = avio_rl16(pb);
241  time.tm_isdst = avio_rl16(pb);
242  avio_skip(pb, 2);
243  if (strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", &time))
244  av_dict_set(&avctx->metadata, "time", str, 0);
245  size -= 20;
246  } else if (type == MKTAG('E','X','P','O') && size >= 16) {
247  av_dict_set(&avctx->metadata, "isoMode", avio_rl32(pb) ? "auto" : "manual", 0);
248  read_uint32(avctx, pb, "isoValue", "%"PRIi32);
249  read_uint32(avctx, pb, "isoAnalog", "%"PRIi32);
250  read_uint32(avctx, pb, "digitalGain", "%"PRIi32);
251  size -= 16;
252  if (size >= 8) {
253  read_uint64(avctx, pb, "shutterValue", "%"PRIi64);
254  size -= 8;
255  }
256  } else if (type == MKTAG('S','T','Y','L') && size >= 36) {
257  read_uint32(avctx, pb, "picStyleId", "%"PRIi32);
258  read_uint32(avctx, pb, "contrast", "%"PRIi32);
259  read_uint32(avctx, pb, "sharpness", "%"PRIi32);
260  read_uint32(avctx, pb, "saturation", "%"PRIi32);
261  read_uint32(avctx, pb, "colortone", "%"PRIi32);
262  read_string(avctx, pb, "picStyleName", 16);
263  size -= 36;
264  } else if (type == MKTAG('V','E','R','S') && size >= 4) {
265  unsigned int length = avio_rl32(pb);
266  read_string(avctx, pb, "version", length);
267  size -= length + 4;
268  } else if (type == MKTAG('D','A','R','K')) {
269  } else if (type == MKTAG('D','I','S','O')) {
270  } else if (type == MKTAG('M','A','R','K')) {
271  } else if (type == MKTAG('N','U','L','L')) {
272  } else if (type == MKTAG('M','L','V','I')) { /* occurs when MLV and Mnn files are concatenated */
273  } else if (type == MKTAG('R','A','W','C')) {
274  } else {
275  av_log(avctx, AV_LOG_INFO, "unsupported tag %s, size %u\n",
277  }
278  avio_skip(pb, size);
279  }
280  return 0;
281 }
282 
283 static int read_header(AVFormatContext *avctx)
284 {
285  MlvContext *mlv = avctx->priv_data;
286  AVIOContext *pb = avctx->pb;
287  AVStream *vst = NULL, *ast = NULL;
288  FFStream *vsti = NULL, *asti = NULL;
289  int size, ret;
290  unsigned nb_video_frames, nb_audio_frames;
291  uint64_t guid;
292  char guidstr[32];
293 
294  avio_skip(pb, 4);
295  size = avio_rl32(pb);
296  if (size < 52)
297  return AVERROR_INVALIDDATA;
298 
299  avio_skip(pb, 8);
300 
301  guid = avio_rl64(pb);
302  snprintf(guidstr, sizeof(guidstr), "0x%"PRIx64, guid);
303  av_dict_set(&avctx->metadata, "guid", guidstr, 0);
304 
305  avio_skip(pb, 8); //fileNum, fileCount, fileFlags
306 
307  mlv->class[0] = avio_rl16(pb);
308  mlv->class[1] = avio_rl16(pb);
309 
310  nb_video_frames = avio_rl32(pb);
311  nb_audio_frames = avio_rl32(pb);
312 
313  if (nb_video_frames && mlv->class[0]) {
314  vst = avformat_new_stream(avctx, NULL);
315  if (!vst)
316  return AVERROR(ENOMEM);
317  vsti = ffstream(vst);
318 
319  vst->id = 0;
320  vst->nb_frames = nb_video_frames;
322  avpriv_request_sample(avctx, "compression");
324  switch (mlv->class[0] & ~(MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA)) {
325  case MLV_VIDEO_CLASS_RAW:
327  break;
328  case MLV_VIDEO_CLASS_YUV:
331  vst->codecpar->codec_tag = 0;
332  break;
335  break;
338  vst->codecpar->codec_tag = 0;
339  break;
342  vst->codecpar->codec_tag = 0;
343  break;
344  default:
345  avpriv_request_sample(avctx, "unknown video class");
346  }
347  }
348 
349  if (nb_audio_frames && mlv->class[1]) {
350  ast = avformat_new_stream(avctx, NULL);
351  if (!ast)
352  return AVERROR(ENOMEM);
353  asti = ffstream(ast);
354  ast->id = 1;
355  ast->nb_frames = nb_audio_frames;
356  if ((mlv->class[1] & MLV_CLASS_FLAG_LZMA))
357  avpriv_request_sample(avctx, "compression");
358  if ((mlv->class[1] & ~MLV_CLASS_FLAG_LZMA) != MLV_AUDIO_CLASS_WAV)
359  avpriv_request_sample(avctx, "unknown audio class");
360 
361  ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
362  avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate);
363  }
364 
365  if (vst) {
367  framerate.num = avio_rl32(pb);
368  framerate.den = avio_rl32(pb);
369  avpriv_set_pts_info(vst, 64, framerate.den, framerate.num);
370  } else
371  avio_skip(pb, 8);
372 
373  avio_skip(pb, size - 52);
374 
375  /* scan primary file */
376  mlv->pb[100] = avctx->pb;
377  ret = scan_file(avctx, vst, ast, 100);
378  if (ret < 0)
379  return ret;
380 
381  /* scan secondary files */
382  if (strlen(avctx->url) > 2) {
383  int i;
384  char *filename = av_strdup(avctx->url);
385 
386  if (!filename)
387  return AVERROR(ENOMEM);
388 
389  for (i = 0; i < 100; i++) {
390  snprintf(filename + strlen(filename) - 2, 3, "%02d", i);
391  if (avctx->io_open(avctx, &mlv->pb[i], filename, AVIO_FLAG_READ, NULL) < 0)
392  break;
393  if (check_file_header(mlv->pb[i], guid) < 0) {
394  av_log(avctx, AV_LOG_WARNING, "ignoring %s; bad format or guid mismatch\n", filename);
395  ff_format_io_close(avctx, &mlv->pb[i]);
396  continue;
397  }
398  av_log(avctx, AV_LOG_INFO, "scanning %s\n", filename);
399  ret = scan_file(avctx, vst, ast, i);
400  if (ret < 0) {
401  av_log(avctx, AV_LOG_WARNING, "ignoring %s; %s\n", filename, av_err2str(ret));
402  ff_format_io_close(avctx, &mlv->pb[i]);
403  continue;
404  }
405  }
406  av_free(filename);
407  }
408 
409  if (vst)
410  vst->duration = vsti->nb_index_entries;
411  if (ast)
412  ast->duration = asti->nb_index_entries;
413 
414  if ((vst && !vsti->nb_index_entries) || (ast && !asti->nb_index_entries)) {
415  av_log(avctx, AV_LOG_ERROR, "no index entries found\n");
416  return AVERROR_INVALIDDATA;
417  }
418 
419  if (vst && ast)
420  avio_seek(pb, FFMIN(vsti->index_entries[0].pos, asti->index_entries[0].pos), SEEK_SET);
421  else if (vst)
422  avio_seek(pb, vsti->index_entries[0].pos, SEEK_SET);
423  else if (ast)
424  avio_seek(pb, asti->index_entries[0].pos, SEEK_SET);
425 
426  return 0;
427 }
428 
429 static void write_tiff_short(PutByteContext *pb, int tag, int value)
430 {
431  bytestream2_put_le16(pb, tag);
432  bytestream2_put_le16(pb, TIFF_SHORT);
433  bytestream2_put_le32(pb, 1);
434  bytestream2_put_le16(pb, value);
435  bytestream2_put_le16(pb, 0);
436 }
437 
438 static void write_tiff_short2(PutByteContext *pb, int tag, int v1, int v2)
439 {
440  bytestream2_put_le16(pb, tag);
441  bytestream2_put_le16(pb, TIFF_SHORT);
442  bytestream2_put_le32(pb, 2);
443  bytestream2_put_le16(pb, v1);
444  bytestream2_put_le16(pb, v2);
445 }
446 
447 static void write_tiff_long(PutByteContext *pb, int tag, int value)
448 {
449  bytestream2_put_le16(pb, tag);
450  bytestream2_put_le16(pb, TIFF_LONG);
451  bytestream2_put_le32(pb, 1);
452  bytestream2_put_le32(pb, value);
453 }
454 
455 static void write_tiff_byte4(PutByteContext *pb, int tag, int v1, int v2, int v3, int v4)
456 {
457  bytestream2_put_le16(pb, tag);
458  bytestream2_put_le16(pb, TIFF_BYTE);
459  bytestream2_put_le32(pb, 4);
460  bytestream2_put_byte(pb, v1);
461  bytestream2_put_byte(pb, v2);
462  bytestream2_put_byte(pb, v3);
463  bytestream2_put_byte(pb, v4);
464 }
465 
467 {
468  MlvContext *mlv = avctx->priv_data;
469  PutByteContext pbctx, *pb = &pbctx;
470  int ret, header_size;
471  uint8_t *stripofs, *matrixofs;
472 
473 #define MAX_HEADER_SIZE 2048
474  if ((ret = av_new_packet(pkt, size + MAX_HEADER_SIZE)) < 0)
475  return ret;
476 
478 
479  bytestream2_put_le16(pb, 0x4949);
480  bytestream2_put_le16(pb, 42);
481  bytestream2_put_le32(pb, 8);
482 
483  bytestream2_put_le16(pb, 18); /* nb_entries */
484 
492  write_tiff_long(pb, TIFF_STRIP_OFFS, 0); /* stripofs */
493  stripofs = pb->buffer - 4;
494 
500  write_tiff_byte4(pb, TIFF_CFA_PATTERN, 0, 1, 1, 2);
501  write_tiff_byte4(pb, DNG_VERSION, 1, 4, 0, 0);
504 
505  bytestream2_put_le16(pb, DNG_COLOR_MATRIX1);
506  bytestream2_put_le16(pb, TIFF_SRATIONAL);
507  bytestream2_put_le32(pb, 9);
508  bytestream2_put_le32(pb, 0); /* matrixofs */
509  matrixofs = pb->buffer - 4;
510  bytestream2_put_le32(pb, 0);
511 
512  AV_WL32(matrixofs, bytestream2_tell_p(pb));
513  for (int i = 0; i < 9; i++) {
514  bytestream2_put_le32(pb, mlv->color_matrix1[i][0]);
515  bytestream2_put_le32(pb, mlv->color_matrix1[i][1]);
516  }
517 
518  header_size = bytestream2_tell_p(pb);
519 
520  AV_WL32(stripofs, header_size);
521  ret = avio_read(pbio, pkt->data + header_size, size);
522  if (ret < 0)
523  return ret;
524 
525  return 0;
526 }
527 
529 {
530  MlvContext *mlv = avctx->priv_data;
531  AVIOContext *pb;
532  AVStream *st;
533  FFStream *sti;
534  int index, ret;
535  unsigned int size, space;
536 
537  if (!avctx->nb_streams)
538  return AVERROR_EOF;
539 
540  st = avctx->streams[mlv->stream_index];
541  sti = ffstream(st);
542  if (mlv->pts >= st->duration)
543  return AVERROR_EOF;
544 
546  if (index < 0) {
547  av_log(avctx, AV_LOG_ERROR, "could not find index entry for frame %"PRId64"\n", mlv->pts);
548  return AVERROR(EIO);
549  }
550 
551  pb = mlv->pb[sti->index_entries[index].size];
552  if (!pb) {
553  ret = FFERROR_REDO;
554  goto next_packet;
555  }
556  avio_seek(pb, sti->index_entries[index].pos, SEEK_SET);
557 
558  avio_skip(pb, 4); // blockType
559  size = avio_rl32(pb);
560  if (size < 16)
561  return AVERROR_INVALIDDATA;
562  avio_skip(pb, 12); //timestamp, frameNumber
563  size -= 12;
564  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
565  avio_skip(pb, 8); // cropPosX, cropPosY, panPosX, panPosY
566  size -= 8;
567  }
568  space = avio_rl32(pb);
569  avio_skip(pb, space);
570  size -= space;
571 
572  if ((mlv->class[st->id] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) {
574  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
575  if (st->codecpar->codec_id == AV_CODEC_ID_TIFF)
576  ret = get_packet_lj92(avctx, st, pb, pkt, size);
577  else
578  ret = av_get_packet(pb, pkt, (st->codecpar->width * st->codecpar->height * st->codecpar->bits_per_coded_sample + 7) >> 3);
579  } else { // AVMEDIA_TYPE_AUDIO
580  if (space > UINT_MAX - 24 || size < (24 + space))
581  return AVERROR_INVALIDDATA;
582  ret = av_get_packet(pb, pkt, size - (24 + space));
583  }
584 
585  if (ret < 0)
586  return ret;
587 
588  pkt->stream_index = mlv->stream_index;
589  pkt->pts = mlv->pts;
590 
591  ret = 0;
592 next_packet:
593  mlv->stream_index++;
594  if (mlv->stream_index == avctx->nb_streams) {
595  mlv->stream_index = 0;
596  mlv->pts++;
597  }
598  return ret;
599 }
600 
601 static int read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
602 {
603  MlvContext *mlv = avctx->priv_data;
604 
606  return AVERROR(ENOSYS);
607 
608  if (!(avctx->pb->seekable & AVIO_SEEKABLE_NORMAL))
609  return AVERROR(EIO);
610 
611  mlv->pts = timestamp;
612  return 0;
613 }
614 
616 {
617  MlvContext *mlv = s->priv_data;
618  int i;
619  for (i = 0; i < 100; i++)
620  ff_format_io_close(s, &mlv->pb[i]);
621  return 0;
622 }
623 
625  .p.name = "mlv",
626  .p.long_name = NULL_IF_CONFIG_SMALL("Magic Lantern Video (MLV)"),
627  .priv_data_size = sizeof(MlvContext),
628  .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
629  .read_probe = probe,
633  .read_seek = read_seek,
634 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
MLV_VIDEO_CLASS_RAW
#define MLV_VIDEO_CLASS_RAW
Definition: mlvdec.c:43
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
space
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated space
Definition: undefined.txt:4
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
MLV_AUDIO_CLASS_WAV
#define MLV_AUDIO_CLASS_WAV
Definition: mlvdec.c:48
AVSEEK_FLAG_FRAME
#define AVSEEK_FLAG_FRAME
seeking based on frame number
Definition: avformat.h:2502
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
TIFF_CFA_PATTERN_DIM
@ TIFF_CFA_PATTERN_DIM
Definition: tiff.h:87
rational.h
int64_t
long long int64_t
Definition: coverity.c:34
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:65
MlvContext::stream_index
int stream_index
Definition: mlvdec.c:57
read_uint64
static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition: mlvdec.c:124
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1368
AVPacket::data
uint8_t * data
Definition: packet.h:539
TIFF_LONG
@ TIFF_LONG
Definition: tiff_common.h:40
bytestream2_tell_p
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:197
read_string
static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag, unsigned size)
Definition: mlvdec.c:89
AVSEEK_FLAG_BYTE
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition: avformat.h:2500
MlvContext::black_level
int black_level
Definition: mlvdec.c:59
ff_mlv_demuxer
const FFInputFormat ff_mlv_demuxer
Definition: mlvdec.c:624
read_uint32
static void read_uint32(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition: mlvdec.c:119
TIFF_NEWJPEG
@ TIFF_NEWJPEG
Definition: tiff.h:132
ff_get_wav_header
int ff_get_wav_header(void *logctx, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition: riffdec.c:95
write_tiff_short
static void write_tiff_short(PutByteContext *pb, int tag, int value)
Definition: mlvdec.c:429
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
TIFF_ROWSPERSTRIP
@ TIFF_ROWSPERSTRIP
Definition: tiff.h:58
scan_file
static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file)
Definition: mlvdec.c:129
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:610
TIFF_FILL_ORDER
@ TIFF_FILL_ORDER
Definition: tiff.h:51
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
avpriv_set_pts_info
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:868
MlvContext
Definition: mlvdec.c:54
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:358
AVSEEK_FLAG_ANY
#define AVSEEK_FLAG_ANY
seek to any frame, even non-keyframes
Definition: avformat.h:2501
FFStream::index_entries_allocated_size
unsigned int index_entries_allocated_size
Definition: internal.h:191
AVIOContext::pos
int64_t pos
position in the file of the current buffer
Definition: avio.h:237
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:644
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:807
read_header
static int read_header(AVFormatContext *avctx)
Definition: mlvdec.c:283
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:714
AV_DICT_DONT_STRDUP_VAL
#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
TIFF_SHORT
@ TIFF_SHORT
Definition: tiff_common.h:39
write_tiff_long
static void write_tiff_long(PutByteContext *pb, int tag, int value)
Definition: mlvdec.c:447
read_seek
static int read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
Definition: mlvdec.c:601
MAX_HEADER_SIZE
#define MAX_HEADER_SIZE
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1535
read_uint16
static void read_uint16(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition: mlvdec.c:114
TIFF_SUBFILE
@ TIFF_SUBFILE
Definition: tiff.h:45
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
MLV_VERSION
#define MLV_VERSION
Definition: mlvdec.c:41
read_uint8
static void read_uint8(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
Definition: mlvdec.c:109
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: packet.c:99
MlvContext::pb
AVIOContext * pb[101]
Definition: mlvdec.c:55
AV_PIX_FMT_BAYER_RGGB16LE
@ AV_PIX_FMT_BAYER_RGGB16LE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:291
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
AVIndexEntry::size
int size
Definition: avformat.h:613
TIFF_STRIP_SIZE
@ TIFF_STRIP_SIZE
Definition: tiff.h:59
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
FF_INFMT_FLAG_INIT_CLEANUP
#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
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
framerate
float framerate
Definition: av1_levels.c:29
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
read_close
static int read_close(AVFormatContext *s)
Definition: mlvdec.c:615
MLV_VIDEO_CLASS_JPEG
#define MLV_VIDEO_CLASS_JPEG
Definition: mlvdec.c:45
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MlvContext::white_level
int white_level
Definition: mlvdec.c:60
MlvContext::color_matrix1
int color_matrix1[9][2]
Definition: mlvdec.c:61
tiff.h
tiff_common.h
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1342
read_packet
static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: mlvdec.c:528
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:190
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
time.h
TIFF_BYTE
@ TIFF_BYTE
Definition: tiff_common.h:37
TIFF_SAMPLES_PER_PIXEL
@ TIFF_SAMPLES_PER_PIXEL
Definition: tiff.h:57
TIFF_SRATIONAL
@ TIFF_SRATIONAL
Definition: tiff_common.h:46
TIFF_WIDTH
@ TIFF_WIDTH
Definition: tiff.h:46
index
int index
Definition: gxfenc.c:90
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:809
write_tiff_short2
static void write_tiff_short2(PutByteContext *pb, int tag, int v1, int v2)
Definition: mlvdec.c:438
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1356
PutByteContext
Definition: bytestream.h:37
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:730
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
height
#define height
Definition: dsp.h:85
FFStream
Definition: internal.h:132
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1416
PutByteContext::buffer
uint8_t * buffer
Definition: bytestream.h:38
size
int size
Definition: twinvq_data.h:10344
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:959
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:46
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:603
MLV_VIDEO_CLASS_YUV
#define MLV_VIDEO_CLASS_YUV
Definition: mlvdec.c:44
version
version
Definition: libkvazaar.c:321
TIFF_COMPR
@ TIFF_COMPR
Definition: tiff.h:49
TIFF_HEIGHT
@ TIFF_HEIGHT
Definition: tiff.h:47
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
FFERROR_REDO
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition: demux.h:176
DNG_BLACK_LEVEL
@ DNG_BLACK_LEVEL
Definition: tiff.h:104
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
check_file_header
static int check_file_header(AVIOContext *pb, uint64_t guid)
Definition: mlvdec.c:73
TIFF_PHOTOMETRIC_CFA
@ TIFF_PHOTOMETRIC_CFA
Definition: tiff.h:200
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
AVCodecParameters::height
int height
Definition: codec_par.h:135
TIFF_PLANAR
@ TIFF_PLANAR
Definition: tiff.h:62
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
demux.h
DNG_VERSION
@ DNG_VERSION
Definition: tiff.h:101
TIFF_CFA_PATTERN
@ TIFF_CFA_PATTERN
Definition: tiff.h:88
TIFF_STRIP_OFFS
@ TIFF_STRIP_OFFS
Definition: tiff.h:56
ff_add_index_entry
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
av_get_packet
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:91
get_packet_lj92
static int get_packet_lj92(AVFormatContext *avctx, AVStream *st, AVIOContext *pbio, AVPacket *pkt, int64_t size)
Definition: mlvdec.c:466
MLV_VIDEO_CLASS_H264
#define MLV_VIDEO_CLASS_H264
Definition: mlvdec.c:46
tag
uint32_t tag
Definition: movenc.c:1879
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:760
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
DNG_WHITE_LEVEL
@ DNG_WHITE_LEVEL
Definition: tiff.h:105
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
TIFF_BPP
@ TIFF_BPP
Definition: tiff.h:48
avformat.h
TIFF_PHOTOMETRIC
@ TIFF_PHOTOMETRIC
Definition: tiff.h:50
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:612
AVFormatContext::io_open
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:1903
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:603
MLV_CLASS_FLAG_DELTA
#define MLV_CLASS_FLAG_DELTA
Definition: mlvdec.c:51
AVPacket::stream_index
int stream_index
Definition: packet.h:541
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:318
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:188
av_dict_set_int
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:167
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:617
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
read_probe
static int read_probe(const AVProbeData *p)
Definition: cdg.c:30
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
mem.h
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVCodecParameters::format
int format
Definition: codec_par.h:92
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:516
av_dict_set
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:88
riff.h
DNG_COLOR_MATRIX1
@ DNG_COLOR_MATRIX1
Definition: tiff.h:106
FFInputFormat
Definition: demux.h:42
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:738
bytestream.h
MLV_CLASS_FLAG_LJ92
#define MLV_CLASS_FLAG_LJ92
Definition: mlvdec.c:50
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
MLV_CLASS_FLAG_LZMA
#define MLV_CLASS_FLAG_LZMA
Definition: mlvdec.c:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
probe
static int probe(const AVProbeData *p)
Definition: mlvdec.c:64
AV_CODEC_ID_TIFF
@ AV_CODEC_ID_TIFF
Definition: codec_id.h:148
av_image_check_size
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
width
#define width
Definition: dsp.h:85
snprintf
#define snprintf
Definition: snprintf.h:34
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1328
write_tiff_byte4
static void write_tiff_byte4(PutByteContext *pb, int tag, int v1, int v2, int v3, int v4)
Definition: mlvdec.c:455
MlvContext::class
int class[2]
Definition: mlvdec.c:56
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:348
av_index_search_timestamp
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: seek.c:245
MlvContext::pts
uint64_t pts
Definition: mlvdec.c:58
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:346