ffmdec.c
Go to the documentation of this file.
1 /*
2  * FFM (ffserver live feed) demuxer
3  * Copyright (c) 2001 Fabrice Bellard
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 #include "libavutil/intreadwrite.h"
23 #include "libavutil/intfloat.h"
24 #include "avformat.h"
25 #include "internal.h"
26 #include "ffm.h"
27 #include "avio_internal.h"
28 
30 {
31  FFMContext *ffm = s->priv_data;
32  int64_t pos, avail_size;
33  int len;
34 
35  len = ffm->packet_end - ffm->packet_ptr;
36  if (size <= len)
37  return 1;
38  pos = avio_tell(s->pb);
39  if (!ffm->write_index) {
40  if (pos == ffm->file_size)
41  return AVERROR_EOF;
42  avail_size = ffm->file_size - pos;
43  } else {
44  if (pos == ffm->write_index) {
45  /* exactly at the end of stream */
46  return AVERROR(EAGAIN);
47  } else if (pos < ffm->write_index) {
48  avail_size = ffm->write_index - pos;
49  } else {
50  avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
51  }
52  }
53  avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
54  if (size <= avail_size)
55  return 1;
56  else
57  return AVERROR(EAGAIN);
58 }
59 
60 static int ffm_resync(AVFormatContext *s, int state)
61 {
62  av_log(s, AV_LOG_ERROR, "resyncing\n");
63  while (state != PACKET_ID) {
64  if (url_feof(s->pb)) {
65  av_log(s, AV_LOG_ERROR, "cannot find FFM syncword\n");
66  return -1;
67  }
68  state = (state << 8) | avio_r8(s->pb);
69  }
70  return 0;
71 }
72 
73 /* first is true if we read the frame header */
75  uint8_t *buf, int size, int header)
76 {
77  FFMContext *ffm = s->priv_data;
78  AVIOContext *pb = s->pb;
79  int len, fill_size, size1, frame_offset, id;
80 
81  size1 = size;
82  while (size > 0) {
83  redo:
84  len = ffm->packet_end - ffm->packet_ptr;
85  if (len < 0)
86  return -1;
87  if (len > size)
88  len = size;
89  if (len == 0) {
90  if (avio_tell(pb) == ffm->file_size)
91  avio_seek(pb, ffm->packet_size, SEEK_SET);
92  retry_read:
93  if (pb->buffer_size != ffm->packet_size) {
94  int64_t tell = avio_tell(pb);
96  avio_seek(pb, tell, SEEK_SET);
97  }
98  id = avio_rb16(pb); /* PACKET_ID */
99  if (id != PACKET_ID)
100  if (ffm_resync(s, id) < 0)
101  return -1;
102  fill_size = avio_rb16(pb);
103  ffm->dts = avio_rb64(pb);
104  frame_offset = avio_rb16(pb);
105  avio_read(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
106  ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
107  if (ffm->packet_end < ffm->packet || frame_offset < 0)
108  return -1;
109  /* if first packet or resynchronization packet, we must
110  handle it specifically */
111  if (ffm->first_packet || (frame_offset & 0x8000)) {
112  if (!frame_offset) {
113  /* This packet has no frame headers in it */
114  if (avio_tell(pb) >= ffm->packet_size * 3LL) {
115  avio_seek(pb, -ffm->packet_size * 2LL, SEEK_CUR);
116  goto retry_read;
117  }
118  /* This is bad, we cannot find a valid frame header */
119  return 0;
120  }
121  ffm->first_packet = 0;
122  if ((frame_offset & 0x7fff) < FFM_HEADER_SIZE)
123  return -1;
124  ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;
125  if (!header)
126  break;
127  } else {
128  ffm->packet_ptr = ffm->packet;
129  }
130  goto redo;
131  }
132  memcpy(buf, ffm->packet_ptr, len);
133  buf += len;
134  ffm->packet_ptr += len;
135  size -= len;
136  header = 0;
137  }
138  return size1 - size;
139 }
140 
141 /* ensure that acutal seeking happens between FFM_PACKET_SIZE
142  and file_size - FFM_PACKET_SIZE */
143 static int64_t ffm_seek1(AVFormatContext *s, int64_t pos1)
144 {
145  FFMContext *ffm = s->priv_data;
146  AVIOContext *pb = s->pb;
147  int64_t pos;
148 
149  pos = FFMIN(pos1, ffm->file_size - FFM_PACKET_SIZE);
150  pos = FFMAX(pos, FFM_PACKET_SIZE);
151  av_dlog(s, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos);
152  return avio_seek(pb, pos, SEEK_SET);
153 }
154 
155 static int64_t get_dts(AVFormatContext *s, int64_t pos)
156 {
157  AVIOContext *pb = s->pb;
158  int64_t dts;
159 
160  ffm_seek1(s, pos);
161  avio_skip(pb, 4);
162  dts = avio_rb64(pb);
163  av_dlog(s, "dts=%0.6f\n", dts / 1000000.0);
164  return dts;
165 }
166 
168 {
169  FFMContext *ffm = s->priv_data;
170  AVIOContext *pb = s->pb;
171  int64_t pts;
172  //int64_t orig_write_index = ffm->write_index;
173  int64_t pos_min, pos_max;
174  int64_t pts_start;
175  int64_t ptr = avio_tell(pb);
176 
177 
178  pos_min = 0;
179  pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
180 
181  pts_start = get_dts(s, pos_min);
182 
183  pts = get_dts(s, pos_max);
184 
185  if (pts - 100000 > pts_start)
186  goto end;
187 
189 
190  pts_start = get_dts(s, pos_min);
191 
192  pts = get_dts(s, pos_max);
193 
194  if (pts - 100000 <= pts_start) {
195  while (1) {
196  int64_t newpos;
197  int64_t newpts;
198 
199  newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE;
200 
201  if (newpos == pos_min)
202  break;
203 
204  newpts = get_dts(s, newpos);
205 
206  if (newpts - 100000 <= pts) {
207  pos_max = newpos;
208  pts = newpts;
209  } else {
210  pos_min = newpos;
211  }
212  }
213  ffm->write_index += pos_max;
214  }
215 
216  end:
217  avio_seek(pb, ptr, SEEK_SET);
218 }
219 
220 
222 {
223  int i;
224 
225  for (i = 0; i < s->nb_streams; i++)
226  av_freep(&s->streams[i]->codec->rc_eq);
227 
228  return 0;
229 }
230 
232 {
233  FFMContext *ffm = s->priv_data;
234  AVStream *st;
235  AVIOContext *pb = s->pb;
236  AVCodecContext *codec;
237 
238  ffm->packet_size = avio_rb32(pb);
239  if (ffm->packet_size != FFM_PACKET_SIZE)
240  goto fail;
241  ffm->write_index = avio_rb64(pb);
242  /* get also filesize */
243  if (pb->seekable) {
244  ffm->file_size = avio_size(pb);
245  if (ffm->write_index && 0)
247  } else {
248  ffm->file_size = (UINT64_C(1) << 63) - 1;
249  }
250 
251  while(!url_feof(pb)) {
252  unsigned id = avio_rb32(pb);
253  unsigned size = avio_rb32(pb);
254  int64_t next = avio_tell(pb) + size;
255  char rc_eq_buf[128];
256 
257  if(!id)
258  break;
259 
260  switch(id) {
261  case MKBETAG('M', 'A', 'I', 'N'):
262  avio_rb32(pb); /* nb_streams */
263  avio_rb32(pb); /* total bitrate */
264  break;
265  case MKBETAG('C', 'O', 'M', 'M'):
266  st = avformat_new_stream(s, NULL);
267  if (!st)
268  goto fail;
269 
270  avpriv_set_pts_info(st, 64, 1, 1000000);
271 
272  codec = st->codec;
273  /* generic info */
274  codec->codec_id = avio_rb32(pb);
275  codec->codec_type = avio_r8(pb);
276  codec->bit_rate = avio_rb32(pb);
277  codec->flags = avio_rb32(pb);
278  codec->flags2 = avio_rb32(pb);
279  codec->debug = avio_rb32(pb);
280  if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) {
281  codec->extradata_size = avio_rb32(pb);
282  codec->extradata = av_malloc(codec->extradata_size);
283  if (!codec->extradata)
284  return AVERROR(ENOMEM);
285  avio_read(pb, codec->extradata, codec->extradata_size);
286  }
287  avio_seek(pb, next, SEEK_SET);
288  id = avio_rb32(pb);
289  size = avio_rb32(pb);
290  next = avio_tell(pb) + size;
291  switch(id) {
292  case MKBETAG('S', 'T', 'V', 'I'):
293  codec->time_base.num = avio_rb32(pb);
294  codec->time_base.den = avio_rb32(pb);
295  codec->width = avio_rb16(pb);
296  codec->height = avio_rb16(pb);
297  codec->gop_size = avio_rb16(pb);
298  codec->pix_fmt = avio_rb32(pb);
299  codec->qmin = avio_r8(pb);
300  codec->qmax = avio_r8(pb);
301  codec->max_qdiff = avio_r8(pb);
302  codec->qcompress = avio_rb16(pb) / 10000.0;
303  codec->qblur = avio_rb16(pb) / 10000.0;
304  codec->bit_rate_tolerance = avio_rb32(pb);
305  avio_get_str(pb, INT_MAX, rc_eq_buf, sizeof(rc_eq_buf));
306  codec->rc_eq = av_strdup(rc_eq_buf);
307  codec->rc_max_rate = avio_rb32(pb);
308  codec->rc_min_rate = avio_rb32(pb);
309  codec->rc_buffer_size = avio_rb32(pb);
310  codec->i_quant_factor = av_int2double(avio_rb64(pb));
311  codec->b_quant_factor = av_int2double(avio_rb64(pb));
312  codec->i_quant_offset = av_int2double(avio_rb64(pb));
313  codec->b_quant_offset = av_int2double(avio_rb64(pb));
314  codec->dct_algo = avio_rb32(pb);
315  codec->strict_std_compliance = avio_rb32(pb);
316  codec->max_b_frames = avio_rb32(pb);
317  codec->mpeg_quant = avio_rb32(pb);
318  codec->intra_dc_precision = avio_rb32(pb);
319  codec->me_method = avio_rb32(pb);
320  codec->mb_decision = avio_rb32(pb);
321  codec->nsse_weight = avio_rb32(pb);
322  codec->frame_skip_cmp = avio_rb32(pb);
324  codec->codec_tag = avio_rb32(pb);
325  codec->thread_count = avio_r8(pb);
326  codec->coder_type = avio_rb32(pb);
327  codec->me_cmp = avio_rb32(pb);
328  codec->me_subpel_quality = avio_rb32(pb);
329  codec->me_range = avio_rb32(pb);
330  codec->keyint_min = avio_rb32(pb);
331  codec->scenechange_threshold = avio_rb32(pb);
332  codec->b_frame_strategy = avio_rb32(pb);
333  codec->qcompress = av_int2double(avio_rb64(pb));
334  codec->qblur = av_int2double(avio_rb64(pb));
335  codec->max_qdiff = avio_rb32(pb);
336  codec->refs = avio_rb32(pb);
337  break;
338  case MKBETAG('S', 'T', 'A', 'U'):
339  codec->sample_rate = avio_rb32(pb);
340  codec->channels = avio_rl16(pb);
341  codec->frame_size = avio_rl16(pb);
342  break;
343  }
344  break;
345  }
346  avio_seek(pb, next, SEEK_SET);
347  }
348 
349  /* get until end of block reached */
350  while ((avio_tell(pb) % ffm->packet_size) != 0)
351  avio_r8(pb);
352 
353  /* init packet demux */
354  ffm->packet_ptr = ffm->packet;
355  ffm->packet_end = ffm->packet;
356  ffm->frame_offset = 0;
357  ffm->dts = 0;
358  ffm->read_state = READ_HEADER;
359  ffm->first_packet = 1;
360  return 0;
361  fail:
362  ffm_close(s);
363  return -1;
364 }
365 
367 {
368  FFMContext *ffm = s->priv_data;
369  AVStream *st;
370  AVIOContext *pb = s->pb;
371  AVCodecContext *codec;
372  int i, nb_streams;
373  uint32_t tag;
374 
375  /* header */
376  tag = avio_rl32(pb);
377  if (tag == MKTAG('F', 'F', 'M', '2'))
378  return ffm2_read_header(s);
379  if (tag != MKTAG('F', 'F', 'M', '1'))
380  goto fail;
381  ffm->packet_size = avio_rb32(pb);
382  if (ffm->packet_size != FFM_PACKET_SIZE)
383  goto fail;
384  ffm->write_index = avio_rb64(pb);
385  /* get also filesize */
386  if (pb->seekable) {
387  ffm->file_size = avio_size(pb);
388  if (ffm->write_index && 0)
390  } else {
391  ffm->file_size = (UINT64_C(1) << 63) - 1;
392  }
393 
394  nb_streams = avio_rb32(pb);
395  avio_rb32(pb); /* total bitrate */
396  /* read each stream */
397  for(i=0;i<nb_streams;i++) {
398  char rc_eq_buf[128];
399 
400  st = avformat_new_stream(s, NULL);
401  if (!st)
402  goto fail;
403 
404  avpriv_set_pts_info(st, 64, 1, 1000000);
405 
406  codec = st->codec;
407  /* generic info */
408  codec->codec_id = avio_rb32(pb);
409  codec->codec_type = avio_r8(pb); /* codec_type */
410  codec->bit_rate = avio_rb32(pb);
411  codec->flags = avio_rb32(pb);
412  codec->flags2 = avio_rb32(pb);
413  codec->debug = avio_rb32(pb);
414  /* specific info */
415  switch(codec->codec_type) {
416  case AVMEDIA_TYPE_VIDEO:
417  codec->time_base.num = avio_rb32(pb);
418  codec->time_base.den = avio_rb32(pb);
419  codec->width = avio_rb16(pb);
420  codec->height = avio_rb16(pb);
421  codec->gop_size = avio_rb16(pb);
422  codec->pix_fmt = avio_rb32(pb);
423  codec->qmin = avio_r8(pb);
424  codec->qmax = avio_r8(pb);
425  codec->max_qdiff = avio_r8(pb);
426  codec->qcompress = avio_rb16(pb) / 10000.0;
427  codec->qblur = avio_rb16(pb) / 10000.0;
428  codec->bit_rate_tolerance = avio_rb32(pb);
429  avio_get_str(pb, INT_MAX, rc_eq_buf, sizeof(rc_eq_buf));
430  codec->rc_eq = av_strdup(rc_eq_buf);
431  codec->rc_max_rate = avio_rb32(pb);
432  codec->rc_min_rate = avio_rb32(pb);
433  codec->rc_buffer_size = avio_rb32(pb);
434  codec->i_quant_factor = av_int2double(avio_rb64(pb));
435  codec->b_quant_factor = av_int2double(avio_rb64(pb));
436  codec->i_quant_offset = av_int2double(avio_rb64(pb));
437  codec->b_quant_offset = av_int2double(avio_rb64(pb));
438  codec->dct_algo = avio_rb32(pb);
439  codec->strict_std_compliance = avio_rb32(pb);
440  codec->max_b_frames = avio_rb32(pb);
441  codec->mpeg_quant = avio_rb32(pb);
442  codec->intra_dc_precision = avio_rb32(pb);
443  codec->me_method = avio_rb32(pb);
444  codec->mb_decision = avio_rb32(pb);
445  codec->nsse_weight = avio_rb32(pb);
446  codec->frame_skip_cmp = avio_rb32(pb);
448  codec->codec_tag = avio_rb32(pb);
449  codec->thread_count = avio_r8(pb);
450  codec->coder_type = avio_rb32(pb);
451  codec->me_cmp = avio_rb32(pb);
452  codec->me_subpel_quality = avio_rb32(pb);
453  codec->me_range = avio_rb32(pb);
454  codec->keyint_min = avio_rb32(pb);
455  codec->scenechange_threshold = avio_rb32(pb);
456  codec->b_frame_strategy = avio_rb32(pb);
457  codec->qcompress = av_int2double(avio_rb64(pb));
458  codec->qblur = av_int2double(avio_rb64(pb));
459  codec->max_qdiff = avio_rb32(pb);
460  codec->refs = avio_rb32(pb);
461  break;
462  case AVMEDIA_TYPE_AUDIO:
463  codec->sample_rate = avio_rb32(pb);
464  codec->channels = avio_rl16(pb);
465  codec->frame_size = avio_rl16(pb);
466  break;
467  default:
468  goto fail;
469  }
470  if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) {
471  codec->extradata_size = avio_rb32(pb);
472  codec->extradata = av_malloc(codec->extradata_size);
473  if (!codec->extradata)
474  return AVERROR(ENOMEM);
475  avio_read(pb, codec->extradata, codec->extradata_size);
476  }
477  }
478 
479  /* get until end of block reached */
480  while ((avio_tell(pb) % ffm->packet_size) != 0)
481  avio_r8(pb);
482 
483  /* init packet demux */
484  ffm->packet_ptr = ffm->packet;
485  ffm->packet_end = ffm->packet;
486  ffm->frame_offset = 0;
487  ffm->dts = 0;
488  ffm->read_state = READ_HEADER;
489  ffm->first_packet = 1;
490  return 0;
491  fail:
492  ffm_close(s);
493  return -1;
494 }
495 
496 /* return < 0 if eof */
498 {
499  int size;
500  FFMContext *ffm = s->priv_data;
501  int duration, ret;
502 
503  switch(ffm->read_state) {
504  case READ_HEADER:
505  if ((ret = ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) < 0)
506  return ret;
507 
508  av_dlog(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n",
509  avio_tell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size);
510  if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
512  return -1;
513  if (ffm->header[1] & FLAG_DTS)
514  if (ffm_read_data(s, ffm->header+16, 4, 1) != 4)
515  return -1;
516  ffm->read_state = READ_DATA;
517  /* fall thru */
518  case READ_DATA:
519  size = AV_RB24(ffm->header + 2);
520  if ((ret = ffm_is_avail_data(s, size)) < 0)
521  return ret;
522 
523  duration = AV_RB24(ffm->header + 5);
524 
525  if (av_new_packet(pkt, size) < 0) {
526  return AVERROR(ENOMEM);
527  }
528  pkt->stream_index = ffm->header[0];
529  if ((unsigned)pkt->stream_index >= s->nb_streams) {
530  av_log(s, AV_LOG_ERROR, "invalid stream index %d\n", pkt->stream_index);
531  av_free_packet(pkt);
532  ffm->read_state = READ_HEADER;
533  return -1;
534  }
535  pkt->pos = avio_tell(s->pb);
536  if (ffm->header[1] & FLAG_KEY_FRAME)
537  pkt->flags |= AV_PKT_FLAG_KEY;
538 
539  ffm->read_state = READ_HEADER;
540  if (ffm_read_data(s, pkt->data, size, 0) != size) {
541  /* bad case: desynchronized packet. we cancel all the packet loading */
542  av_free_packet(pkt);
543  return -1;
544  }
545  pkt->pts = AV_RB64(ffm->header+8);
546  if (ffm->header[1] & FLAG_DTS)
547  pkt->dts = pkt->pts - AV_RB32(ffm->header+16);
548  else
549  pkt->dts = pkt->pts;
550  pkt->duration = duration;
551  break;
552  }
553  return 0;
554 }
555 
556 /* seek to a given time in the file. The file read pointer is
557  positioned at or before pts. XXX: the following code is quite
558  approximative */
559 static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags)
560 {
561  FFMContext *ffm = s->priv_data;
562  int64_t pos_min, pos_max, pos;
563  int64_t pts_min, pts_max, pts;
564  double pos1;
565 
566  av_dlog(s, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
567  /* find the position using linear interpolation (better than
568  dichotomy in typical cases) */
569  if (ffm->write_index && ffm->write_index < ffm->file_size) {
570  if (get_dts(s, FFM_PACKET_SIZE) < wanted_pts) {
571  pos_min = FFM_PACKET_SIZE;
572  pos_max = ffm->write_index - FFM_PACKET_SIZE;
573  } else {
574  pos_min = ffm->write_index;
575  pos_max = ffm->file_size - FFM_PACKET_SIZE;
576  }
577  } else {
578  pos_min = FFM_PACKET_SIZE;
579  pos_max = ffm->file_size - FFM_PACKET_SIZE;
580  }
581  while (pos_min <= pos_max) {
582  pts_min = get_dts(s, pos_min);
583  pts_max = get_dts(s, pos_max);
584  if (pts_min > wanted_pts || pts_max <= wanted_pts) {
585  pos = pts_min > wanted_pts ? pos_min : pos_max;
586  goto found;
587  }
588  /* linear interpolation */
589  pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
590  (double)(pts_max - pts_min);
591  pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;
592  if (pos <= pos_min)
593  pos = pos_min;
594  else if (pos >= pos_max)
595  pos = pos_max;
596  pts = get_dts(s, pos);
597  /* check if we are lucky */
598  if (pts == wanted_pts) {
599  goto found;
600  } else if (pts > wanted_pts) {
601  pos_max = pos - FFM_PACKET_SIZE;
602  } else {
603  pos_min = pos + FFM_PACKET_SIZE;
604  }
605  }
606  pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
607 
608  found:
609  if (ffm_seek1(s, pos) < 0)
610  return -1;
611 
612  /* reset read state */
613  ffm->read_state = READ_HEADER;
614  ffm->packet_ptr = ffm->packet;
615  ffm->packet_end = ffm->packet;
616  ffm->first_packet = 1;
617 
618  return 0;
619 }
620 
621 static int ffm_probe(AVProbeData *p)
622 {
623  if (
624  p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
625  (p->buf[3] == '1' || p->buf[3] == '2'))
626  return AVPROBE_SCORE_MAX + 1;
627  return 0;
628 }
629 
631  .name = "ffm",
632  .long_name = NULL_IF_CONFIG_SMALL("FFM (FFserver live feed)"),
633  .priv_data_size = sizeof(FFMContext),
638  .read_seek = ffm_seek,
639 };
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:1743
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
Definition: ffm.h:41
#define PACKET_ID
Definition: ffm.h:32
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:261
struct FFMContext FFMContext
int64_t dts
Definition: ffm.h:54
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
int mpeg_quant
0-> h263 quant 1-> mpeg quant
int dct_algo
DCT algorithm, see FF_DCT_* below.
enum AVCodecID id
Definition: mxfenc.c:89
int frame_offset
Definition: ffm.h:53
float qblur
amount of qscale smoothing over time (0.0-1.0)
int64_t pos
byte position in stream, -1 if unknown
#define AV_RB64
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
int num
numerator
Definition: rational.h:44
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
#define AV_RB24
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
#define FLAG_DTS
Definition: ffm.h:37
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:595
int frame_skip_cmp
frame skip comparison function
static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: ffmdec.c:497
static int ffm_read_data(AVFormatContext *s, uint8_t *buf, int size, int header)
Definition: ffmdec.c:74
float i_quant_offset
qscale offset between P and I-frames
int scenechange_threshold
scene change detection threshold 0 is default, larger means fewer detected scene changes.
#define FFM_HEADER_SIZE
Definition: ffm.h:30
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
static int ffm_resync(AVFormatContext *s, int state)
Definition: ffmdec.c:60
Format I/O context.
Definition: avformat.h:944
int64_t file_size
Definition: ffm.h:46
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition: intfloat.h:60
uint8_t
static int64_t get_dts(AVFormatContext *s, int64_t pos)
Definition: ffmdec.c:155
#define FRAME_HEADER_SIZE
Definition: cpia.c:30
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:610
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_RB32
static AVPacket pkt
Definition: demuxing.c:56
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
end end
uint8_t * packet_end
Definition: ffm.h:55
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int me_cmp
motion estimation comparison function
AVStream ** streams
Definition: avformat.h:992
static int ffm_is_avail_data(AVFormatContext *s, int size)
Definition: ffmdec.c:29
int coder_type
coder type
uint8_t * data
uint32_t tag
Definition: movenc.c:894
#define AVERROR_EOF
End of file.
Definition: error.h:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:675
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
static int64_t duration
Definition: ffplay.c:294
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
static int ffm2_read_header(AVFormatContext *s)
Definition: ffmdec.c:231
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:73
uint8_t * packet_ptr
Definition: ffm.h:55
static void adjust_write_index(AVFormatContext *s)
Definition: ffmdec.c:167
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:579
int ffio_set_buf_size(AVIOContext *s, int buf_size)
Definition: aviobuf.c:726
int qmax
maximum quantizer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int flags
CODEC_FLAG_*.
int rc_max_rate
maximum bitrate
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
float i_quant_factor
qscale factor between P and I-frames If > 0 then the last p frame quantizer will be used (q= lastp_q*...
const char * rc_eq
rate control equation
static int ffm_probe(AVProbeData *p)
Definition: ffmdec.c:621
#define FFMAX(a, b)
Definition: common.h:56
int size
int first_packet
Definition: ffm.h:51
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
int rc_buffer_size
decoder bitstream buffer size
int intra_dc_precision
precision of the intra DC coefficient - 8
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
int refs
number of reference frames
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
int bit_rate
the average bitrate
#define FFMIN(a, b)
Definition: common.h:58
static int read_probe(AVProbeData *pd)
ret
Definition: avfilter.c:821
int width
picture width / height.
uint8_t header[FRAME_HEADER_SIZE+4]
Definition: ffm.h:48
int mb_decision
macroblock decision mode
int max_qdiff
maximum quantizer difference between frames
int packet_size
Definition: ffm.h:52
int buffer_size
Maximum buffer size.
Definition: avio.h:83
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
int frame_size
Number of samples per channel in an audio frame.
NULL
Definition: eval.c:55
static int ffm_close(AVFormatContext *s)
Definition: ffmdec.c:221
enum AVMediaType codec_type
enum AVCodecID codec_id
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
Definition: ffm.h:44
main external API structure.
int qmin
minimum quantizer
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
static int write_index(NUTContext *nut, AVIOContext *bc)
Definition: nutenc.c:565
void * buf
Definition: avisynth_c.h:594
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
synthesis window for stochastic i
static int ffm_read_header(AVFormatContext *s)
Definition: ffmdec.c:366
float b_quant_offset
qscale offset between IP and B-frames
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
static uint32_t state
Definition: trasher.c:27
static int flags
Definition: cpu.c:23
AVInputFormat ff_ffm_demuxer
Definition: ffmdec.c:630
static int64_t ffm_seek1(AVFormatContext *s, int64_t pos1)
Definition: ffmdec.c:143
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:563
Main libavformat public API header.
uint8_t packet[FFM_PACKET_SIZE]
Definition: ffm.h:56
int nsse_weight
noise vs.
int64_t pos
position in the file of the current buffer
Definition: avio.h:94
static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags)
Definition: ffmdec.c:559
int den
denominator
Definition: rational.h:45
#define MKBETAG(a, b, c, d)
Definition: common.h:283
int len
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
int read_state
Definition: ffm.h:47
int flags2
CODEC_FLAG2_*.
int64_t write_index
Definition: ffm.h:46
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:633
int me_method
Motion estimation algorithm used for video coding.
int rc_min_rate
minimum bitrate
#define MKTAG(a, b, c, d)
Definition: common.h:282
This structure stores compressed data.
int me_subpel_quality
subpel ME quality
#define FLAG_KEY_FRAME
Definition: ffm.h:36
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define FFM_PACKET_SIZE
Definition: ffm.h:31
int keyint_min
minimum GOP size