History

Merge remote-tracking branch 'qatar/master'

* qatar/master: (58 commits) amrnbdec: check frame size before decoding. cscd: use negative error values to indicate decode_init() failures. h264: prevent overreads in intra PCM decoding. FATE: do not decode audio in the nuv test. dxa: set audio stream time base using the sample rate psx-str: do not allow seeking by bytes asfdec: Do not set AVCodecContext.frame_size vqf: set packet parameters after av_new_packet() mpegaudiodec: use DSPUtil.butterflies_float(). FATE: add mp3 test for sample that exhibited false overreads fate: add cdxl test for bit line plane arrangement vmnc: return error on decode_init() failure. libvorbis: add/update error messages libvorbis: use AVFifoBuffer for output packet buffer libvorbis: remove unneeded e_o_s check libvorbis: check return values for functions that can return errors libvorbis: use float input instead of s16 libvorbis: do not flush libvorbis analysis if dsp state was not initialized libvorbis: use VBR by default, with default quality of 3 libvorbis: fix use of minrate/maxrate AVOptions ... Conflicts: Changelog doc/APIchanges libavcodec/avcodec.h libavcodec/dpxenc.c libavcodec/libvorbis.c libavcodec/vmnc.c libavformat/asfdec.c libavformat/id3v2enc.c libavformat/internal.h libavformat/mp3enc.c libavformat/utils.c libavformat/version.h libswscale/utils.c tests/fate/video.mak tests/ref/fate/nuv tests/ref/fate/prores-alpha tests/ref/lavf/ffm tests/ref/vsynth1/prores tests/ref/vsynth2/prores

Michael Niedermayer committed 14 years ago

Commit 79ae0842 parents a77c8ad 882abda64 files · +1217 −519Browse files

Unified · Split

64 files
  1. Changelog +1 −0
  2. doc/APIchanges +8 −0
  3. doc/muxers.texi +34 −0
  4. libavcodec/aacdec.c +84 −70
  5. libavcodec/ac3enc.c +22 −6
  6. libavcodec/ac3enc_fixed.c +1 −0
  7. libavcodec/ac3enc_float.c +1 −0
  8. libavcodec/ac3enc_opts_template.c +6 −0
  9. libavcodec/amrnbdec.c +8 −0
  10. libavcodec/avcodec.h +20 −14
  11. libavcodec/cscd.c +2 −2
  12. libavcodec/dpxenc.c +1 −2
  13. libavcodec/eac3enc.c +1 −0
  14. libavcodec/flvenc.c +3 −0
  15. libavcodec/h261enc.c +3 −0
  16. libavcodec/h263.h +1 −1
  17. libavcodec/h264_cabac.c +2 −0
  18. libavcodec/libvorbis.c +170 −138
  19. libavcodec/mpeg12enc.c +2 −0
  20. libavcodec/mpeg4videoenc.c +2 −1
  21. libavcodec/mpegaudiodec.c +7 −0
  22. libavcodec/mpegvideo.h +35 −0
  23. libavcodec/mpegvideo_enc.c +56 −17
  24. libavcodec/options.c +21 −7
  25. libavcodec/proresdec_lgpl.c +32 −13
  26. libavcodec/proresenc_kostya.c +35 −22
  27. libavcodec/qtrle.c +1 −1
  28. libavcodec/rpza.c +4 −0
  29. libavcodec/rv10enc.c +3 −0
  30. libavcodec/rv20enc.c +3 −0
  31. libavcodec/version.h +9 −0
  32. libavcodec/vmnc.c +1 −1
  33. libavcodec/vp5.c +5 −0
  34. libavcodec/vp6.c +5 −1
  35. libavformat/asfdec.c +5 −21
  36. libavformat/avformat.h +16 −0
  37. libavformat/dxa.c +2 −0
  38. libavformat/ffmdec.c +0 −2
  39. libavformat/ffmenc.c +0 −2
  40. libavformat/id3v2.c +147 −6
  41. libavformat/id3v2.h +49 −8
  42. libavformat/id3v2enc.c +145 −47
  43. libavformat/internal.h +5 −0
  44. libavformat/matroska.h +1 −5
  45. libavformat/mov.c +4 −3
  46. libavformat/mp3enc.c +183 −74
  47. libavformat/omadec.c +1 −1
  48. libavformat/omaenc.c +1 −1
  49. libavformat/psxstr.c +1 −0
  50. libavformat/rtpenc.c +1 −1
  51. libavformat/swfdec.c +0 −2
  52. libavformat/utils.c +36 −19
  53. libavformat/version.h +1 −1
  54. libavformat/vqf.c +3 −3
  55. libswscale/utils.c +1 −1
  56. tests/codec-regression.sh +3 −3
  57. tests/fate/cdxl.mak +3 −0
  58. tests/fate/mp3.mak +5 −0
  59. tests/fate/video.mak +1 −1
  60. tests/ref/fate/cdxl-bitline-ham6 +11 −0
  61. tests/ref/fate/nuv +0 −19
  62. tests/ref/lavf/ffm +1 −1
  63. tests/ref/vsynth1/prores_kostya +1 −1
  64. tests/ref/vsynth2/prores_kostya +1 −1
Changelog+1−0
@@ -8,6 +8,7 @@ version next: · 7 unmodified lines
8- Apple ProRes encoder8- Apple ProRes encoder
9- ffprobe -count_packets and -count_frames options9- ffprobe -count_packets and -count_frames options
10- Sun Rasterfile Encoder10- Sun Rasterfile Encoder
11- ID3v2 attached pictures reading and writing
11 12
12 13
13version 0.10:14version 0.10:
doc/APIchanges+8−0
@@ -13,6 +13,7 @@ libavutil: 2011-04-18 · 12 unmodified lines
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
16<<<<<<< HEAD
162012-02-21 - xxxxxxx - lavc 54.4.100172012-02-21 - xxxxxxx - lavc 54.4.100
17 Add av_get_pcm_codec() function.18 Add av_get_pcm_codec() function.
18 19
@@ -35,6 +36,13 @@ API changes, most recent first: · 16 unmodified lines
352012-01-24 - xxxxxxx - lavfi 2.60.100362012-01-24 - xxxxxxx - lavfi 2.60.100
36 Add avfilter_graph_dump.37 Add avfilter_graph_dump.
37 38
39||||||| merged common ancestors
40=======
412012-xx-xx - xxxxxxx - lavf 54.2.0 - avformat.h
42 Add AVStream.attached_pic and AV_DISPOSITION_ATTACHED_PIC,
43 used for dealing with attached pictures/cover art.
44
45>>>>>>> qatar/master
382012-02-25 - c9bca80 - lavu 51.24.0 - error.h462012-02-25 - c9bca80 - lavu 51.24.0 - error.h
39 Add AVERROR_UNKNOWN47 Add AVERROR_UNKNOWN
40 48
doc/muxers.texi+34−0
@@ -370,5 +370,39 @@ Wrap around segment index once it reaches @var{limit}. · 369 unmodified lines
370ffmpeg -i in.mkv -c copy -map 0 -f segment -list out.list out%03d.nut370ffmpeg -i in.mkv -c copy -map 0 -f segment -list out.list out%03d.nut
371@end example371@end example
372 372
373@section mp3
374
375The MP3 muxer writes a raw MP3 stream with an ID3v2 header at the beginning and
376optionally an ID3v1 tag at the end. ID3v2.3 and ID3v2.4 are supported, the
377@code{id3v2_version} option controls which one is used. The legacy ID3v1 tag is
378not written by default, but may be enabled with the @code{write_id3v1} option.
379
380For seekable output the muxer also writes a Xing frame at the beginning, which
381contains the number of frames in the file. It is useful for computing duration
382of VBR files.
383
384The muxer supports writing ID3v2 attached pictures (APIC frames). The pictures
385are supplied to the muxer in form of a video stream with a single packet. There
386can be any number of those streams, each will correspond to a single APIC frame.
387The stream metadata tags @var{title} and @var{comment} map to APIC
388@var{description} and @var{picture type} respectively. See
389@url{http://id3.org/id3v2.4.0-frames} for allowed picture types.
390
391Note that the APIC frames must be written at the beginning, so the muxer will
392buffer the audio frames until it gets all the pictures. It is therefore advised
393to provide the pictures as soon as possible to avoid excessive buffering.
394
395Examples:
396
397Write an mp3 with an ID3v2.3 header and an ID3v1 footer:
398@example
399ffmpeg -i INPUT -id3v2_version 3 -write_id3v1 1 out.mp3
400@end example
401
402Attach a picture to an mp3:
403@example
404ffmpeg -i input.mp3 -i cover.png -c copy -metadata:s:v title="Album cover"
405-metadata:s:v comment="Cover (Front)" out.mp3
406@end example
373 407
374@c man end MUXERS408@c man end MUXERS
libavcodec/aacdec.c+84−70
@@ -114,55 +114,6 @@ static VLC vlc_spectral[11]; · 113 unmodified lines
114 114
115static const char overread_err[] = "Input buffer exhausted before END element found\n";115static const char overread_err[] = "Input buffer exhausted before END element found\n";
116 116
117static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
118{
119 // For PCE based channel configurations map the channels solely based on tags.
120 if (!ac->m4ac.chan_config) {
121 return ac->tag_che_map[type][elem_id];
122 }
123 // For indexed channel configurations map the channels solely based on position.
124 switch (ac->m4ac.chan_config) {
125 case 7:
126 if (ac->tags_mapped == 3 && type == TYPE_CPE) {
127 ac->tags_mapped++;
128 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
129 }
130 case 6:
131 /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
132 instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
133 encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
134 if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
135 ac->tags_mapped++;
136 return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
137 }
138 case 5:
139 if (ac->tags_mapped == 2 && type == TYPE_CPE) {
140 ac->tags_mapped++;
141 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
142 }
143 case 4:
144 if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
145 ac->tags_mapped++;
146 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
147 }
148 case 3:
149 case 2:
150 if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
151 ac->tags_mapped++;
152 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
153 } else if (ac->m4ac.chan_config == 2) {
154 return NULL;
155 }
156 case 1:
157 if (!ac->tags_mapped && type == TYPE_SCE) {
158 ac->tags_mapped++;
159 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
160 }
161 default:
162 return NULL;
163 }
164}
165
166static int count_channels(uint8_t (*layout)[3], int tags)117static int count_channels(uint8_t (*layout)[3], int tags)
167{118{
168 int i, sum = 0;119 int i, sum = 0;
@@ -454,6 +405,90 @@ static void flush(AVCodecContext *avctx) · 285 unmodified lines
454 }405 }
455}406}
456 407
408/**
409 * Set up channel positions based on a default channel configuration
410 * as specified in table 1.17.
411 *
412 * @return Returns error status. 0 - OK, !0 - error
413 */
414static av_cold int set_default_channel_config(AVCodecContext *avctx,
415 uint8_t (*layout_map)[3],
416 int *tags,
417 int channel_config)
418{
419 if (channel_config < 1 || channel_config > 7) {
420 av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
421 channel_config);
422 return -1;
423 }
424 *tags = tags_per_config[channel_config];
425 memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
426 return 0;
427}
428
429static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
430{
431 // For PCE based channel configurations map the channels solely based on tags.
432 if (!ac->m4ac.chan_config) {
433 return ac->tag_che_map[type][elem_id];
434 }
435 // Allow single CPE stereo files to be signalled with mono configuration.
436 if (!ac->tags_mapped && type == TYPE_CPE && ac->m4ac.chan_config == 1) {
437 uint8_t layout_map[MAX_ELEM_ID*4][3];
438 int layout_map_tags;
439
440 if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags,
441 2) < 0)
442 return NULL;
443 if (output_configure(ac, layout_map, layout_map_tags,
444 2, OC_TRIAL_FRAME) < 0)
445 return NULL;
446
447 ac->m4ac.chan_config = 2;
448 }
449 // For indexed channel configurations map the channels solely based on position.
450 switch (ac->m4ac.chan_config) {
451 case 7:
452 if (ac->tags_mapped == 3 && type == TYPE_CPE) {
453 ac->tags_mapped++;
454 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
455 }
456 case 6:
457 /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
458 instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
459 encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
460 if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
461 ac->tags_mapped++;
462 return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
463 }
464 case 5:
465 if (ac->tags_mapped == 2 && type == TYPE_CPE) {
466 ac->tags_mapped++;
467 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
468 }
469 case 4:
470 if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
471 ac->tags_mapped++;
472 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
473 }
474 case 3:
475 case 2:
476 if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
477 ac->tags_mapped++;
478 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
479 } else if (ac->m4ac.chan_config == 2) {
480 return NULL;
481 }
482 case 1:
483 if (!ac->tags_mapped && type == TYPE_SCE) {
484 ac->tags_mapped++;
485 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
486 }
487 default:
488 return NULL;
489 }
490}
491
457/**492/**
458 * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.493 * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
459 *494 *
@@ -550,27 +585,6 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, · 90 unmodified lines
550 return tags;585 return tags;
551}586}
552 587
553/**
554 * Set up channel positions based on a default channel configuration
555 * as specified in table 1.17.
556 *
557 * @return Returns error status. 0 - OK, !0 - error
558 */
559static av_cold int set_default_channel_config(AVCodecContext *avctx,
560 uint8_t (*layout_map)[3],
561 int *tags,
562 int channel_config)
563{
564 if (channel_config < 1 || channel_config > 7) {
565 av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
566 channel_config);
567 return -1;
568 }
569 *tags = tags_per_config[channel_config];
570 memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
571 return 0;
572}
573
574/**588/**
575 * Decode GA "General Audio" specific configuration; reference: table 4.1.589 * Decode GA "General Audio" specific configuration; reference: table 4.1.
576 *590 *
libavcodec/ac3enc.c+22−6
@@ -2138,6 +2138,17 @@ static av_cold int validate_options(AC3EncodeContext *s) · 2137 unmodified lines
2138 s->bit_alloc.sr_code = i % 3;2138 s->bit_alloc.sr_code = i % 3;
2139 s->bitstream_id = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;2139 s->bitstream_id = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;
2140 2140
2141 /* select a default bit rate if not set by the user */
2142 if (!avctx->bit_rate) {
2143 switch (s->fbw_channels) {
2144 case 1: avctx->bit_rate = 96000; break;
2145 case 2: avctx->bit_rate = 192000; break;
2146 case 3: avctx->bit_rate = 320000; break;
2147 case 4: avctx->bit_rate = 384000; break;
2148 case 5: avctx->bit_rate = 448000; break;
2149 }
2150 }
2151
2141 /* validate bit rate */2152 /* validate bit rate */
2142 if (s->eac3) {2153 if (s->eac3) {
2143 int max_br, min_br, wpf, min_br_dist, min_br_code;2154 int max_br, min_br, wpf, min_br_dist, min_br_code;
@@ -2186,15 +2197,20 @@ static av_cold int validate_options(AC3EncodeContext *s) · 42 unmodified lines
2186 wpf--;2197 wpf--;
2187 s->frame_size_min = 2 * wpf;2198 s->frame_size_min = 2 * wpf;
2188 } else {2199 } else {
2200 int best_br = 0, best_code = 0, best_diff = INT_MAX;
2189 for (i = 0; i < 19; i++) {2201 for (i = 0; i < 19; i++) {
2190 if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)2202 int br = (ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift) * 1000;
2203 int diff = abs(br - avctx->bit_rate);
2204 if (diff < best_diff) {
2205 best_br = br;
2206 best_code = i;
2207 best_diff = diff;
2208 }
2209 if (!best_diff)
2191 break;2210 break;
2192 }2211 }
2193 if (i == 19) {2212 avctx->bit_rate = best_br;
2194 av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n");2213 s->frame_size_code = best_code << 1;
2195 return AVERROR(EINVAL);
2196 }
2197 s->frame_size_code = i << 1;
2198 s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];2214 s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
2199 s->num_blks_code = 0x3;2215 s->num_blks_code = 0x3;
2200 s->num_blocks = 6;2216 s->num_blocks = 6;
libavcodec/ac3enc_fixed.c+1−0
@@ -157,4 +157,5 @@ AVCodec ff_ac3_fixed_encoder = { · 156 unmodified lines
157 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),157 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
158 .priv_class = &ac3enc_class,158 .priv_class = &ac3enc_class,
159 .channel_layouts = ff_ac3_channel_layouts,159 .channel_layouts = ff_ac3_channel_layouts,
160 .defaults = ac3_defaults,
160};161};
libavcodec/ac3enc_float.c+1−0
@@ -155,5 +155,6 @@ AVCodec ff_ac3_encoder = { · 154 unmodified lines
155 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),155 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
156 .priv_class = &ac3enc_class,156 .priv_class = &ac3enc_class,
157 .channel_layouts = ff_ac3_channel_layouts,157 .channel_layouts = ff_ac3_channel_layouts,
158 .defaults = ac3_defaults,
158};159};
159#endif160#endif
libavcodec/ac3enc_opts_template.c+6−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
20 */20 */
21 21
22#include "libavutil/opt.h"22#include "libavutil/opt.h"
23#include "internal.h"
23#include "ac3.h"24#include "ac3.h"
24 25
25#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED26#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED
@@ -78,3 +79,8 @@ static const AVOption eac3_options[] = { · 52 unmodified lines
78 {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},79 {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
79{NULL}80{NULL}
80};81};
82
83static const AVCodecDefault ac3_defaults[] = {
84 { "b", "0" },
85 { NULL }
86};
libavcodec/amrnbdec.c+8−0
@@ -200,6 +200,10 @@ static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf, · 199 unmodified lines
200 p->bad_frame_indicator = !get_bits1(&gb); // quality bit200 p->bad_frame_indicator = !get_bits1(&gb); // quality bit
201 skip_bits(&gb, 2); // two padding bits201 skip_bits(&gb, 2); // two padding bits
202 202
203 if (mode >= N_MODES || buf_size < frame_sizes_nb[mode] + 1) {
204 return NO_DATA;
205 }
206
203 if (mode < MODE_DTX)207 if (mode < MODE_DTX)
204 ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1,208 ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1,
205 amr_unpacking_bitmaps_per_mode[mode]);209 amr_unpacking_bitmaps_per_mode[mode]);
@@ -947,6 +951,10 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, · 741 unmodified lines
947 buf_out = (float *)p->avframe.data[0];951 buf_out = (float *)p->avframe.data[0];
948 952
949 p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);953 p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);
954 if (p->cur_frame_mode == NO_DATA) {
955 av_log(avctx, AV_LOG_ERROR, "Corrupt bitstream\n");
956 return AVERROR_INVALIDDATA;
957 }
950 if (p->cur_frame_mode == MODE_DTX) {958 if (p->cur_frame_mode == MODE_DTX) {
951 av_log_missing_feature(avctx, "dtx mode", 0);959 av_log_missing_feature(avctx, "dtx mode", 0);
952 av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n");960 av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n");
libavcodec/avcodec.h+20−14
@@ -582,17 +582,19 @@ typedef struct RcOverride{ · 581 unmodified lines
582#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).582#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
583/* Fx : Flag for h263+ extra options */583/* Fx : Flag for h263+ extra options */
584#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction584#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
585#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
586#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
587#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter585#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
588#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation586#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
589#define CODEC_FLAG_CLOSED_GOP 0x80000000587#define CODEC_FLAG_CLOSED_GOP 0x80000000
590#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.588#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
591#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
592#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.589#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
593#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.590#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
594#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!591#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
592#if FF_API_MPV_GLOBAL_OPTS
593#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
594#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
595#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
595#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping596#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
597#endif
596#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.598#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
597#define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe599#define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe
598 600
@@ -1492,19 +1494,21 @@ typedef struct AVCodecContext { · 893 unmodified lines
1492 1494
1493 int b_frame_strategy;1495 int b_frame_strategy;
1494 1496
1497#if FF_API_MPV_GLOBAL_OPTS
1495 /**1498 /**
1496 * luma single coefficient elimination threshold1499 * luma single coefficient elimination threshold
1497 * - encoding: Set by user.1500 * - encoding: Set by user.
1498 * - decoding: unused1501 * - decoding: unused
1499 */1502 */
1500 int luma_elim_threshold;1503 attribute_deprecated int luma_elim_threshold;
1501 1504
1502 /**1505 /**
1503 * chroma single coeff elimination threshold1506 * chroma single coeff elimination threshold
1504 * - encoding: Set by user.1507 * - encoding: Set by user.
1505 * - decoding: unused1508 * - decoding: unused
1506 */1509 */
1507 int chroma_elim_threshold;1510 attribute_deprecated int chroma_elim_threshold;
1511#endif
1508 1512
1509 /**1513 /**
1510 * qscale offset between IP and B-frames1514 * qscale offset between IP and B-frames
@@ -1735,13 +1739,15 @@ typedef struct AVCodecContext { · 224 unmodified lines
1735 */1739 */
1736 int inter_quant_bias;1740 int inter_quant_bias;
1737 1741
1742#if FF_API_COLOR_TABLE_ID
1738 /**1743 /**
1739 * color table ID1744 * color table ID
1740 * - encoding: unused1745 * - encoding: unused
1741 * - decoding: Which clrtable should be used for 8bit RGB images.1746 * - decoding: Which clrtable should be used for 8bit RGB images.
1742 * Tables have to be stored somewhere. FIXME1747 * Tables have to be stored somewhere. FIXME
1743 */1748 */
1744 int color_table_id;1749 attribute_deprecated int color_table_id;
1750#endif
1745 1751
1746 /**1752 /**
1747 * slice flags1753 * slice flags
@@ -1799,19 +1805,19 @@ typedef struct AVCodecContext { · 51 unmodified lines
1799 */1805 */
1800 int noise_reduction;1806 int noise_reduction;
1801 1807
1808#if FF_API_INTER_THRESHOLD
1802 /**1809 /**
1803 *1810 * @deprecated this field is unused
1804 * - encoding: Set by user.
1805 * - decoding: unused
1806 */1811 */
1807 int inter_threshold;1812 attribute_deprecated int inter_threshold;
1813#endif
1808 1814
1815#if FF_API_MPV_GLOBAL_OPTS
1809 /**1816 /**
1810 * quantizer noise shaping1817 * @deprecated use mpegvideo private options instead
1811 * - encoding: Set by user.
1812 * - decoding: unused
1813 */1818 */
1814 int quantizer_noise_shaping;1819 attribute_deprecated int quantizer_noise_shaping;
1820#endif
1815 1821
1816 /**1822 /**
1817 * Motion estimation threshold below which no motion estimation is1823 * Motion estimation threshold below which no motion estimation is
libavcodec/cscd.c+2−2
@@ -228,7 +228,7 @@ static av_cold int decode_init(AVCodecContext *avctx) { · 227 unmodified lines
228 av_log(avctx, AV_LOG_ERROR,228 av_log(avctx, AV_LOG_ERROR,
229 "CamStudio codec error: invalid depth %i bpp\n",229 "CamStudio codec error: invalid depth %i bpp\n",
230 avctx->bits_per_coded_sample);230 avctx->bits_per_coded_sample);
231 return 1;231 return AVERROR_INVALIDDATA;
232 }232 }
233 c->bpp = avctx->bits_per_coded_sample;233 c->bpp = avctx->bits_per_coded_sample;
234 avcodec_get_frame_defaults(&c->pic);234 avcodec_get_frame_defaults(&c->pic);
@@ -242,7 +242,7 @@ static av_cold int decode_init(AVCodecContext *avctx) { · 7 unmodified lines
242 c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING);242 c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING);
243 if (!c->decomp_buf) {243 if (!c->decomp_buf) {
244 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");244 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
245 return 1;245 return AVERROR(ENOMEM);
246 }246 }
247 return 0;247 return 0;
248}248}
libavcodec/dpxenc.c+1−2
@@ -131,9 +131,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 130 unmodified lines
131 memcpy (buf + 8, "V1.0", 4);131 memcpy (buf + 8, "V1.0", 4);
132 write32(buf + 20, 1); /* new image */132 write32(buf + 20, 1); /* new image */
133 write32(buf + 24, HEADER_SIZE);133 write32(buf + 24, HEADER_SIZE);
134 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){134 if (!(avctx->flags & CODEC_FLAG_BITEXACT))
135 memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100));135 memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100));
136 }
137 write32(buf + 660, 0xFFFFFFFF); /* unencrypted */136 write32(buf + 660, 0xFFFFFFFF); /* unencrypted */
138 137
139 /* Image information header */138 /* Image information header */
libavcodec/eac3enc.c+1−0
@@ -258,5 +258,6 @@ AVCodec ff_eac3_encoder = { · 257 unmodified lines
258 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),258 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
259 .priv_class = &eac3enc_class,259 .priv_class = &eac3enc_class,
260 .channel_layouts = ff_ac3_channel_layouts,260 .channel_layouts = ff_ac3_channel_layouts,
261 .defaults = ac3_defaults,
261};262};
262#endif263#endif
libavcodec/flvenc.c+3−0
@@ -84,6 +84,8 @@ void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, in · 83 unmodified lines
84 }84 }
85}85}
86 86
87FF_MPV_GENERIC_CLASS(flv)
88
87AVCodec ff_flv_encoder = {89AVCodec ff_flv_encoder = {
88 .name = "flv",90 .name = "flv",
89 .type = AVMEDIA_TYPE_VIDEO,91 .type = AVMEDIA_TYPE_VIDEO,
@@ -94,4 +96,5 @@ AVCodec ff_flv_encoder = { · 4 unmodified lines
94 .close = ff_MPV_encode_end,96 .close = ff_MPV_encode_end,
95 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},97 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
96 .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),98 .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
99 .priv_class = &flv_class,
97};100};
libavcodec/h261enc.c+3−0
@@ -321,6 +321,8 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){ · 320 unmodified lines
321 }321 }
322}322}
323 323
324FF_MPV_GENERIC_CLASS(h261)
325
324AVCodec ff_h261_encoder = {326AVCodec ff_h261_encoder = {
325 .name = "h261",327 .name = "h261",
326 .type = AVMEDIA_TYPE_VIDEO,328 .type = AVMEDIA_TYPE_VIDEO,
@@ -331,4 +333,5 @@ AVCodec ff_h261_encoder = { · 4 unmodified lines
331 .close = ff_MPV_encode_end,333 .close = ff_MPV_encode_end,
332 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},334 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
333 .long_name= NULL_IF_CONFIG_SMALL("H.261"),335 .long_name= NULL_IF_CONFIG_SMALL("H.261"),
336 .priv_class = &h261_class,
334};337};
libavcodec/h263.h+1−1
@@ -148,7 +148,7 @@ static inline int get_p_cbp(MpegEncContext * s, · 147 unmodified lines
148 int motion_x, int motion_y){148 int motion_x, int motion_y){
149 int cbp, i;149 int cbp, i;
150 150
151 if(s->flags & CODEC_FLAG_CBP_RD){151 if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
152 int best_cbpy_score= INT_MAX;152 int best_cbpy_score= INT_MAX;
153 int best_cbpc_score= INT_MAX;153 int best_cbpc_score= INT_MAX;
154 int cbpc = (-1), cbpy= (-1);154 int cbpc = (-1), cbpy= (-1);
libavcodec/h264_cabac.c+2−0
@@ -1998,6 +1998,8 @@ decode_intra_mb: · 1997 unmodified lines
1998 }1998 }
1999 1999
2000 // The pixels are stored in the same order as levels in h->mb array.2000 // The pixels are stored in the same order as levels in h->mb array.
2001 if ((int) (h->cabac.bytestream_end - ptr) < mb_size)
2002 return -1;
2001 memcpy(h->mb, ptr, mb_size); ptr+=mb_size;2003 memcpy(h->mb, ptr, mb_size); ptr+=mb_size;
2002 2004
2003 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);2005 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
libavcodec/libvorbis.c+170−138
@@ -20,12 +20,13 @@ · 19 unmodified lines
20 20
21/**21/**
22 * @file22 * @file
23 * Ogg Vorbis codec support via libvorbisenc.23 * Vorbis encoding support via libvorbisenc.
24 * @author Mark Hills <mark@pogo.org.uk>24 * @author Mark Hills <mark@pogo.org.uk>
25 */25 */
26 26
27#include <vorbis/vorbisenc.h>27#include <vorbis/vorbisenc.h>
28 28
29#include "libavutil/fifo.h"
29#include "libavutil/opt.h"30#include "libavutil/opt.h"
30#include "avcodec.h"31#include "avcodec.h"
31#include "bytestream.h"32#include "bytestream.h"
@@ -35,32 +36,41 @@ · 3 unmodified lines
35#undef NDEBUG36#undef NDEBUG
36#include <assert.h>37#include <assert.h>
37 38
39/* Number of samples the user should send in each call.
40 * This value is used because it is the LCD of all possible frame sizes, so
41 * an output packet will always start at the same point as one of the input
42 * packets.
43 */
38#define OGGVORBIS_FRAME_SIZE 6444#define OGGVORBIS_FRAME_SIZE 64
39 45
40#define BUFFER_SIZE (1024 * 64)46#define BUFFER_SIZE (1024 * 64)
41 47
42typedef struct OggVorbisContext {48typedef struct OggVorbisContext {
43 AVClass *av_class;49 AVClass *av_class; /**< class for AVOptions */
44 vorbis_info vi;50 vorbis_info vi; /**< vorbis_info used during init */
45 vorbis_dsp_state vd;51 vorbis_dsp_state vd; /**< DSP state used for analysis */
46 vorbis_block vb;52 vorbis_block vb; /**< vorbis_block used for analysis */
47 uint8_t buffer[BUFFER_SIZE];53 AVFifoBuffer *pkt_fifo; /**< output packet buffer */
48 int buffer_index;54 int eof; /**< end-of-file flag */
49 int eof;55 int dsp_initialized; /**< vd has been initialized */
50 56 vorbis_comment vc; /**< VorbisComment info */
51 /* decoder */57 ogg_packet op; /**< ogg packet */
52 vorbis_comment vc;58 double iblock; /**< impulse block bias option */
53 ogg_packet op;
54
55 double iblock;
56} OggVorbisContext;59} OggVorbisContext;
57 60
58static const AVOption options[] = {61static const AVOption options[] = {
59 { "iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -15, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },62 { "iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -15, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
60 { NULL }63 { NULL }
61};64};
65
66static const AVCodecDefault defaults[] = {
67 { "b", "0" },
68 { NULL },
69};
70
62static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };71static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
63 72
73
64static int vorbis_error_to_averror(int ov_err)74static int vorbis_error_to_averror(int ov_err)
65{75{
66 switch (ov_err) {76 switch (ov_err) {
@@ -71,27 +81,34 @@ static int vorbis_error_to_averror(int ov_err) · 4 unmodified lines
71 }81 }
72}82}
73 83
74static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext)84static av_cold int oggvorbis_init_encoder(vorbis_info *vi,
85 AVCodecContext *avctx)
75{86{
76 OggVorbisContext *context = avccontext->priv_data;87 OggVorbisContext *s = avctx->priv_data;
77 double cfreq;88 double cfreq;
78 int ret;89 int ret;
79 90
80 if (avccontext->flags & CODEC_FLAG_QSCALE) {91 if (avctx->flags & CODEC_FLAG_QSCALE || !avctx->bit_rate) {
81 /* variable bitrate */92 /* variable bitrate
82 float q = avccontext->global_quality / (float)FF_QP2LAMBDA;93 * NOTE: we use the oggenc range of -1 to 10 for global_quality for
83 if ((ret = vorbis_encode_setup_vbr(vi, avccontext->channels,94 * user convenience, but libvorbis uses -0.1 to 1.0.
84 avccontext->sample_rate,95 */
96 float q = avctx->global_quality / (float)FF_QP2LAMBDA;
97 /* default to 3 if the user did not set quality or bitrate */
98 if (!(avctx->flags & CODEC_FLAG_QSCALE))
99 q = 3.0;
100 if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels,
101 avctx->sample_rate,
85 q / 10.0)))102 q / 10.0)))
86 goto error;103 goto error;
87 } else {104 } else {
88 int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1;105 int minrate = avctx->rc_min_rate > 0 ? avctx->rc_min_rate : -1;
89 int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1;106 int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1;
90 107
91 /* constant bitrate */108 /* average bitrate */
92 if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels,109 if ((ret = vorbis_encode_setup_managed(vi, avctx->channels,
93 avccontext->sample_rate, minrate,110 avctx->sample_rate, maxrate,
94 avccontext->bit_rate, maxrate)))111 avctx->bit_rate, minrate)))
95 goto error;112 goto error;
96 113
97 /* variable bitrate by estimate, disable slow rate management */114 /* variable bitrate by estimate, disable slow rate management */
@@ -101,43 +118,44 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco · 3 unmodified lines
101 }118 }
102 119
103 /* cutoff frequency */120 /* cutoff frequency */
104 if (avccontext->cutoff > 0) {121 if (avctx->cutoff > 0) {
105 cfreq = avccontext->cutoff / 1000.0;122 cfreq = avctx->cutoff / 1000.0;
106 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))123 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
107 goto error; /* should not happen */124 goto error; /* should not happen */
108 }125 }
109 126
110 if (context->iblock) {127 /* impulse block bias */
111 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock)))128 if (s->iblock) {
129 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->iblock)))
112 goto error;130 goto error;
113 }131 }
114 132
115 if (avccontext->channels == 3 &&133 if (avctx->channels == 3 &&
116 avccontext->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||134 avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
117 avccontext->channels == 4 &&135 avctx->channels == 4 &&
118 avccontext->channel_layout != AV_CH_LAYOUT_2_2 &&136 avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
119 avccontext->channel_layout != AV_CH_LAYOUT_QUAD ||137 avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
120 avccontext->channels == 5 &&138 avctx->channels == 5 &&
121 avccontext->channel_layout != AV_CH_LAYOUT_5POINT0 &&139 avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
122 avccontext->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||140 avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
123 avccontext->channels == 6 &&141 avctx->channels == 6 &&
124 avccontext->channel_layout != AV_CH_LAYOUT_5POINT1 &&142 avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
125 avccontext->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||143 avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
126 avccontext->channels == 7 &&144 avctx->channels == 7 &&
127 avccontext->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||145 avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
128 avccontext->channels == 8 &&146 avctx->channels == 8 &&
129 avccontext->channel_layout != AV_CH_LAYOUT_7POINT1) {147 avctx->channel_layout != AV_CH_LAYOUT_7POINT1) {
130 if (avccontext->channel_layout) {148 if (avctx->channel_layout) {
131 char name[32];149 char name[32];
132 av_get_channel_layout_string(name, sizeof(name), avccontext->channels,150 av_get_channel_layout_string(name, sizeof(name), avctx->channels,
133 avccontext->channel_layout);151 avctx->channel_layout);
134 av_log(avccontext, AV_LOG_ERROR, "%s not supported by Vorbis: "152 av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: "
135 "output stream will have incorrect "153 "output stream will have incorrect "
136 "channel layout.\n", name);154 "channel layout.\n", name);
137 } else {155 } else {
138 av_log(avccontext, AV_LOG_WARNING, "No channel layout specified. The encoder "156 av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder "
139 "will use Vorbis channel layout for "157 "will use Vorbis channel layout for "
140 "%d channels.\n", avccontext->channels);158 "%d channels.\n", avctx->channels);
141 }159 }
142 }160 }
143 161
@@ -155,59 +173,64 @@ static int xiph_len(int l) · 11 unmodified lines
155 return 1 + l / 255 + l;173 return 1 + l / 255 + l;
156}174}
157 175
158static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext)176static av_cold int oggvorbis_encode_close(AVCodecContext *avctx)
159{177{
160 OggVorbisContext *context = avccontext->priv_data;178 OggVorbisContext *s = avctx->priv_data;
161/* ogg_packet op ; */
162 179
163 vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF */180 /* notify vorbisenc this is EOF */
181 if (s->dsp_initialized)
182 vorbis_analysis_wrote(&s->vd, 0);
164 183
165 vorbis_block_clear(&context->vb);184 vorbis_block_clear(&s->vb);
166 vorbis_dsp_clear(&context->vd);185 vorbis_dsp_clear(&s->vd);
167 vorbis_info_clear(&context->vi);186 vorbis_info_clear(&s->vi);
168 187
169 av_freep(&avccontext->coded_frame);188 av_fifo_free(s->pkt_fifo);
170 av_freep(&avccontext->extradata);189 av_freep(&avctx->coded_frame);
190 av_freep(&avctx->extradata);
171 191
172 return 0;192 return 0;
173}193}
174 194
175static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)195static av_cold int oggvorbis_encode_init(AVCodecContext *avctx)
176{196{
177 OggVorbisContext *context = avccontext->priv_data;197 OggVorbisContext *s = avctx->priv_data;
178 ogg_packet header, header_comm, header_code;198 ogg_packet header, header_comm, header_code;
179 uint8_t *p;199 uint8_t *p;
180 unsigned int offset;200 unsigned int offset;
181 int ret;201 int ret;
182 202
183 vorbis_info_init(&context->vi);203 vorbis_info_init(&s->vi);
184 if ((ret = oggvorbis_init_encoder(&context->vi, avccontext))) {204 if ((ret = oggvorbis_init_encoder(&s->vi, avctx))) {
185 av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n");205 av_log(avctx, AV_LOG_ERROR, "encoder setup failed\n");
186 goto error;206 goto error;
187 }207 }
188 if ((ret = vorbis_analysis_init(&context->vd, &context->vi))) {208 if ((ret = vorbis_analysis_init(&s->vd, &s->vi))) {
209 av_log(avctx, AV_LOG_ERROR, "analysis init failed\n");
189 ret = vorbis_error_to_averror(ret);210 ret = vorbis_error_to_averror(ret);
190 goto error;211 goto error;
191 }212 }
192 if ((ret = vorbis_block_init(&context->vd, &context->vb))) {213 s->dsp_initialized = 1;
214 if ((ret = vorbis_block_init(&s->vd, &s->vb))) {
215 av_log(avctx, AV_LOG_ERROR, "dsp init failed\n");
193 ret = vorbis_error_to_averror(ret);216 ret = vorbis_error_to_averror(ret);
194 goto error;217 goto error;
195 }218 }
196 219
197 vorbis_comment_init(&context->vc);220 vorbis_comment_init(&s->vc);
198 vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT);221 vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT);
199 222
200 if ((ret = vorbis_analysis_headerout(&context->vd, &context->vc, &header,223 if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm,
201 &header_comm, &header_code))) {224 &header_code))) {
202 ret = vorbis_error_to_averror(ret);225 ret = vorbis_error_to_averror(ret);
203 goto error;226 goto error;
204 }227 }
205 228
206 avccontext->extradata_size =229 avctx->extradata_size = 1 + xiph_len(header.bytes) +
207 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) +230 xiph_len(header_comm.bytes) +
208 header_code.bytes;231 header_code.bytes;
209 p = avccontext->extradata =232 p = avctx->extradata = av_malloc(avctx->extradata_size +
210 av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);233 FF_INPUT_BUFFER_PADDING_SIZE);
211 if (!p) {234 if (!p) {
212 ret = AVERROR(ENOMEM);235 ret = AVERROR(ENOMEM);
213 goto error;236 goto error;
@@ -222,100 +245,107 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) · 8 unmodified lines
222 offset += header_comm.bytes;245 offset += header_comm.bytes;
223 memcpy(&p[offset], header_code.packet, header_code.bytes);246 memcpy(&p[offset], header_code.packet, header_code.bytes);
224 offset += header_code.bytes;247 offset += header_code.bytes;
225 assert(offset == avccontext->extradata_size);248 assert(offset == avctx->extradata_size);
226 249
227#if 0250 vorbis_comment_clear(&s->vc);
228 vorbis_block_clear(&context->vb);
229 vorbis_dsp_clear(&context->vd);
230 vorbis_info_clear(&context->vi);
231#endif
232 vorbis_comment_clear(&context->vc);
233 251
234 avccontext->frame_size = OGGVORBIS_FRAME_SIZE;252 avctx->frame_size = OGGVORBIS_FRAME_SIZE;
253
254 s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE);
255 if (!s->pkt_fifo) {
256 ret = AVERROR(ENOMEM);
257 goto error;
258 }
235 259
236 avccontext->coded_frame = avcodec_alloc_frame();260 avctx->coded_frame = avcodec_alloc_frame();
237 if (!avccontext->coded_frame) {261 if (!avctx->coded_frame) {
238 ret = AVERROR(ENOMEM);262 ret = AVERROR(ENOMEM);
239 goto error;263 goto error;
240 }264 }
241 265
242 return 0;266 return 0;
243error:267error:
244 oggvorbis_encode_close(avccontext);268 oggvorbis_encode_close(avctx);
245 return ret;269 return ret;
246}270}
247 271
248static int oggvorbis_encode_frame(AVCodecContext *avccontext,272static int oggvorbis_encode_frame(AVCodecContext *avctx, unsigned char *packets,
249 unsigned char *packets,
250 int buf_size, void *data)273 int buf_size, void *data)
251{274{
252 OggVorbisContext *context = avccontext->priv_data;275 OggVorbisContext *s = avctx->priv_data;
253 ogg_packet op;276 ogg_packet op;
254 signed short *audio = data;277 float *audio = data;
255 int l;278 int pkt_size, ret;
256 279
280 /* send samples to libvorbis */
257 if (data) {281 if (data) {
258 const int samples = avccontext->frame_size;282 const int samples = avctx->frame_size;
259 float **buffer;283 float **buffer;
260 int c, channels = context->vi.channels;284 int c, channels = s->vi.channels;
261 285
262 buffer = vorbis_analysis_buffer(&context->vd, samples);286 buffer = vorbis_analysis_buffer(&s->vd, samples);
263 for (c = 0; c < channels; c++) {287 for (c = 0; c < channels; c++) {
288 int i;
264 int co = (channels > 8) ? c :289 int co = (channels > 8) ? c :
265 ff_vorbis_encoding_channel_layout_offsets[channels - 1][c];290 ff_vorbis_encoding_channel_layout_offsets[channels - 1][c];
266 for (l = 0; l < samples; l++)291 for (i = 0; i < samples; i++)
267 buffer[c][l] = audio[l * channels + co] / 32768.f;292 buffer[c][i] = audio[i * channels + co];
293 }
294 if ((ret = vorbis_analysis_wrote(&s->vd, samples)) < 0) {
295 av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n");
296 return vorbis_error_to_averror(ret);
268 }297 }
269 vorbis_analysis_wrote(&context->vd, samples);
270 } else {298 } else {
271 if (!context->eof)299 if (!s->eof)
272 vorbis_analysis_wrote(&context->vd, 0);300 if ((ret = vorbis_analysis_wrote(&s->vd, 0)) < 0) {
273 context->eof = 1;301 av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n");
302 return vorbis_error_to_averror(ret);
303 }
304 s->eof = 1;
274 }305 }
275 306
276 while (vorbis_analysis_blockout(&context->vd, &context->vb) == 1) {307 /* retrieve available packets from libvorbis */
277 vorbis_analysis(&context->vb, NULL);308 while ((ret = vorbis_analysis_blockout(&s->vd, &s->vb)) == 1) {
278 vorbis_bitrate_addblock(&context->vb);309 if ((ret = vorbis_analysis(&s->vb, NULL)) < 0)
279 310 break;
280 while (vorbis_bitrate_flushpacket(&context->vd, &op)) {311 if ((ret = vorbis_bitrate_addblock(&s->vb)) < 0)
281 /* i'd love to say the following line is a hack, but sadly it's312 break;
282 * not, apparently the end of stream decision is in libogg. */313
283 if (op.bytes == 1 && op.e_o_s)314 /* add any available packets to the output packet buffer */
284 continue;315 while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) {
285 if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) {316 if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) {
286 av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");317 av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n");
287 return AVERROR(EINVAL);318 return AVERROR_BUG;
288 }319 }
289 memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));320 av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
290 context->buffer_index += sizeof(ogg_packet);321 av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL);
291 memcpy(context->buffer + context->buffer_index, op.packet, op.bytes);322 }
292 context->buffer_index += op.bytes;323 if (ret < 0) {
293// av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes);324 av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
325 break;
294 }326 }
295 }327 }
328 if (ret < 0) {
329 av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
330 return vorbis_error_to_averror(ret);
331 }
296 332
297 l = 0;333 /* output then next packet from the output buffer, if available */
298 if (context->buffer_index) {334 pkt_size = 0;
299 ogg_packet *op2 = (ogg_packet *)context->buffer;335 if (av_fifo_size(s->pkt_fifo) >= sizeof(ogg_packet)) {
300 op2->packet = context->buffer + sizeof(ogg_packet);336 av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
301 337 pkt_size = op.bytes;
302 l = op2->bytes;338 // FIXME: we should use the user-supplied pts and duration
303 avccontext->coded_frame->pts = ff_samples_to_time_base(avccontext,339 avctx->coded_frame->pts = ff_samples_to_time_base(avctx,
304 op2->granulepos);340 op.granulepos);
305 //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate341 if (pkt_size > buf_size) {
306 342 av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
307 if (l > buf_size) {
308 av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
309 return AVERROR(EINVAL);343 return AVERROR(EINVAL);
310 }344 }
311 345 av_fifo_generic_read(s->pkt_fifo, packets, pkt_size, NULL);
312 memcpy(packets, op2->packet, l);
313 context->buffer_index -= l + sizeof(ogg_packet);
314 memmove(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index);
315// av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l);
316 }346 }
317 347
318 return l;348 return pkt_size;
319}349}
320 350
321AVCodec ff_libvorbis_encoder = {351AVCodec ff_libvorbis_encoder = {
@@ -327,7 +357,9 @@ AVCodec ff_libvorbis_encoder = { · 5 unmodified lines
327 .encode = oggvorbis_encode_frame,357 .encode = oggvorbis_encode_frame,
328 .close = oggvorbis_encode_close,358 .close = oggvorbis_encode_close,
329 .capabilities = CODEC_CAP_DELAY,359 .capabilities = CODEC_CAP_DELAY,
330 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },360 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
361 AV_SAMPLE_FMT_NONE },
331 .long_name = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"),362 .long_name = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"),
332 .priv_class = &class,363 .priv_class = &class,
364 .defaults = defaults,
333};365};
libavcodec/mpeg12enc.c+2−0
@@ -939,6 +939,7 @@ static void mpeg1_encode_block(MpegEncContext *s, · 938 unmodified lines
939 939
940static const AVOption mpeg1_options[] = {940static const AVOption mpeg1_options[] = {
941 COMMON_OPTS941 COMMON_OPTS
942 FF_MPV_COMMON_OPTS
942 { NULL },943 { NULL },
943};944};
944 945
@@ -946,6 +947,7 @@ static const AVOption mpeg2_options[] = { · 1 unmodified line
946 COMMON_OPTS947 COMMON_OPTS
947 { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },948 { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
948 { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },949 { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
950 FF_MPV_COMMON_OPTS
949 { NULL },951 { NULL },
950};952};
951 953
libavcodec/mpeg4videoenc.c+2−1
@@ -430,7 +430,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], · 429 unmodified lines
430{430{
431 int cbp = 0, i;431 int cbp = 0, i;
432 432
433 if (s->flags & CODEC_FLAG_CBP_RD) {433 if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
434 int score = 0;434 int score = 0;
435 const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);435 const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
436 436
@@ -1330,6 +1330,7 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) · 893 unmodified lines
1330static const AVOption options[] = {1330static const AVOption options[] = {
1331 { "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },1331 { "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
1332 { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },1332 { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
1333 FF_MPV_COMMON_OPTS
1333 { NULL },1334 { NULL },
1334};1335};
1335 1336
libavcodec/mpegaudiodec.c+7−0
@@ -31,6 +31,7 @@ · 30 unmodified lines
31#include "get_bits.h"31#include "get_bits.h"
32#include "mathops.h"32#include "mathops.h"
33#include "mpegaudiodsp.h"33#include "mpegaudiodsp.h"
34#include "dsputil.h"
34 35
35/*36/*
36 * TODO:37 * TODO:
@@ -82,6 +83,7 @@ typedef struct MPADecodeContext { · 45 unmodified lines
82 int err_recognition;83 int err_recognition;
83 AVCodecContext* avctx;84 AVCodecContext* avctx;
84 MPADSPContext mpadsp;85 MPADSPContext mpadsp;
86 DSPContext dsp;
85 AVFrame frame;87 AVFrame frame;
86} MPADecodeContext;88} MPADecodeContext;
87 89
@@ -434,6 +436,7 @@ static av_cold int decode_init(AVCodecContext * avctx) · 346 unmodified lines
434 s->avctx = avctx;436 s->avctx = avctx;
435 437
436 ff_mpadsp_init(&s->mpadsp);438 ff_mpadsp_init(&s->mpadsp);
439 ff_dsputil_init(&s->dsp, avctx);
437 440
438 avctx->sample_fmt= OUT_FMT;441 avctx->sample_fmt= OUT_FMT;
439 s->err_recognition = avctx->err_recognition;442 s->err_recognition = avctx->err_recognition;
@@ -1155,6 +1158,9 @@ found2: · 715 unmodified lines
1155 /* ms stereo ONLY */1158 /* ms stereo ONLY */
1156 /* NOTE: the 1/sqrt(2) normalization factor is included in the1159 /* NOTE: the 1/sqrt(2) normalization factor is included in the
1157 global gain */1160 global gain */
1161#if CONFIG_FLOAT
1162 s-> dsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
1163#else
1158 tab0 = g0->sb_hybrid;1164 tab0 = g0->sb_hybrid;
1159 tab1 = g1->sb_hybrid;1165 tab1 = g1->sb_hybrid;
1160 for (i = 0; i < 576; i++) {1166 for (i = 0; i < 576; i++) {
@@ -1163,6 +1169,7 @@ found2: · 2 unmodified lines
1163 tab0[i] = tmp0 + tmp1;1169 tab0[i] = tmp0 + tmp1;
1164 tab1[i] = tmp0 - tmp1;1170 tab1[i] = tmp0 - tmp1;
1165 }1171 }
1172#endif
1166 }1173 }
1167}1174}
1168 1175
libavcodec/mpegvideo.h+35−0
@@ -38,6 +38,8 @@ · 37 unmodified lines
38#include "rl.h"38#include "rl.h"
39#include "libavutil/timecode.h"39#include "libavutil/timecode.h"
40 40
41#include "libavutil/opt.h"
42
41#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded43#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
42 44
43enum OutputFormat {45enum OutputFormat {
@@ -695,6 +697,9 @@ typedef struct MpegEncContext { · 651 unmodified lines
695 int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);697 int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
696 int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);698 int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
697 void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);699 void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
700
701 int mpv_flags; ///< flags set by private options
702 int quantizer_noise_shaping;
698} MpegEncContext;703} MpegEncContext;
699 704
700#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \705#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
@@ -702,6 +707,36 @@ typedef struct MpegEncContext { · 1 unmodified line
702 &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\707 &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
703 : NULL)708 : NULL)
704 709
710/* mpegvideo_enc common options */
711#define FF_MPV_FLAG_SKIP_RD 0x0001
712#define FF_MPV_FLAG_STRICT_GOP 0x0002
713#define FF_MPV_FLAG_QP_RD 0x0004
714#define FF_MPV_FLAG_CBP_RD 0x0008
715
716#define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
717#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
718#define FF_MPV_COMMON_OPTS \
719{ "mpv_flags", "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
720{ "skip_rd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_SKIP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
721{ "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
722{ "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
723{ "cbp_rd", "use rate distortion optimization for CBP", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
724{ "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
725 FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
726{ "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
727 FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
728{ "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },
729
730extern const AVOption ff_mpv_generic_options[];
731
732#define FF_MPV_GENERIC_CLASS(name) \
733static const AVClass name ## _class = {\
734 .class_name = #name " encoder",\
735 .item_name = av_default_item_name,\
736 .option = ff_mpv_generic_options,\
737 .version = LIBAVUTIL_VERSION_INT,\
738};
739
705void ff_MPV_decode_defaults(MpegEncContext *s);740void ff_MPV_decode_defaults(MpegEncContext *s);
706int ff_MPV_common_init(MpegEncContext *s);741int ff_MPV_common_init(MpegEncContext *s);
707void ff_MPV_common_end(MpegEncContext *s);742void ff_MPV_common_end(MpegEncContext *s);
libavcodec/mpegvideo_enc.c+56−17
@@ -63,6 +63,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int · 62 unmodified lines
63static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];63static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];
64static uint8_t default_fcode_tab[MAX_MV * 2 + 1];64static uint8_t default_fcode_tab[MAX_MV * 2 + 1];
65 65
66const AVOption ff_mpv_generic_options[] = {
67 FF_MPV_COMMON_OPTS
68 { NULL },
69};
70
66void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],71void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
67 uint16_t (*qmat16)[2][64],72 uint16_t (*qmat16)[2][64],
68 const uint16_t *quant_matrix,73 const uint16_t *quant_matrix,
@@ -352,8 +357,12 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 283 unmodified lines
352 s->flags2 = avctx->flags2;357 s->flags2 = avctx->flags2;
353 s->max_b_frames = avctx->max_b_frames;358 s->max_b_frames = avctx->max_b_frames;
354 s->codec_id = avctx->codec->id;359 s->codec_id = avctx->codec->id;
355 s->luma_elim_threshold = avctx->luma_elim_threshold;360#if FF_API_MPV_GLOBAL_OPTS
356 s->chroma_elim_threshold = avctx->chroma_elim_threshold;361 if (avctx->luma_elim_threshold)
362 s->luma_elim_threshold = avctx->luma_elim_threshold;
363 if (avctx->chroma_elim_threshold)
364 s->chroma_elim_threshold = avctx->chroma_elim_threshold;
365#endif
357 s->strict_std_compliance = avctx->strict_std_compliance;366 s->strict_std_compliance = avctx->strict_std_compliance;
358 s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0;367 s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0;
359 s->mpeg_quant = avctx->mpeg_quant;368 s->mpeg_quant = avctx->mpeg_quant;
@@ -373,13 +382,18 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 13 unmodified lines
373 /* Fixed QSCALE */382 /* Fixed QSCALE */
374 s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);383 s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
375 384
385#if FF_API_MPV_GLOBAL_OPTS
386 if (s->flags & CODEC_FLAG_QP_RD)
387 s->mpv_flags |= FF_MPV_FLAG_QP_RD;
388#endif
389
376 s->adaptive_quant = (s->avctx->lumi_masking ||390 s->adaptive_quant = (s->avctx->lumi_masking ||
377 s->avctx->dark_masking ||391 s->avctx->dark_masking ||
378 s->avctx->temporal_cplx_masking ||392 s->avctx->temporal_cplx_masking ||
379 s->avctx->spatial_cplx_masking ||393 s->avctx->spatial_cplx_masking ||
380 s->avctx->p_masking ||394 s->avctx->p_masking ||
381 s->avctx->border_masking ||395 s->avctx->border_masking ||
382 (s->flags & CODEC_FLAG_QP_RD)) &&396 (s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
383 !s->fixed_qscale;397 !s->fixed_qscale;
384 398
385 s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER);399 s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER);
@@ -488,12 +502,17 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 102 unmodified lines
488 return -1;502 return -1;
489 }503 }
490 504
491 if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) {505#if FF_API_MPV_GLOBAL_OPTS
506 if (s->flags & CODEC_FLAG_CBP_RD)
507 s->mpv_flags |= FF_MPV_FLAG_CBP_RD;
508#endif
509
510 if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
492 av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");511 av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
493 return -1;512 return -1;
494 }513 }
495 514
496 if ((s->flags & CODEC_FLAG_QP_RD) &&515 if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
497 s->avctx->mb_decision != FF_MB_DECISION_RD) {516 s->avctx->mb_decision != FF_MB_DECISION_RD) {
498 av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");517 av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
499 return -1;518 return -1;
@@ -610,6 +629,15 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 110 unmodified lines
610 }629 }
611 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;630 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
612 631
632#if FF_API_MPV_GLOBAL_OPTS
633 if (avctx->flags2 & CODEC_FLAG2_SKIP_RD)
634 s->mpv_flags |= FF_MPV_FLAG_SKIP_RD;
635 if (avctx->flags2 & CODEC_FLAG2_STRICT_GOP)
636 s->mpv_flags |= FF_MPV_FLAG_STRICT_GOP;
637 if (avctx->quantizer_noise_shaping)
638 s->quantizer_noise_shaping = avctx->quantizer_noise_shaping;
639#endif
640
613 switch (avctx->codec->id) {641 switch (avctx->codec->id) {
614 case CODEC_ID_MPEG1VIDEO:642 case CODEC_ID_MPEG1VIDEO:
615 s->out_format = FMT_MPEG1;643 s->out_format = FMT_MPEG1;
@@ -1301,7 +1329,7 @@ static int select_input_picture(MpegEncContext *s) · 685 unmodified lines
1301 }1329 }
1302 1330
1303 if (s->picture_in_gop_number + b_frames >= s->gop_size) {1331 if (s->picture_in_gop_number + b_frames >= s->gop_size) {
1304 if ((s->flags2 & CODEC_FLAG2_STRICT_GOP) &&1332 if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
1305 s->gop_size > s->picture_in_gop_number) {1333 s->gop_size > s->picture_in_gop_number) {
1306 b_frames = s->gop_size - s->picture_in_gop_number - 1;1334 b_frames = s->gop_size - s->picture_in_gop_number - 1;
1307 } else {1335 } else {
@@ -1726,7 +1754,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 418 unmodified lines
1726 s->lambda = s->lambda_table[mb_xy];1754 s->lambda = s->lambda_table[mb_xy];
1727 update_qscale(s);1755 update_qscale(s);
1728 1756
1729 if (!(s->flags & CODEC_FLAG_QP_RD)) {1757 if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {
1730 s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];1758 s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];
1731 s->dquant = s->qscale - last_qp;1759 s->dquant = s->qscale - last_qp;
1732 1760
@@ -1746,7 +1774,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 13 unmodified lines
1746 }1774 }
1747 }1775 }
1748 ff_set_qscale(s, last_qp + s->dquant);1776 ff_set_qscale(s, last_qp + s->dquant);
1749 } else if (s->flags & CODEC_FLAG_QP_RD)1777 } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD)
1750 ff_set_qscale(s, s->qscale + s->dquant);1778 ff_set_qscale(s, s->qscale + s->dquant);
1751 1779
1752 wrap_y = s->linesize;1780 wrap_y = s->linesize;
@@ -1934,7 +1962,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 181 unmodified lines
1934 }1962 }
1935 }1963 }
1936 1964
1937 if (s->avctx->quantizer_noise_shaping) {1965 if (s->quantizer_noise_shaping) {
1938 if (!skip_dct[0])1966 if (!skip_dct[0])
1939 get_visual_weight(weight[0], ptr_y , wrap_y);1967 get_visual_weight(weight[0], ptr_y , wrap_y);
1940 if (!skip_dct[1])1968 if (!skip_dct[1])
@@ -1975,7 +2003,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 34 unmodified lines
1975 } else2003 } else
1976 s->block_last_index[i] = -1;2004 s->block_last_index[i] = -1;
1977 }2005 }
1978 if (s->avctx->quantizer_noise_shaping) {2006 if (s->quantizer_noise_shaping) {
1979 for (i = 0; i < mb_block_count; i++) {2007 for (i = 0; i < mb_block_count; i++) {
1980 if (!skip_dct[i]) {2008 if (!skip_dct[i]) {
1981 s->block_last_index[i] =2009 s->block_last_index[i] =
@@ -1992,7 +2020,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 10 unmodified lines
1992 for (i = 4; i < mb_block_count; i++)2020 for (i = 4; i < mb_block_count; i++)
1993 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);2021 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
1994 2022
1995 if (s->flags & CODEC_FLAG_CBP_RD) {2023 if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
1996 for (i = 0; i < mb_block_count; i++) {2024 for (i = 0; i < mb_block_count; i++) {
1997 if (s->block_last_index[i] == -1)2025 if (s->block_last_index[i] == -1)
1998 s->coded_score[i] = INT_MAX / 256;2026 s->coded_score[i] = INT_MAX / 256;
@@ -2513,7 +2541,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 514 unmodified lines
2513 s->mb_skipped=0;2541 s->mb_skipped=0;
2514 s->dquant=0; //only for QP_RD2542 s->dquant=0; //only for QP_RD
2515 2543
2516 if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD2544 if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) { // more than 1 MB type possible or FF_MPV_FLAG_QP_RD
2517 int next_block=0;2545 int next_block=0;
2518 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;2546 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
2519 2547
@@ -2650,7 +2678,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 130 unmodified lines
2650 }2678 }
2651 }2679 }
2652 2680
2653 if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){2681 if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) {
2654 if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD2682 if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD
2655 const int last_qp= backup_s.qscale;2683 const int last_qp= backup_s.qscale;
2656 int qpi, qp, dc[6];2684 int qpi, qp, dc[6];
@@ -2715,7 +2743,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 58 unmodified lines
2715 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,2743 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
2716 &dmin, &next_block, 0, 0);2744 &dmin, &next_block, 0, 0);
2717 }2745 }
2718 if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){2746 if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) {
2719 int coded=0;2747 int coded=0;
2720 for(i=0; i<6; i++)2748 for(i=0; i<6; i++)
2721 coded |= s->block_last_index[i];2749 coded |= s->block_last_index[i];
@@ -3755,7 +3783,7 @@ STOP_TIMER("init rem[]") · 1033 unmodified lines
3755#ifdef REFINE_STATS3783#ifdef REFINE_STATS
3756{START_TIMER3784{START_TIMER
3757#endif3785#endif
3758 analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;3786 analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3;
3759 3787
3760 if(analyze_gradient){3788 if(analyze_gradient){
3761#ifdef REFINE_STATS3789#ifdef REFINE_STATS
@@ -3813,7 +3841,7 @@ STOP_TIMER("dct")} · 51 unmodified lines
3813 const int level= block[j];3841 const int level= block[j];
3814 int change, old_coeff;3842 int change, old_coeff;
3815 3843
3816 if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1)3844 if(s->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
3817 break;3845 break;
3818 3846
3819 if(level){3847 if(level){
@@ -3831,7 +3859,7 @@ STOP_TIMER("dct")} · 11 unmodified lines
3831 int score, new_coeff, unquant_change;3859 int score, new_coeff, unquant_change;
3832 3860
3833 score=0;3861 score=0;
3834 if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))3862 if(s->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
3835 continue;3863 continue;
3836 3864
3837 if(new_level){3865 if(new_level){
@@ -4089,6 +4117,7 @@ int ff_dct_quantize_c(MpegEncContext *s, · 251 unmodified lines
4089static const AVOption h263_options[] = {4117static const AVOption h263_options[] = {
4090 { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },4118 { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4091 { "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},4119 { "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
4120 FF_MPV_COMMON_OPTS
4092 { NULL },4121 { NULL },
4093};4122};
4094 4123
@@ -4117,6 +4146,7 @@ static const AVOption h263p_options[] = { · 22 unmodified lines
4117 { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },4146 { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4118 { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },4147 { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4119 { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},4148 { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
4149 FF_MPV_COMMON_OPTS
4120 { NULL },4150 { NULL },
4121};4151};
4122static const AVClass h263p_class = {4152static const AVClass h263p_class = {
@@ -4140,6 +4170,8 @@ AVCodec ff_h263p_encoder = { · 17 unmodified lines
4140 .priv_class = &h263p_class,4170 .priv_class = &h263p_class,
4141};4171};
4142 4172
4173FF_MPV_GENERIC_CLASS(msmpeg4v2)
4174
4143AVCodec ff_msmpeg4v2_encoder = {4175AVCodec ff_msmpeg4v2_encoder = {
4144 .name = "msmpeg4v2",4176 .name = "msmpeg4v2",
4145 .type = AVMEDIA_TYPE_VIDEO,4177 .type = AVMEDIA_TYPE_VIDEO,
@@ -4150,8 +4182,11 @@ AVCodec ff_msmpeg4v2_encoder = { · 4 unmodified lines
4150 .close = ff_MPV_encode_end,4182 .close = ff_MPV_encode_end,
4151 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},4183 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4152 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),4184 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
4185 .priv_class = &msmpeg4v2_class,
4153};4186};
4154 4187
4188FF_MPV_GENERIC_CLASS(msmpeg4v3)
4189
4155AVCodec ff_msmpeg4v3_encoder = {4190AVCodec ff_msmpeg4v3_encoder = {
4156 .name = "msmpeg4",4191 .name = "msmpeg4",
4157 .type = AVMEDIA_TYPE_VIDEO,4192 .type = AVMEDIA_TYPE_VIDEO,
@@ -4162,8 +4197,11 @@ AVCodec ff_msmpeg4v3_encoder = { · 4 unmodified lines
4162 .close = ff_MPV_encode_end,4197 .close = ff_MPV_encode_end,
4163 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},4198 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4164 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),4199 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
4200 .priv_class = &msmpeg4v3_class,
4165};4201};
4166 4202
4203FF_MPV_GENERIC_CLASS(wmv1)
4204
4167AVCodec ff_wmv1_encoder = {4205AVCodec ff_wmv1_encoder = {
4168 .name = "wmv1",4206 .name = "wmv1",
4169 .type = AVMEDIA_TYPE_VIDEO,4207 .type = AVMEDIA_TYPE_VIDEO,
@@ -4174,4 +4212,5 @@ AVCodec ff_wmv1_encoder = { · 4 unmodified lines
4174 .close = ff_MPV_encode_end,4212 .close = ff_MPV_encode_end,
4175 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},4213 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4176 .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),4214 .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
4215 .priv_class = &wmv1_class,
4177};4216};
libavcodec/options.c+21−7
@@ -98,12 +98,16 @@ static const AVOption options[]={ · 97 unmodified lines
98{"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},98{"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
99{"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},99{"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
100{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"},100{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"},
101{"cbp", "use rate distortion optimization for cbp", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},101#if FF_API_MPV_GLOBAL_OPTS
102{"qprd", "use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},102{"cbp", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
103{"qprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
104#endif
103{"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},105{"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},
104{"cgop", "closed gop", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},106{"cgop", "closed gop", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},
105{"fast", "allow non spec compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},107{"fast", "allow non spec compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},
106{"sgop", "strictly enforce gop size", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},108#if FF_API_MPV_GLOBAL_OPTS
109{"sgop", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
110#endif
107{"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},111{"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
108{"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},112{"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},
109{"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"},113{"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"},
@@ -167,8 +171,10 @@ static const AVOption options[]={ · 57 unmodified lines
167{"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},171{"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},
168{"ms", "workaround various bugs in microsofts broken decoders", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},172{"ms", "workaround various bugs in microsofts broken decoders", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},
169{"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},173{"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},
174#if FF_API_MPV_GLOBAL_OPTS
170{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},175{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
171{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},176{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
177#endif
172{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},178{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
173{"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},179{"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
174{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},180{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
@@ -194,8 +200,8 @@ static const AVOption options[]={ · 19 unmodified lines
194{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},200{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
195{"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},201{"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
196{"rc_eq", "set rate control equation", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},202{"rc_eq", "set rate control equation", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
197{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},203{"maxrate", "set max bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
198{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},204{"minrate", "set min bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
199{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E},205{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E},
200{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E},206{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E},
201{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E},207{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E},
@@ -296,7 +302,9 @@ static const AVOption options[]={ · 94 unmodified lines
296{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},302{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
297{"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},303{"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
298{"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},304{"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
305#if FF_API_COLOR_TABLE_ID
299{"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},306{"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
307#endif
300{"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},308{"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
301{"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"},309{"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"},
302{"vlc", "variable length coder / huffman coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"},310{"vlc", "variable length coder / huffman coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"},
@@ -317,10 +325,14 @@ static const AVOption options[]={ · 14 unmodified lines
317{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E},325{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
318{"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},326{"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
319{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},327{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
328#if FF_API_INTER_THRESHOLD
320{"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},329{"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
330#endif
321{"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT}, 0, UINT_MAX, V|A|E|D, "flags2"},331{"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT}, 0, UINT_MAX, V|A|E|D, "flags2"},
322{"error", NULL, OFFSET(error_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},332{"error", NULL, OFFSET(error_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
323{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},333#if FF_API_MPV_GLOBAL_OPTS
334{"qns", "deprecated, use mpegvideo private options instead", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
335#endif
324{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"},336{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"},
325{"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"},337{"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"},
326{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},338{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
@@ -366,7 +378,9 @@ static const AVOption options[]={ · 39 unmodified lines
366{"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},378{"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
367{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},379{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
368{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},380{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
369{"skiprd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},381#if FF_API_MPV_GLOBAL_OPTS
382{"skiprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
383#endif
370{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},384{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},
371{"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},385{"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},
372{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},386{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},
libavcodec/proresdec_lgpl.c+32−13
@@ -165,6 +165,10 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, · 164 unmodified lines
165 ctx->picture.top_field_first = ctx->frame_type & 1;165 ctx->picture.top_field_first = ctx->frame_type & 1;
166 }166 }
167 167
168 avctx->color_primaries = buf[14];
169 avctx->color_trc = buf[15];
170 avctx->colorspace = buf[16];
171
168 ctx->alpha_info = buf[17] & 0xf;172 ctx->alpha_info = buf[17] & 0xf;
169 if (ctx->alpha_info)173 if (ctx->alpha_info)
170 av_log_missing_feature(avctx, "alpha channel", 0);174 av_log_missing_feature(avctx, "alpha channel", 0);
@@ -411,7 +415,7 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td, · 240 unmodified lines
411 int data_size, uint16_t *out_ptr,415 int data_size, uint16_t *out_ptr,
412 int linesize, int mbs_per_slice,416 int linesize, int mbs_per_slice,
413 int blocks_per_mb, int plane_size_factor,417 int blocks_per_mb, int plane_size_factor,
414 const int16_t *qmat)418 const int16_t *qmat, int is_chroma)
415{419{
416 GetBitContext gb;420 GetBitContext gb;
417 DCTELEM *block_ptr;421 DCTELEM *block_ptr;
@@ -431,18 +435,33 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td, · 13 unmodified lines
431 /* inverse quantization, inverse transform and output */435 /* inverse quantization, inverse transform and output */
432 block_ptr = td->blocks;436 block_ptr = td->blocks;
433 437
434 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {438 if (!is_chroma) {
435 ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);439 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
436 block_ptr += 64;440 ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
437 if (blocks_per_mb > 2) {441 block_ptr += 64;
438 ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);442 if (blocks_per_mb > 2) {
443 ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
444 block_ptr += 64;
445 }
446 ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
439 block_ptr += 64;447 block_ptr += 64;
448 if (blocks_per_mb > 2) {
449 ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
450 block_ptr += 64;
451 }
440 }452 }
441 ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);453 } else {
442 block_ptr += 64;454 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
443 if (blocks_per_mb > 2) {455 ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
444 ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);456 block_ptr += 64;
457 ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
445 block_ptr += 64;458 block_ptr += 64;
459 if (blocks_per_mb > 2) {
460 ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
461 block_ptr += 64;
462 ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
463 block_ptr += 64;
464 }
446 }465 }
447 }466 }
448}467}
@@ -523,7 +542,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata) · 74 unmodified lines
523 (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +542 (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
524 (mb_x_pos << 5)), y_linesize,543 (mb_x_pos << 5)), y_linesize,
525 mbs_per_slice, 4, slice_width_factor + 2,544 mbs_per_slice, 4, slice_width_factor + 2,
526 td->qmat_luma_scaled);545 td->qmat_luma_scaled, 0);
527 546
528 /* decode U chroma plane */547 /* decode U chroma plane */
529 decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size,548 decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size,
@@ -531,7 +550,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata) · 1 unmodified line
531 (mb_x_pos << ctx->mb_chroma_factor)),550 (mb_x_pos << ctx->mb_chroma_factor)),
532 u_linesize, mbs_per_slice, ctx->num_chroma_blocks,551 u_linesize, mbs_per_slice, ctx->num_chroma_blocks,
533 slice_width_factor + ctx->chroma_factor - 1,552 slice_width_factor + ctx->chroma_factor - 1,
534 td->qmat_chroma_scaled);553 td->qmat_chroma_scaled, 1);
535 554
536 /* decode V chroma plane */555 /* decode V chroma plane */
537 decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size,556 decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size,
@@ -540,7 +559,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata) · 2 unmodified lines
540 (mb_x_pos << ctx->mb_chroma_factor)),559 (mb_x_pos << ctx->mb_chroma_factor)),
541 v_linesize, mbs_per_slice, ctx->num_chroma_blocks,560 v_linesize, mbs_per_slice, ctx->num_chroma_blocks,
542 slice_width_factor + ctx->chroma_factor - 1,561 slice_width_factor + ctx->chroma_factor - 1,
543 td->qmat_chroma_scaled);562 td->qmat_chroma_scaled, 1);
544 563
545 return 0;564 return 0;
546}565}
libavcodec/proresenc_kostya.c+35−22
@@ -171,7 +171,7 @@ typedef struct ProresContext { · 170 unmodified lines
171static void get_slice_data(ProresContext *ctx, const uint16_t *src,171static void get_slice_data(ProresContext *ctx, const uint16_t *src,
172 int linesize, int x, int y, int w, int h,172 int linesize, int x, int y, int w, int h,
173 DCTELEM *blocks,173 DCTELEM *blocks,
174 int mbs_per_slice, int blocks_per_mb)174 int mbs_per_slice, int blocks_per_mb, int is_chroma)
175{175{
176 const uint16_t *esrc;176 const uint16_t *esrc;
177 const int mb_width = 4 * blocks_per_mb;177 const int mb_width = 4 * blocks_per_mb;
@@ -189,37 +189,50 @@ static void get_slice_data(ProresContext *ctx, const uint16_t *src, · 11 unmodified lines
189 elinesize = linesize;189 elinesize = linesize;
190 } else {190 } else {
191 int bw, bh, pix;191 int bw, bh, pix;
192 const int estride = 16 / sizeof(*ctx->emu_buf);
193 192
194 esrc = ctx->emu_buf;193 esrc = ctx->emu_buf;
195 elinesize = 16;194 elinesize = 16 * sizeof(*ctx->emu_buf);
196 195
197 bw = FFMIN(w - x, mb_width);196 bw = FFMIN(w - x, mb_width);
198 bh = FFMIN(h - y, 16);197 bh = FFMIN(h - y, 16);
199 198
200 for (j = 0; j < bh; j++) {199 for (j = 0; j < bh; j++) {
201 memcpy(ctx->emu_buf + j * estride, src + j * linesize,200 memcpy(ctx->emu_buf + j * 16,
201 (const uint8_t*)src + j * linesize,
202 bw * sizeof(*src));202 bw * sizeof(*src));
203 pix = ctx->emu_buf[j * estride + bw - 1];203 pix = ctx->emu_buf[j * 16 + bw - 1];
204 for (k = bw; k < mb_width; k++)204 for (k = bw; k < mb_width; k++)
205 ctx->emu_buf[j * estride + k] = pix;205 ctx->emu_buf[j * 16 + k] = pix;
206 }206 }
207 for (; j < 16; j++)207 for (; j < 16; j++)
208 memcpy(ctx->emu_buf + j * estride,208 memcpy(ctx->emu_buf + j * 16,
209 ctx->emu_buf + (bh - 1) * estride,209 ctx->emu_buf + (bh - 1) * 16,
210 mb_width * sizeof(*ctx->emu_buf));210 mb_width * sizeof(*ctx->emu_buf));
211 }211 }
212 ctx->dsp.fdct(esrc, elinesize, blocks);212 if (!is_chroma) {
213 blocks += 64;213 ctx->dsp.fdct(esrc, elinesize, blocks);
214 if (blocks_per_mb > 2) {
215 ctx->dsp.fdct(src + 8, linesize, blocks);
216 blocks += 64;214 blocks += 64;
217 }215 if (blocks_per_mb > 2) {
218 ctx->dsp.fdct(src + linesize * 4, linesize, blocks);216 ctx->dsp.fdct(src + 8, linesize, blocks);
219 blocks += 64;217 blocks += 64;
220 if (blocks_per_mb > 2) {218 }
221 ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);219 ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
222 blocks += 64;220 blocks += 64;
221 if (blocks_per_mb > 2) {
222 ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
223 blocks += 64;
224 }
225 } else {
226 ctx->dsp.fdct(esrc, elinesize, blocks);
227 blocks += 64;
228 ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
229 blocks += 64;
230 if (blocks_per_mb > 2) {
231 ctx->dsp.fdct(src + 8, linesize, blocks);
232 blocks += 64;
233 ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
234 blocks += 64;
235 }
223 }236 }
224 237
225 x += mb_width;238 x += mb_width;
@@ -383,7 +396,7 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, · 157 unmodified lines
383 396
384 get_slice_data(ctx, src, pic->linesize[i], xp, yp,397 get_slice_data(ctx, src, pic->linesize[i], xp, yp,
385 pwidth, avctx->height, ctx->blocks[0],398 pwidth, avctx->height, ctx->blocks[0],
386 mbs_per_slice, num_cblocks);399 mbs_per_slice, num_cblocks, is_chroma);
387 sizes[i] = encode_slice_plane(ctx, pb, src, pic->linesize[i],400 sizes[i] = encode_slice_plane(ctx, pb, src, pic->linesize[i],
388 mbs_per_slice, ctx->blocks[0],401 mbs_per_slice, ctx->blocks[0],
389 num_cblocks, plane_factor,402 num_cblocks, plane_factor,
@@ -539,7 +552,7 @@ static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic, · 149 unmodified lines
539 552
540 get_slice_data(ctx, src, pic->linesize[i], xp, yp,553 get_slice_data(ctx, src, pic->linesize[i], xp, yp,
541 pwidth, avctx->height, ctx->blocks[i],554 pwidth, avctx->height, ctx->blocks[i],
542 mbs_per_slice, num_cblocks[i]);555 mbs_per_slice, num_cblocks[i], is_chroma[i]);
543 }556 }
544 557
545 for (q = min_quant; q < max_quant + 2; q++) {558 for (q = min_quant; q < max_quant + 2; q++) {
@@ -676,9 +689,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 130 unmodified lines
676 bytestream_put_be16 (&buf, avctx->height);689 bytestream_put_be16 (&buf, avctx->height);
677 bytestream_put_byte (&buf, ctx->chroma_factor << 6); // frame flags690 bytestream_put_byte (&buf, ctx->chroma_factor << 6); // frame flags
678 bytestream_put_byte (&buf, 0); // reserved691 bytestream_put_byte (&buf, 0); // reserved
679 bytestream_put_byte (&buf, 0); // primaries692 bytestream_put_byte (&buf, avctx->color_primaries);
680 bytestream_put_byte (&buf, 0); // transfer function693 bytestream_put_byte (&buf, avctx->color_trc);
681 bytestream_put_byte (&buf, 6); // colour matrix - ITU-R BT.601-4694 bytestream_put_byte (&buf, avctx->colorspace);
682 bytestream_put_byte (&buf, 0x40); // source format and alpha information695 bytestream_put_byte (&buf, 0x40); // source format and alpha information
683 bytestream_put_byte (&buf, 0); // reserved696 bytestream_put_byte (&buf, 0); // reserved
684 bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present697 bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present
libavcodec/qtrle.c+1−1
@@ -424,7 +424,7 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx) · 423 unmodified lines
424 default:424 default:
425 av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",425 av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
426 avctx->bits_per_coded_sample);426 avctx->bits_per_coded_sample);
427 break;427 return AVERROR_INVALIDDATA;
428 }428 }
429 429
430 avcodec_get_frame_defaults(&s->frame);430 avcodec_get_frame_defaults(&s->frame);
libavcodec/rpza.c+4−0
@@ -183,6 +183,8 @@ static void rpza_decode_stream(RpzaContext *s) · 182 unmodified lines
183 color4[1] |= ((11 * ta + 21 * tb) >> 5);183 color4[1] |= ((11 * ta + 21 * tb) >> 5);
184 color4[2] |= ((21 * ta + 11 * tb) >> 5);184 color4[2] |= ((21 * ta + 11 * tb) >> 5);
185 185
186 if (s->size - stream_ptr < n_blocks * 4)
187 return;
186 while (n_blocks--) {188 while (n_blocks--) {
187 block_ptr = row_ptr + pixel_ptr;189 block_ptr = row_ptr + pixel_ptr;
188 for (pixel_y = 0; pixel_y < 4; pixel_y++) {190 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
@@ -200,6 +202,8 @@ static void rpza_decode_stream(RpzaContext *s) · 11 unmodified lines
200 202
201 /* Fill block with 16 colors */203 /* Fill block with 16 colors */
202 case 0x00:204 case 0x00:
205 if (s->size - stream_ptr < 16)
206 return;
203 block_ptr = row_ptr + pixel_ptr;207 block_ptr = row_ptr + pixel_ptr;
204 for (pixel_y = 0; pixel_y < 4; pixel_y++) {208 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
205 for (pixel_x = 0; pixel_x < 4; pixel_x++){209 for (pixel_x = 0; pixel_x < 4; pixel_x++){
libavcodec/rv10enc.c+3−0
@@ -56,6 +56,8 @@ void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number) · 55 unmodified lines
56 put_bits(&s->pb, 3, 0); /* ignored */56 put_bits(&s->pb, 3, 0); /* ignored */
57}57}
58 58
59FF_MPV_GENERIC_CLASS(rv10)
60
59AVCodec ff_rv10_encoder = {61AVCodec ff_rv10_encoder = {
60 .name = "rv10",62 .name = "rv10",
61 .type = AVMEDIA_TYPE_VIDEO,63 .type = AVMEDIA_TYPE_VIDEO,
@@ -66,4 +68,5 @@ AVCodec ff_rv10_encoder = { · 4 unmodified lines
66 .close = ff_MPV_encode_end,68 .close = ff_MPV_encode_end,
67 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},69 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
68 .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),70 .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
71 .priv_class = &rv10_class,
69};72};
libavcodec/rv20enc.c+3−0
@@ -57,6 +57,8 @@ void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number){ · 56 unmodified lines
57 }57 }
58}58}
59 59
60FF_MPV_GENERIC_CLASS(rv20)
61
60AVCodec ff_rv20_encoder = {62AVCodec ff_rv20_encoder = {
61 .name = "rv20",63 .name = "rv20",
62 .type = AVMEDIA_TYPE_VIDEO,64 .type = AVMEDIA_TYPE_VIDEO,
@@ -67,4 +69,5 @@ AVCodec ff_rv20_encoder = { · 4 unmodified lines
67 .close = ff_MPV_encode_end,69 .close = ff_MPV_encode_end,
68 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},70 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
69 .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),71 .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
72 .priv_class = &rv20_class,
70};73};
libavcodec/version.h+9−0
@@ -60,5 +60,14 @@ · 59 unmodified lines
60#ifndef FF_API_OLD_ENCODE_VIDEO60#ifndef FF_API_OLD_ENCODE_VIDEO
61#define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 55)61#define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 55)
62#endif62#endif
63#ifndef FF_API_MPV_GLOBAL_OPTS
64#define FF_API_MPV_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 55)
65#endif
66#ifndef FF_API_COLOR_TABLE_ID
67#define FF_API_COLOR_TABLE_ID (LIBAVCODEC_VERSION_MAJOR < 55)
68#endif
69#ifndef FF_API_INTER_THRESHOLD
70#define FF_API_INTER_THRESHOLD (LIBAVCODEC_VERSION_MAJOR < 55)
71#endif
63 72
64#endif /* AVCODEC_VERSION_H */73#endif /* AVCODEC_VERSION_H */
libavcodec/vmnc.c+1−1
@@ -484,7 +484,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 483 unmodified lines
484 break;484 break;
485 default:485 default:
486 av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);486 av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
487 return AVERROR_PATCHWELCOME;487 return AVERROR_INVALIDDATA;
488 }488 }
489 489
490 return 0;490 return 0;
libavcodec/vp5.c+5−0
@@ -57,6 +57,11 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size, · 56 unmodified lines
57 }57 }
58 rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */58 rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */
59 cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */59 cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */
60 if (!rows || !cols) {
61 av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n",
62 cols << 4, rows << 4);
63 return 0;
64 }
60 vp56_rac_gets(c, 8); /* number of displayed macroblock rows */65 vp56_rac_gets(c, 8); /* number of displayed macroblock rows */
61 vp56_rac_gets(c, 8); /* number of displayed macroblock cols */66 vp56_rac_gets(c, 8); /* number of displayed macroblock cols */
62 vp56_rac_gets(c, 2);67 vp56_rac_gets(c, 2);
libavcodec/vp6.c+5−1
@@ -77,6 +77,10 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size, · 76 unmodified lines
77 cols = buf[3]; /* number of stored macroblock cols */77 cols = buf[3]; /* number of stored macroblock cols */
78 /* buf[4] is number of displayed macroblock rows */78 /* buf[4] is number of displayed macroblock rows */
79 /* buf[5] is number of displayed macroblock cols */79 /* buf[5] is number of displayed macroblock cols */
80 if (!rows || !cols) {
81 av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4);
82 return 0;
83 }
80 84
81 if (!s->macroblocks || /* first frame */85 if (!s->macroblocks || /* first frame */
82 16*cols != s->avctx->coded_width ||86 16*cols != s->avctx->coded_width ||
@@ -97,7 +101,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size, · 14 unmodified lines
97 vrt_shift = 5;101 vrt_shift = 5;
98 s->sub_version = sub_version;102 s->sub_version = sub_version;
99 } else {103 } else {
100 if (!s->sub_version)104 if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height)
101 return 0;105 return 0;
102 106
103 if (separated_coeff || !s->filter_header) {107 if (separated_coeff || !s->filter_header) {
libavformat/asfdec.c+5−21
@@ -26,7 +26,6 @@ · 25 unmodified lines
26#include "libavutil/avstring.h"26#include "libavutil/avstring.h"
27#include "libavutil/dict.h"27#include "libavutil/dict.h"
28#include "libavutil/mathematics.h"28#include "libavutil/mathematics.h"
29#include "libavcodec/mpegaudio.h"
30#include "avformat.h"29#include "avformat.h"
31#include "internal.h"30#include "internal.h"
32#include "avio_internal.h"31#include "avio_internal.h"
@@ -199,6 +198,8 @@ static int asf_read_file_properties(AVFormatContext *s, int64_t size) · 166 unmodified lines
199 asf->hdr.flags = avio_rl32(pb);198 asf->hdr.flags = avio_rl32(pb);
200 asf->hdr.min_pktsize = avio_rl32(pb);199 asf->hdr.min_pktsize = avio_rl32(pb);
201 asf->hdr.max_pktsize = avio_rl32(pb);200 asf->hdr.max_pktsize = avio_rl32(pb);
201 if (asf->hdr.min_pktsize >= (1U<<29))
202 return AVERROR_INVALIDDATA;
202 asf->hdr.max_bitrate = avio_rl32(pb);203 asf->hdr.max_bitrate = avio_rl32(pb);
203 s->packet_size = asf->hdr.max_pktsize;204 s->packet_size = asf->hdr.max_pktsize;
204 205
@@ -317,25 +318,6 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) · 112 unmodified lines
317 || asf_st->ds_packet_size % asf_st->ds_chunk_size)318 || asf_st->ds_packet_size % asf_st->ds_chunk_size)
318 asf_st->ds_span = 0; // disable descrambling319 asf_st->ds_span = 0; // disable descrambling
319 }320 }
320 switch (st->codec->codec_id) {
321 case CODEC_ID_MP3:
322 st->codec->frame_size = MPA_FRAME_SIZE;
323 break;
324 case CODEC_ID_PCM_S16LE:
325 case CODEC_ID_PCM_S16BE:
326 case CODEC_ID_PCM_U16LE:
327 case CODEC_ID_PCM_U16BE:
328 case CODEC_ID_PCM_S8:
329 case CODEC_ID_PCM_U8:
330 case CODEC_ID_PCM_ALAW:
331 case CODEC_ID_PCM_MULAW:
332 st->codec->frame_size = 1;
333 break;
334 default:
335 /* This is probably wrong, but it prevents a crash later */
336 st->codec->frame_size = 1;
337 break;
338 }
339 } else if (type == AVMEDIA_TYPE_VIDEO &&321 } else if (type == AVMEDIA_TYPE_VIDEO &&
340 size - (avio_tell(pb) - pos1 + 24) >= 51) {322 size - (avio_tell(pb) - pos1 + 24) >= 51) {
341 avio_rl32(pb);323 avio_rl32(pb);
@@ -612,7 +594,9 @@ static int asf_read_header(AVFormatContext *s) · 270 unmodified lines
612 if (gsize < 24)594 if (gsize < 24)
613 return -1;595 return -1;
614 if (!ff_guidcmp(&g, &ff_asf_file_header)) {596 if (!ff_guidcmp(&g, &ff_asf_file_header)) {
615 asf_read_file_properties(s, gsize);597 int ret = asf_read_file_properties(s, gsize);
598 if (ret < 0)
599 return ret;
616 } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {600 } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
617 asf_read_stream_properties(s, gsize);601 asf_read_stream_properties(s, gsize);
618 } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {602 } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
libavformat/avformat.h+16−0
@@ -541,6 +541,13 @@ typedef struct AVIndexEntry { · 540 unmodified lines
541#define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */541#define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
542#define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */542#define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
543#define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */543#define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
544/**
545 * The stream is stored in the file as an attached picture/"cover art" (e.g.
546 * APIC frame in ID3v2). The single packet associated with it will be returned
547 * among the first few packets read from the file unless seeking takes place.
548 * It can also be accessed at any time in AVStream.attached_pic.
549 */
550#define AV_DISPOSITION_ATTACHED_PIC 0x0400
544 551
545/**552/**
546 * Stream structure.553 * Stream structure.
@@ -615,6 +622,15 @@ typedef struct AVStream { · 68 unmodified lines
615 */622 */
616 AVRational avg_frame_rate;623 AVRational avg_frame_rate;
617 624
625 /**
626 * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
627 * will contain the attached picture.
628 *
629 * decoding: set by libavformat, must not be modified by the caller.
630 * encoding: unused
631 */
632 AVPacket attached_pic;
633
618 /*****************************************************************634 /*****************************************************************
619 * All fields below this line are not part of the public API. They635 * All fields below this line are not part of the public API. They
620 * may not be used outside of libavformat and can be changed and636 * may not be used outside of libavformat and can be changed and
libavformat/dxa.c+2−0
@@ -107,6 +107,8 @@ static int dxa_read_header(AVFormatContext *s) · 106 unmodified lines
107 ret = ff_get_wav_header(pb, ast->codec, fsize);107 ret = ff_get_wav_header(pb, ast->codec, fsize);
108 if (ret < 0)108 if (ret < 0)
109 return ret;109 return ret;
110 if (ast->codec->sample_rate > 0)
111 avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
110 // find 'data' chunk112 // find 'data' chunk
111 while(avio_tell(pb) < c->vidpos && !url_feof(pb)){113 while(avio_tell(pb) < c->vidpos && !url_feof(pb)){
112 tag = avio_rl32(pb);114 tag = avio_rl32(pb);
libavformat/ffmdec.c+0−2
@@ -338,8 +338,6 @@ static int ffm_read_header(AVFormatContext *s) · 337 unmodified lines
338 codec->dct_algo = avio_rb32(pb);338 codec->dct_algo = avio_rb32(pb);
339 codec->strict_std_compliance = avio_rb32(pb);339 codec->strict_std_compliance = avio_rb32(pb);
340 codec->max_b_frames = avio_rb32(pb);340 codec->max_b_frames = avio_rb32(pb);
341 codec->luma_elim_threshold = avio_rb32(pb);
342 codec->chroma_elim_threshold = avio_rb32(pb);
343 codec->mpeg_quant = avio_rb32(pb);341 codec->mpeg_quant = avio_rb32(pb);
344 codec->intra_dc_precision = avio_rb32(pb);342 codec->intra_dc_precision = avio_rb32(pb);
345 codec->me_method = avio_rb32(pb);343 codec->me_method = avio_rb32(pb);
libavformat/ffmenc.c+0−2
@@ -144,8 +144,6 @@ static int ffm_write_header(AVFormatContext *s) · 143 unmodified lines
144 avio_wb32(pb, codec->dct_algo);144 avio_wb32(pb, codec->dct_algo);
145 avio_wb32(pb, codec->strict_std_compliance);145 avio_wb32(pb, codec->strict_std_compliance);
146 avio_wb32(pb, codec->max_b_frames);146 avio_wb32(pb, codec->max_b_frames);
147 avio_wb32(pb, codec->luma_elim_threshold);
148 avio_wb32(pb, codec->chroma_elim_threshold);
149 avio_wb32(pb, codec->mpeg_quant);147 avio_wb32(pb, codec->mpeg_quant);
150 avio_wb32(pb, codec->intra_dc_precision);148 avio_wb32(pb, codec->intra_dc_precision);
151 avio_wb32(pb, codec->me_method);149 avio_wb32(pb, codec->me_method);
libavformat/id3v2.c+147−6
@@ -38,6 +38,7 @@ · 37 unmodified lines
38#include "libavutil/intreadwrite.h"38#include "libavutil/intreadwrite.h"
39#include "libavutil/dict.h"39#include "libavutil/dict.h"
40#include "avio_internal.h"40#include "avio_internal.h"
41#include "internal.h"
41 42
42const AVMetadataConv ff_id3v2_34_metadata_conv[] = {43const AVMetadataConv ff_id3v2_34_metadata_conv[] = {
43 { "TALB", "album"},44 { "TALB", "album"},
@@ -99,6 +100,38 @@ const char ff_id3v2_3_tags[][4] = { · 55 unmodified lines
99 { 0 },100 { 0 },
100};101};
101 102
103const char *ff_id3v2_picture_types[21] = {
104 "Other",
105 "32x32 pixels 'file icon'",
106 "Other file icon",
107 "Cover (front)",
108 "Cover (back)",
109 "Leaflet page",
110 "Media (e.g. label side of CD)",
111 "Lead artist/lead performer/soloist",
112 "Artist/performer",
113 "Conductor",
114 "Band/Orchestra",
115 "Composer",
116 "Lyricist/text writer",
117 "Recording Location",
118 "During recording",
119 "During performance",
120 "Movie/video screen capture",
121 "A bright coloured fish",
122 "Illustration",
123 "Band/artist logotype",
124 "Publisher/Studio logotype",
125};
126
127const CodecMime ff_id3v2_mime_tags[] = {
128 {"image/gif" , CODEC_ID_GIF},
129 {"image/jpeg", CODEC_ID_MJPEG},
130 {"image/png" , CODEC_ID_PNG},
131 {"image/tiff", CODEC_ID_TIFF},
132 {"", CODEC_ID_NONE},
133};
134
102int ff_id3v2_match(const uint8_t *buf, const char * magic)135int ff_id3v2_match(const uint8_t *buf, const char * magic)
103{136{
104 return buf[0] == magic[0] &&137 return buf[0] == magic[0] &&
@@ -394,6 +427,84 @@ finish: · 289 unmodified lines
394 av_dict_set(m, "date", date, 0);427 av_dict_set(m, "date", date, 0);
395}428}
396 429
430static void free_apic(void *obj)
431{
432 ID3v2ExtraMetaAPIC *apic = obj;
433 av_freep(&apic->data);
434 av_freep(&apic->description);
435 av_freep(&apic);
436}
437
438static void read_apic(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)
439{
440 int enc, pic_type;
441 char mimetype[64];
442 const CodecMime *mime = ff_id3v2_mime_tags;
443 enum CodecID id = CODEC_ID_NONE;
444 ID3v2ExtraMetaAPIC *apic = NULL;
445 ID3v2ExtraMeta *new_extra = NULL;
446 int64_t end = avio_tell(pb) + taglen;
447
448 if (taglen <= 4)
449 goto fail;
450
451 new_extra = av_mallocz(sizeof(*new_extra));
452 apic = av_mallocz(sizeof(*apic));
453 if (!new_extra || !apic)
454 goto fail;
455
456 enc = avio_r8(pb);
457 taglen--;
458
459 /* mimetype */
460 taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype));
461 while (mime->id != CODEC_ID_NONE) {
462 if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
463 id = mime->id;
464 break;
465 }
466 mime++;
467 }
468 if (id == CODEC_ID_NONE) {
469 av_log(s, AV_LOG_WARNING, "Unknown attached picture mimetype: %s, skipping.\n", mimetype);
470 goto fail;
471 }
472 apic->id = id;
473
474 /* picture type */
475 pic_type = avio_r8(pb);
476 taglen--;
477 if (pic_type < 0 || pic_type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) {
478 av_log(s, AV_LOG_WARNING, "Unknown attached picture type %d.\n", pic_type);
479 pic_type = 0;
480 }
481 apic->type = ff_id3v2_picture_types[pic_type];
482
483 /* description and picture data */
484 if (decode_str(s, pb, enc, &apic->description, &taglen) < 0) {
485 av_log(s, AV_LOG_ERROR, "Error decoding attached picture description.\n");
486 goto fail;
487 }
488
489 apic->len = taglen;
490 apic->data = av_malloc(taglen);
491 if (!apic->data || avio_read(pb, apic->data, taglen) != taglen)
492 goto fail;
493
494 new_extra->tag = "APIC";
495 new_extra->data = apic;
496 new_extra->next = *extra_meta;
497 *extra_meta = new_extra;
498
499 return;
500
501fail:
502 if (apic)
503 free_apic(apic);
504 av_freep(&new_extra);
505 avio_seek(pb, end, SEEK_SET);
506}
507
397typedef struct ID3v2EMFunc {508typedef struct ID3v2EMFunc {
398 const char *tag3;509 const char *tag3;
399 const char *tag4;510 const char *tag4;
@@ -403,6 +514,7 @@ typedef struct ID3v2EMFunc { · 3 unmodified lines
403 514
404static const ID3v2EMFunc id3v2_extra_meta_funcs[] = {515static const ID3v2EMFunc id3v2_extra_meta_funcs[] = {
405 { "GEO", "GEOB", read_geobtag, free_geobtag },516 { "GEO", "GEOB", read_geobtag, free_geobtag },
517 { "PIC", "APIC", read_apic, free_apic },
406 { NULL }518 { NULL }
407};519};
408 520
@@ -620,7 +732,7 @@ seek: · 211 unmodified lines
620 return;732 return;
621}733}
622 734
623void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)735void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
624{736{
625 int len, ret;737 int len, ret;
626 uint8_t buf[ID3v2_HEADER_SIZE];738 uint8_t buf[ID3v2_HEADER_SIZE];
@@ -651,11 +763,6 @@ void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **e · 24 unmodified lines
651 merge_date(&s->metadata);763 merge_date(&s->metadata);
652}764}
653 765
654void ff_id3v2_read(AVFormatContext *s, const char *magic)
655{
656 ff_id3v2_read_all(s, magic, NULL);
657}
658
659void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)766void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
660{767{
661 ID3v2ExtraMeta *current = *extra_meta, *next;768 ID3v2ExtraMeta *current = *extra_meta, *next;
@@ -669,3 +776,37 @@ void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta) · 7 unmodified lines
669 current = next;776 current = next;
670 }777 }
671}778}
779
780int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
781{
782 ID3v2ExtraMeta *cur;
783
784 for (cur = *extra_meta; cur; cur = cur->next) {
785 ID3v2ExtraMetaAPIC *apic;
786 AVStream *st;
787
788 if (strcmp(cur->tag, "APIC"))
789 continue;
790 apic = cur->data;
791
792 if (!(st = avformat_new_stream(s, NULL)))
793 return AVERROR(ENOMEM);
794
795 st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
796 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
797 st->codec->codec_id = apic->id;
798 av_dict_set(&st->metadata, "title", apic->description, 0);
799 av_dict_set(&st->metadata, "comment", apic->type, 0);
800
801 av_init_packet(&st->attached_pic);
802 st->attached_pic.data = apic->data;
803 st->attached_pic.size = apic->len;
804 st->attached_pic.destruct = av_destruct_packet;
805 st->attached_pic.stream_index = st->index;
806
807 apic->data = NULL;
808 apic->len = 0;
809 }
810
811 return 0;
812}
libavformat/id3v2.h+49−8
@@ -24,6 +24,7 @@ · 23 unmodified lines
24 24
25#include <stdint.h>25#include <stdint.h>
26#include "avformat.h"26#include "avformat.h"
27#include "internal.h"
27#include "metadata.h"28#include "metadata.h"
28 29
29#define ID3v2_HEADER_SIZE 1030#define ID3v2_HEADER_SIZE 10
@@ -45,6 +46,12 @@ enum ID3v2Encoding { · 15 unmodified lines
45 ID3v2_ENCODING_UTF8 = 3,46 ID3v2_ENCODING_UTF8 = 3,
46};47};
47 48
49typedef struct ID3v2EncContext {
50 int version; ///< ID3v2 minor version, either 3 or 4
51 int64_t size_pos; ///< offset of the tag total size
52 int len; ///< size of the tag written so far
53} ID3v2EncContext;
54
48typedef struct ID3v2ExtraMeta {55typedef struct ID3v2ExtraMeta {
49 const char *tag;56 const char *tag;
50 void *data;57 void *data;
@@ -59,6 +66,14 @@ typedef struct ID3v2ExtraMetaGEOB { · 8 unmodified lines
59 uint8_t *data;66 uint8_t *data;
60} ID3v2ExtraMetaGEOB;67} ID3v2ExtraMetaGEOB;
61 68
69typedef struct ID3v2ExtraMetaAPIC {
70 uint8_t *data;
71 int len;
72 const char *type;
73 uint8_t *description;
74 enum CodecID id;
75} ID3v2ExtraMetaAPIC;
76
62/**77/**
63 * Detect ID3v2 Header.78 * Detect ID3v2 Header.
64 * @param buf must be ID3v2_HEADER_SIZE byte long79 * @param buf must be ID3v2_HEADER_SIZE byte long
@@ -75,24 +90,40 @@ int ff_id3v2_match(const uint8_t *buf, const char *magic); · 10 unmodified lines
75int ff_id3v2_tag_len(const uint8_t *buf);90int ff_id3v2_tag_len(const uint8_t *buf);
76 91
77/**92/**
78 * Read an ID3v2 tag (text tags only)93 * Read an ID3v2 tag, including supported extra metadata
94 * @param extra_meta If not NULL, extra metadata is parsed into a list of
95 * ID3v2ExtraMeta structs and *extra_meta points to the head of the list
79 */96 */
80void ff_id3v2_read(AVFormatContext *s, const char *magic);97void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);
81 98
82/**99/**
83 * Read an ID3v2 tag, including supported extra metadata (currently only GEOB)100 * Initialize an ID3v2 tag.
84 * @param extra_meta If not NULL, extra metadata is parsed into a list of101 */
85 * ID3v2ExtraMeta structs and *extra_meta points to the head of the list102void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version,
103 const char *magic);
104
105/**
106 * Convert and write all global metadata from s into an ID3v2 tag.
107 */
108int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3);
109
110/**
111 * Write an attached picture from pkt into an ID3v2 tag.
112 */
113int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt);
114
115/**
116 * Finalize an opened ID3v2 tag.
86 */117 */
87void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);118void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb);
88 119
89/**120/**
90 * Write an ID3v2 tag.121 * Write an ID3v2 tag containing all global metadata from s.
91 * @param id3v2_version Subversion of ID3v2; supported values are 3 and 4122 * @param id3v2_version Subversion of ID3v2; supported values are 3 and 4
92 * @param magic magic bytes to identify the header123 * @param magic magic bytes to identify the header
93 * If in doubt, use ID3v2_DEFAULT_MAGIC.124 * If in doubt, use ID3v2_DEFAULT_MAGIC.
94 */125 */
95int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, const char *magic);126int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, const char *magic);
96 127
97/**128/**
98 * Free memory allocated parsing special (non-text) metadata.129 * Free memory allocated parsing special (non-text) metadata.
@@ -100,6 +131,12 @@ int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, const char *mag · 1 unmodified line
100 */131 */
101void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta);132void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta);
102 133
134/**
135 * Create a stream for each APIC (attached picture) extracted from the
136 * ID3v2 header.
137 */
138int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta);
139
103extern const AVMetadataConv ff_id3v2_34_metadata_conv[];140extern const AVMetadataConv ff_id3v2_34_metadata_conv[];
104extern const AVMetadataConv ff_id3v2_4_metadata_conv[];141extern const AVMetadataConv ff_id3v2_4_metadata_conv[];
105 142
@@ -120,4 +157,8 @@ extern const char ff_id3v2_4_tags[][4]; · 14 unmodified lines
120 */157 */
121extern const char ff_id3v2_3_tags[][4];158extern const char ff_id3v2_3_tags[][4];
122 159
160extern const CodecMime ff_id3v2_mime_tags[];
161
162extern const char *ff_id3v2_picture_types[21];
163
123#endif /* AVFORMAT_ID3V2_H */164#endif /* AVFORMAT_ID3V2_H */
libavformat/id3v2enc.c+145−47
@@ -19,6 +19,8 @@ · 18 unmodified lines
19 */19 */
20 20
21#include <stdint.h>21#include <stdint.h>
22#include <string.h>
23
22#include "libavutil/avstring.h"24#include "libavutil/avstring.h"
23#include "libavutil/dict.h"25#include "libavutil/dict.h"
24#include "libavutil/intreadwrite.h"26#include "libavutil/intreadwrite.h"
@@ -26,12 +28,12 @@ · 1 unmodified line
26#include "avio.h"28#include "avio.h"
27#include "id3v2.h"29#include "id3v2.h"
28 30
29static void id3v2_put_size(AVFormatContext *s, int size)31static void id3v2_put_size(AVIOContext *pb, int size)
30{32{
31 avio_w8(s->pb, size >> 21 & 0x7f);33 avio_w8(pb, size >> 21 & 0x7f);
32 avio_w8(s->pb, size >> 14 & 0x7f);34 avio_w8(pb, size >> 14 & 0x7f);
33 avio_w8(s->pb, size >> 7 & 0x7f);35 avio_w8(pb, size >> 7 & 0x7f);
34 avio_w8(s->pb, size & 0x7f);36 avio_w8(pb, size & 0x7f);
35}37}
36 38
37static int string_is_ascii(const uint8_t *str)39static int string_is_ascii(const uint8_t *str)
@@ -40,17 +42,30 @@ static int string_is_ascii(const uint8_t *str) · 2 unmodified lines
40 return !*str;42 return !*str;
41}43}
42 44
45static void id3v2_encode_string(AVIOContext *pb, const uint8_t *str,
46 enum ID3v2Encoding enc)
47{
48 int (*put)(AVIOContext*, const char*);
49
50 if (enc == ID3v2_ENCODING_UTF16BOM) {
51 avio_wl16(pb, 0xFEFF); /* BOM */
52 put = avio_put_str16le;
53 } else
54 put = avio_put_str;
55
56 put(pb, str);
57}
58
43/**59/**
44 * Write a text frame with one (normal frames) or two (TXXX frames) strings60 * Write a text frame with one (normal frames) or two (TXXX frames) strings
45 * according to encoding (only UTF-8 or UTF-16+BOM supported).61 * according to encoding (only UTF-8 or UTF-16+BOM supported).
46 * @return number of bytes written or a negative error code.62 * @return number of bytes written or a negative error code.
47 */63 */
48static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2,64static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext *avioc, const char *str1, const char *str2,
49 uint32_t tag, enum ID3v2Encoding enc)65 uint32_t tag, enum ID3v2Encoding enc)
50{66{
51 int len;67 int len;
52 uint8_t *pb;68 uint8_t *pb;
53 int (*put)(AVIOContext*, const char*);
54 AVIOContext *dyn_buf;69 AVIOContext *dyn_buf;
55 if (avio_open_dyn_buf(&dyn_buf) < 0)70 if (avio_open_dyn_buf(&dyn_buf) < 0)
56 return AVERROR(ENOMEM);71 return AVERROR(ENOMEM);
@@ -62,28 +77,26 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2 · 5 unmodified lines
62 enc = ID3v2_ENCODING_ISO8859;77 enc = ID3v2_ENCODING_ISO8859;
63 78
64 avio_w8(dyn_buf, enc);79 avio_w8(dyn_buf, enc);
65 if (enc == ID3v2_ENCODING_UTF16BOM) {80 id3v2_encode_string(dyn_buf, str1, enc);
66 avio_wl16(dyn_buf, 0xFEFF); /* BOM */
67 put = avio_put_str16le;
68 } else
69 put = avio_put_str;
70
71 put(dyn_buf, str1);
72 if (str2)81 if (str2)
73 put(dyn_buf, str2);82 id3v2_encode_string(dyn_buf, str2, enc);
74 len = avio_close_dyn_buf(dyn_buf, &pb);83 len = avio_close_dyn_buf(dyn_buf, &pb);
75 84
76 avio_wb32(s->pb, tag);85 avio_wb32(avioc, tag);
77 id3v2_put_size(s, len);86 /* ID3v2.3 frame size is not synchsafe */
78 avio_wb16(s->pb, 0);87 if (id3->version == 3)
79 avio_write(s->pb, pb, len);88 avio_wb32(avioc, len);
89 else
90 id3v2_put_size(avioc, len);
91 avio_wb16(avioc, 0);
92 avio_write(avioc, pb, len);
80 93
81 av_freep(&pb);94 av_freep(&pb);
82 return len + ID3v2_HEADER_SIZE;95 return len + ID3v2_HEADER_SIZE;
83}96}
84 97
85static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const char table[][4],98static int id3v2_check_write_tag(ID3v2EncContext *id3, AVIOContext *pb, AVDictionaryEntry *t,
86 enum ID3v2Encoding enc)99 const char table[][4], enum ID3v2Encoding enc)
87{100{
88 uint32_t tag;101 uint32_t tag;
89 int i;102 int i;
@@ -93,7 +106,7 @@ static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const · 3 unmodified lines
93 tag = AV_RB32(t->key);106 tag = AV_RB32(t->key);
94 for (i = 0; *table[i]; i++)107 for (i = 0; *table[i]; i++)
95 if (tag == AV_RB32(table[i]))108 if (tag == AV_RB32(table[i]))
96 return id3v2_put_ttag(s, t->value, NULL, tag, enc);109 return id3v2_put_ttag(id3, pb, t->value, NULL, tag, enc);
97 return -1;110 return -1;
98}111}
99 112
@@ -135,52 +148,137 @@ static void id3v2_3_metadata_split_date(AVDictionary **pm) · 35 unmodified lines
135 *pm = dst;148 *pm = dst;
136}149}
137 150
138int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version,151void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version,
139 const char *magic)152 const char *magic)
140{153{
141 int64_t size_pos, cur_pos;154 id3->version = id3v2_version;
142 AVDictionaryEntry *t = NULL;
143 155
144 int totlen = 0, enc = id3v2_version == 3 ? ID3v2_ENCODING_UTF16BOM :156 avio_wb32(pb, MKBETAG(magic[0], magic[1], magic[2], id3v2_version));
145 ID3v2_ENCODING_UTF8;157 avio_w8(pb, 0);
146 158 avio_w8(pb, 0); /* flags */
147
148 avio_wb32(s->pb, MKBETAG(magic[0], magic[1], magic[2], id3v2_version));
149 avio_w8(s->pb, 0);
150 avio_w8(s->pb, 0); /* flags */
151 159
152 /* reserve space for size */160 /* reserve space for size */
153 size_pos = avio_tell(s->pb);161 id3->size_pos = avio_tell(pb);
154 avio_wb32(s->pb, 0);162 avio_wb32(pb, 0);
163}
164
165int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
166{
167 AVDictionaryEntry *t = NULL;
168 int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM :
169 ID3v2_ENCODING_UTF8;
155 170
156 ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL);171 ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL);
157 if (id3v2_version == 3)172 if (id3->version == 3)
158 id3v2_3_metadata_split_date(&s->metadata);173 id3v2_3_metadata_split_date(&s->metadata);
159 else if (id3v2_version == 4)174 else if (id3->version == 4)
160 ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL);175 ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL);
161 176
162 while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {177 while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
163 int ret;178 int ret;
164 179
165 if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_tags, enc)) > 0) {180 if ((ret = id3v2_check_write_tag(id3, s->pb, t, ff_id3v2_tags, enc)) > 0) {
166 totlen += ret;181 id3->len += ret;
167 continue;182 continue;
168 }183 }
169 if ((ret = id3v2_check_write_tag(s, t, id3v2_version == 3 ?184 if ((ret = id3v2_check_write_tag(id3, s->pb, t, id3->version == 3 ?
170 ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) {185 ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) {
171 totlen += ret;186 id3->len += ret;
172 continue;187 continue;
173 }188 }
174 189
175 /* unknown tag, write as TXXX frame */190 /* unknown tag, write as TXXX frame */
176 if ((ret = id3v2_put_ttag(s, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)191 if ((ret = id3v2_put_ttag(id3, s->pb, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
177 return ret;192 return ret;
178 totlen += ret;193 id3->len += ret;
179 }194 }
180 195
181 cur_pos = avio_tell(s->pb);196 return 0;
182 avio_seek(s->pb, size_pos, SEEK_SET);197}
183 id3v2_put_size(s, totlen);198
184 avio_seek(s->pb, cur_pos, SEEK_SET);199int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
200{
201 AVStream *st = s->streams[pkt->stream_index];
202 AVDictionaryEntry *e;
203
204 AVIOContext *dyn_buf;
205 uint8_t *buf;
206 const CodecMime *mime = ff_id3v2_mime_tags;
207 const char *mimetype = NULL, *desc = "";
208 int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM :
209 ID3v2_ENCODING_UTF8;
210 int i, len, type = 0;
211
212 /* get the mimetype*/
213 while (mime->id != CODEC_ID_NONE) {
214 if (mime->id == st->codec->codec_id) {
215 mimetype = mime->str;
216 break;
217 }
218 mime++;
219 }
220 if (!mimetype) {
221 av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
222 "write an attached picture.\n", st->index);
223 return AVERROR(EINVAL);
224 }
225
226 /* get the picture type */
227 e = av_dict_get(st->metadata, "comment", NULL, 0);
228 for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
229 if (strstr(ff_id3v2_picture_types[i], e->value) == ff_id3v2_picture_types[i]) {
230 type = i;
231 break;
232 }
233 }
234
235 /* get the description */
236 if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
237 desc = e->value;
238
239 /* start writing */
240 if (avio_open_dyn_buf(&dyn_buf) < 0)
241 return AVERROR(ENOMEM);
242
243 avio_w8(dyn_buf, enc);
244 avio_put_str(dyn_buf, mimetype);
245 avio_w8(dyn_buf, type);
246 id3v2_encode_string(dyn_buf, desc, enc);
247 avio_write(dyn_buf, pkt->data, pkt->size);
248 len = avio_close_dyn_buf(dyn_buf, &buf);
249
250 avio_wb32(s->pb, MKBETAG('A', 'P', 'I', 'C'));
251 if (id3->version == 3)
252 avio_wb32(s->pb, len);
253 else
254 id3v2_put_size(s->pb, len);
255 avio_wb16(s->pb, 0);
256 avio_write(s->pb, buf, len);
257 av_freep(&buf);
258
259 id3->len += len + ID3v2_HEADER_SIZE;
260
261 return 0;
262}
263
264void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb)
265{
266 int64_t cur_pos = avio_tell(pb);
267 avio_seek(pb, id3->size_pos, SEEK_SET);
268 id3v2_put_size(pb, id3->len);
269 avio_seek(pb, cur_pos, SEEK_SET);
270}
271
272int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version,
273 const char *magic)
274{
275 ID3v2EncContext id3 = { 0 };
276 int ret;
277
278 ff_id3v2_start(&id3, s->pb, id3v2_version, magic);
279 if ((ret = ff_id3v2_write_metadata(s, &id3)) < 0)
280 return ret;
281 ff_id3v2_finish(&id3, s->pb);
282
185 return 0;283 return 0;
186}284}
libavformat/internal.h+5−0
@@ -37,6 +37,11 @@ typedef struct AVCodecTag { · 36 unmodified lines
37 unsigned int tag;37 unsigned int tag;
38} AVCodecTag;38} AVCodecTag;
39 39
40typedef struct CodecMime{
41 char str[32];
42 enum CodecID id;
43} CodecMime;
44
40#ifdef __GNUC__45#ifdef __GNUC__
41#define dynarray_add(tab, nb_ptr, elem)\46#define dynarray_add(tab, nb_ptr, elem)\
42do {\47do {\
libavformat/matroska.h+1−5
@@ -24,6 +24,7 @@ · 23 unmodified lines
24 24
25#include "libavcodec/avcodec.h"25#include "libavcodec/avcodec.h"
26#include "metadata.h"26#include "metadata.h"
27#include "internal.h"
27 28
28/* EBML version supported */29/* EBML version supported */
29#define EBML_VERSION 130#define EBML_VERSION 1
@@ -250,11 +251,6 @@ typedef struct CodecTags{ · 220 unmodified lines
250 enum CodecID id;251 enum CodecID id;
251}CodecTags;252}CodecTags;
252 253
253typedef struct CodecMime{
254 char str[32];
255 enum CodecID id;
256}CodecMime;
257
258/* max. depth in the EBML tree structure */254/* max. depth in the EBML tree structure */
259#define EBML_MAX_DEPTH 16255#define EBML_MAX_DEPTH 16
260 256
libavformat/mov.c+4−3
@@ -1223,6 +1223,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) · 1222 unmodified lines
1223 if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {1223 if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
1224 unsigned int color_depth, len;1224 unsigned int color_depth, len;
1225 int color_greyscale;1225 int color_greyscale;
1226 int color_table_id;
1226 1227
1227 st->codec->codec_id = id;1228 st->codec->codec_id = id;
1228 avio_rb16(pb); /* version */1229 avio_rb16(pb); /* version */
@@ -1250,9 +1251,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) · 21 unmodified lines
1250 st->codec->codec_tag=MKTAG('I', '4', '2', '0');1251 st->codec->codec_tag=MKTAG('I', '4', '2', '0');
1251 1252
1252 st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */1253 st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */
1253 st->codec->color_table_id = avio_rb16(pb); /* colortable id */1254 color_table_id = avio_rb16(pb); /* colortable id */
1254 av_dlog(c->fc, "depth %d, ctab id %d\n",1255 av_dlog(c->fc, "depth %d, ctab id %d\n",
1255 st->codec->bits_per_coded_sample, st->codec->color_table_id);1256 st->codec->bits_per_coded_sample, color_table_id);
1256 /* figure out the palette situation */1257 /* figure out the palette situation */
1257 color_depth = st->codec->bits_per_coded_sample & 0x1F;1258 color_depth = st->codec->bits_per_coded_sample & 0x1F;
1258 color_greyscale = st->codec->bits_per_coded_sample & 0x20;1259 color_greyscale = st->codec->bits_per_coded_sample & 0x20;
@@ -1282,7 +1283,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) · 23 unmodified lines
1282 if (color_index < 0)1283 if (color_index < 0)
1283 color_index = 0;1284 color_index = 0;
1284 }1285 }
1285 } else if (st->codec->color_table_id) {1286 } else if (color_table_id) {
1286 const uint8_t *color_table;1287 const uint8_t *color_table;
1287 /* if flag bit 3 is set, use the default palette */1288 /* if flag bit 3 is set, use the default palette */
1288 color_count = 1 << color_depth;1289 color_count = 1 << color_depth;
libavformat/mp3enc.c+183−74
@@ -84,6 +84,7 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) · 83 unmodified lines
84 84
85typedef struct MP3Context {85typedef struct MP3Context {
86 const AVClass *class;86 const AVClass *class;
87 ID3v2EncContext id3;
87 int id3v2_version;88 int id3v2_version;
88 int write_id3v1;89 int write_id3v1;
89 int64_t frames_offset;90 int64_t frames_offset;
@@ -93,60 +94,15 @@ typedef struct MP3Context { · 3 unmodified lines
93 uint32_t seen;94 uint32_t seen;
94 uint32_t pos;95 uint32_t pos;
95 uint64_t bag[VBR_NUM_BAGS];96 uint64_t bag[VBR_NUM_BAGS];
96} MP3Context;
97
98static int mp2_write_trailer(struct AVFormatContext *s)
99{
100 uint8_t buf[ID3v1_TAG_SIZE];
101 MP3Context *mp3 = s->priv_data;
102
103 /* write the id3v1 tag */
104 if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) {
105 avio_write(s->pb, buf, ID3v1_TAG_SIZE);
106 }
107 97
108 /* write number of frames */98 /* index of the audio stream */
109 if (mp3 && mp3->frames_offset) {99 int audio_stream_idx;
110 avio_seek(s->pb, mp3->frames_offset, SEEK_SET);100 /* number of attached pictures we still need to write */
111 avio_wb32(s->pb, s->streams[0]->nb_frames);101 int pics_to_write;
112 avio_seek(s->pb, 0, SEEK_END);
113 }
114
115 avio_flush(s->pb);
116
117 return 0;
118}
119
120#if CONFIG_MP2_MUXER
121AVOutputFormat ff_mp2_muxer = {
122 .name = "mp2",
123 .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
124 .mime_type = "audio/x-mpeg",
125 .extensions = "mp2,m2a",
126 .audio_codec = CODEC_ID_MP2,
127 .video_codec = CODEC_ID_NONE,
128 .write_packet = ff_raw_write_packet,
129 .write_trailer = mp2_write_trailer,
130 .flags = AVFMT_NOTIMESTAMPS,
131};
132#endif
133
134#if CONFIG_MP3_MUXER
135
136static const AVOption options[] = {
137 { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
138 offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
139 { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
140 offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
141 { NULL },
142};
143 102
144static const AVClass mp3_muxer_class = {103 /* audio packets are queued here until we get all the attached pictures */
145 .class_name = "MP3 muxer",104 AVPacketList *queue, *queue_end;
146 .item_name = av_default_item_name,105} MP3Context;
147 .option = options,
148 .version = LIBAVUTIL_VERSION_INT,
149};
150 106
151static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};107static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
152 108
@@ -155,8 +111,8 @@ static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; · 2 unmodified lines
155 */111 */
156static int mp3_write_xing(AVFormatContext *s)112static int mp3_write_xing(AVFormatContext *s)
157{113{
158 AVCodecContext *codec = s->streams[0]->codec;
159 MP3Context *mp3 = s->priv_data;114 MP3Context *mp3 = s->priv_data;
115 AVCodecContext *codec = s->streams[mp3->audio_stream_idx]->codec;
160 int bitrate_idx;116 int bitrate_idx;
161 int best_bitrate_idx = -1;117 int best_bitrate_idx = -1;
162 int best_bitrate_error= INT_MAX;118 int best_bitrate_error= INT_MAX;
@@ -166,6 +122,9 @@ static int mp3_write_xing(AVFormatContext *s) · 3 unmodified lines
166 int srate_idx, i, channels;122 int srate_idx, i, channels;
167 int needed;123 int needed;
168 124
125 if (!s->pb->seekable)
126 return 0;
127
169 for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++)128 for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++)
170 if (avpriv_mpa_freq_tab[i] == codec->sample_rate) {129 if (avpriv_mpa_freq_tab[i] == codec->sample_rate) {
171 srate_idx = i;130 srate_idx = i;
@@ -295,26 +254,7 @@ static void mp3_fix_xing(AVFormatContext *s) · 123 unmodified lines
295 avio_seek(s->pb, 0, SEEK_END);254 avio_seek(s->pb, 0, SEEK_END);
296}255}
297 256
298/**257static int mp3_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
299 * Write an ID3v2 header at beginning of stream
300 */
301
302static int mp3_write_header(struct AVFormatContext *s)
303{
304 MP3Context *mp3 = s->priv_data;
305 int ret;
306
307 ret = ff_id3v2_write(s, mp3->id3v2_version, ID3v2_DEFAULT_MAGIC);
308 if (ret < 0)
309 return ret;
310
311 if (s->pb->seekable)
312 mp3_write_xing(s);
313
314 return 0;
315}
316
317static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
318{258{
319 if (! pkt || ! pkt->data || pkt->size < 4)259 if (! pkt || ! pkt->data || pkt->size < 4)
320 return ff_raw_write_packet(s, pkt);260 return ff_raw_write_packet(s, pkt);
@@ -350,6 +290,175 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt) · 29 unmodified lines
350 }290 }
351}291}
352 292
293static int mp3_queue_flush(AVFormatContext *s)
294{
295 MP3Context *mp3 = s->priv_data;
296 AVPacketList *pktl;
297 int ret = 0, write = 1;
298
299 ff_id3v2_finish(&mp3->id3, s->pb);
300 mp3_write_xing(s);
301
302 while ((pktl = mp3->queue)) {
303 if (write && (ret = mp3_write_packet_internal(s, &pktl->pkt)) < 0)
304 write = 0;
305 av_free_packet(&pktl->pkt);
306 mp3->queue = pktl->next;
307 av_freep(&pktl);
308 }
309 mp3->queue_end = NULL;
310 return ret;
311}
312
313static int mp2_write_trailer(struct AVFormatContext *s)
314{
315 uint8_t buf[ID3v1_TAG_SIZE];
316 MP3Context *mp3 = s->priv_data;
317
318 if (mp3 && mp3->pics_to_write) {
319 av_log(s, AV_LOG_WARNING, "No packets were sent for some of the "
320 "attached pictures.\n");
321 mp3_queue_flush(s);
322 }
323
324 /* write the id3v1 tag */
325 if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) {
326 avio_write(s->pb, buf, ID3v1_TAG_SIZE);
327 }
328
329 /* write number of frames */
330 if (mp3 && mp3->frames_offset) {
331 avio_seek(s->pb, mp3->frames_offset, SEEK_SET);
332 avio_wb32(s->pb, s->streams[mp3->audio_stream_idx]->nb_frames);
333 avio_seek(s->pb, 0, SEEK_END);
334 }
335
336 avio_flush(s->pb);
337
338 return 0;
339}
340
341#if CONFIG_MP2_MUXER
342AVOutputFormat ff_mp2_muxer = {
343 .name = "mp2",
344 .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
345 .mime_type = "audio/x-mpeg",
346 .extensions = "mp2,m2a",
347 .audio_codec = CODEC_ID_MP2,
348 .video_codec = CODEC_ID_NONE,
349 .write_packet = ff_raw_write_packet,
350 .write_trailer = mp2_write_trailer,
351 .flags = AVFMT_NOTIMESTAMPS,
352};
353#endif
354
355#if CONFIG_MP3_MUXER
356
357static const AVOption options[] = {
358 { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
359 offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
360 { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
361 offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
362 { NULL },
363};
364
365static const AVClass mp3_muxer_class = {
366 .class_name = "MP3 muxer",
367 .item_name = av_default_item_name,
368 .option = options,
369 .version = LIBAVUTIL_VERSION_INT,
370};
371
372static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
373{
374 MP3Context *mp3 = s->priv_data;
375
376 if (pkt->stream_index == mp3->audio_stream_idx) {
377 if (mp3->pics_to_write) {
378 /* buffer audio packets until we get all the pictures */
379 AVPacketList *pktl = av_mallocz(sizeof(*pktl));
380 if (!pktl)
381 return AVERROR(ENOMEM);
382
383 pktl->pkt = *pkt;
384 pkt->destruct = NULL;
385
386 if (mp3->queue_end)
387 mp3->queue_end->next = pktl;
388 else
389 mp3->queue = pktl;
390 mp3->queue_end = pktl;
391 } else
392 return mp3_write_packet_internal(s, pkt);
393 } else {
394 int ret;
395
396 /* warn only once for each stream */
397 if (s->streams[pkt->stream_index]->nb_frames == 1) {
398 av_log(s, AV_LOG_WARNING, "Got more than one picture in stream %d,"
399 " ignoring.\n", pkt->stream_index);
400 }
401 if (!mp3->pics_to_write || s->streams[pkt->stream_index]->nb_frames >= 1)
402 return 0;
403
404 if ((ret = ff_id3v2_write_apic(s, &mp3->id3, pkt)) < 0)
405 return ret;
406 mp3->pics_to_write--;
407
408 /* flush the buffered audio packets */
409 if (!mp3->pics_to_write &&
410 (ret = mp3_queue_flush(s)) < 0)
411 return ret;
412 }
413
414 return 0;
415}
416
417/**
418 * Write an ID3v2 header at beginning of stream
419 */
420
421static int mp3_write_header(struct AVFormatContext *s)
422{
423 MP3Context *mp3 = s->priv_data;
424 int ret, i;
425
426 /* check the streams -- we want exactly one audio and arbitrary number of
427 * video (attached pictures) */
428 mp3->audio_stream_idx = -1;
429 for (i = 0; i < s->nb_streams; i++) {
430 AVStream *st = s->streams[i];
431 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
432 if (mp3->audio_stream_idx >= 0 || st->codec->codec_id != CODEC_ID_MP3) {
433 av_log(s, AV_LOG_ERROR, "Invalid audio stream. Exactly one MP3 "
434 "audio stream is required.\n");
435 return AVERROR(EINVAL);
436 }
437 mp3->audio_stream_idx = i;
438 } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) {
439 av_log(s, AV_LOG_ERROR, "Only audio streams and pictures are allowed in MP3.\n");
440 return AVERROR(EINVAL);
441 }
442 }
443 if (mp3->audio_stream_idx < 0) {
444 av_log(s, AV_LOG_ERROR, "No audio stream present.\n");
445 return AVERROR(EINVAL);
446 }
447 mp3->pics_to_write = s->nb_streams - 1;
448
449 ff_id3v2_start(&mp3->id3, s->pb, mp3->id3v2_version, ID3v2_DEFAULT_MAGIC);
450 ret = ff_id3v2_write_metadata(s, &mp3->id3);
451 if (ret < 0)
452 return ret;
453
454 if (!mp3->pics_to_write) {
455 ff_id3v2_finish(&mp3->id3, s->pb);
456 mp3_write_xing(s);
457 }
458
459 return 0;
460}
461
353static int mp3_write_trailer(AVFormatContext *s)462static int mp3_write_trailer(AVFormatContext *s)
354{463{
355 MP3Context *mp3 = s->priv_data;464 MP3Context *mp3 = s->priv_data;
@@ -371,7 +480,7 @@ AVOutputFormat ff_mp3_muxer = { · 15 unmodified lines
371 .extensions = "mp3",480 .extensions = "mp3",
372 .priv_data_size = sizeof(MP3Context),481 .priv_data_size = sizeof(MP3Context),
373 .audio_codec = CODEC_ID_MP3,482 .audio_codec = CODEC_ID_MP3,
374 .video_codec = CODEC_ID_NONE,483 .video_codec = CODEC_ID_PNG,
375 .write_header = mp3_write_header,484 .write_header = mp3_write_header,
376 .write_packet = mp3_write_packet,485 .write_packet = mp3_write_packet,
377 .write_trailer = mp3_write_trailer,486 .write_trailer = mp3_write_trailer,
libavformat/omadec.c+1−1
@@ -270,7 +270,7 @@ static int oma_read_header(AVFormatContext *s) · 269 unmodified lines
270 ID3v2ExtraMeta *extra_meta = NULL;270 ID3v2ExtraMeta *extra_meta = NULL;
271 OMAContext *oc = s->priv_data;271 OMAContext *oc = s->priv_data;
272 272
273 ff_id3v2_read_all(s, ID3v2_EA3_MAGIC, &extra_meta);273 ff_id3v2_read(s, ID3v2_EA3_MAGIC, &extra_meta);
274 ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);274 ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
275 if (ret < EA3_HEADER_SIZE)275 if (ret < EA3_HEADER_SIZE)
276 return -1;276 return -1;
libavformat/omaenc.c+1−1
@@ -49,7 +49,7 @@ static av_cold int oma_write_header(AVFormatContext *s) · 48 unmodified lines
49 }49 }
50 50
51 /* Metadata; OpenMG does not support ID3v2.4 */51 /* Metadata; OpenMG does not support ID3v2.4 */
52 ff_id3v2_write(s, 3, ID3v2_EA3_MAGIC);52 ff_id3v2_write_simple(s, 3, ID3v2_EA3_MAGIC);
53 53
54 ffio_wfourcc(s->pb, "EA3\0");54 ffio_wfourcc(s->pb, "EA3\0");
55 avio_w8(s->pb, EA3_HEADER_SIZE >> 7);55 avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
libavformat/psxstr.c+1−0
@@ -299,4 +299,5 @@ AVInputFormat ff_str_demuxer = { · 298 unmodified lines
299 .read_header = str_read_header,299 .read_header = str_read_header,
300 .read_packet = str_read_packet,300 .read_packet = str_read_packet,
301 .read_close = str_read_close,301 .read_close = str_read_close,
302 .flags = AVFMT_NO_BYTE_SEEK,
302};303};
libavformat/rtpenc.c+1−1
@@ -112,7 +112,7 @@ static int rtp_write_header(AVFormatContext *s1) · 111 unmodified lines
112 112
113 if (s->max_packet_size) {113 if (s->max_packet_size) {
114 if (s1->pb->max_packet_size)114 if (s1->pb->max_packet_size)
115 s->max_packet_size = FFMIN(s->max_payload_size,115 s->max_packet_size = FFMIN(s->max_packet_size,
116 s1->pb->max_packet_size);116 s1->pb->max_packet_size);
117 } else117 } else
118 s->max_packet_size = s1->pb->max_packet_size;118 s->max_packet_size = s1->pb->max_packet_size;
libavformat/swfdec.c+0−2
@@ -113,7 +113,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) · 112 unmodified lines
113 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;113 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
114 vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, avio_r8(pb));114 vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, avio_r8(pb));
115 avpriv_set_pts_info(vst, 16, 256, swf->frame_rate);115 avpriv_set_pts_info(vst, 16, 256, swf->frame_rate);
116 vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
117 len -= 8;116 len -= 8;
118 } else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) {117 } else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) {
119 /* streaming found */118 /* streaming found */
@@ -186,7 +185,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) · 66 unmodified lines
186 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;185 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
187 vst->codec->codec_id = CODEC_ID_MJPEG;186 vst->codec->codec_id = CODEC_ID_MJPEG;
188 avpriv_set_pts_info(vst, 64, 256, swf->frame_rate);187 avpriv_set_pts_info(vst, 64, 256, swf->frame_rate);
189 vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
190 st = vst;188 st = vst;
191 }189 }
192 avio_rl16(pb); /* BITMAP_ID */190 avio_rl16(pb); /* BITMAP_ID */
libavformat/utils.c+36−19
@@ -545,11 +545,29 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o · 544 unmodified lines
545 return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);545 return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);
546}546}
547 547
548static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
549 AVPacketList **plast_pktl){
550 AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
551 if (!pktl)
552 return NULL;
553
554 if (*packet_buffer)
555 (*plast_pktl)->next = pktl;
556 else
557 *packet_buffer = pktl;
558
559 /* add the packet in the buffered packet list */
560 *plast_pktl = pktl;
561 pktl->pkt= *pkt;
562 return &pktl->pkt;
563}
564
548int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)565int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
549{566{
550 AVFormatContext *s = *ps;567 AVFormatContext *s = *ps;
551 int ret = 0;568 int i, ret = 0;
552 AVDictionary *tmp = NULL;569 AVDictionary *tmp = NULL;
570 ID3v2ExtraMeta *id3v2_extra_meta = NULL;
553 571
554 if (!s && !(s = avformat_alloc_context()))572 if (!s && !(s = avformat_alloc_context()))
555 return AVERROR(ENOMEM);573 return AVERROR(ENOMEM);
@@ -592,12 +610,25 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma · 36 unmodified lines
592 610
593 /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */611 /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */
594 if (s->pb)612 if (s->pb)
595 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);613 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
596 614
597 if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)615 if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)
598 if ((ret = s->iformat->read_header(s)) < 0)616 if ((ret = s->iformat->read_header(s)) < 0)
599 goto fail;617 goto fail;
600 618
619 if (id3v2_extra_meta &&
620 (ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)
621 goto fail;
622 ff_id3v2_free_extra_meta(&id3v2_extra_meta);
623
624 /* queue attached pictures */
625 for (i = 0; i < s->nb_streams; i++)
626 if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) {
627 AVPacket copy = s->streams[i]->attached_pic;
628 copy.destruct = NULL;
629 add_to_pktbuf(&s->raw_packet_buffer, &copy, &s->raw_packet_buffer_end);
630 }
631
601 if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)632 if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)
602 s->data_offset = avio_tell(s->pb);633 s->data_offset = avio_tell(s->pb);
603 634
@@ -611,6 +642,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma · 7 unmodified lines
611 return 0;642 return 0;
612 643
613fail:644fail:
645 ff_id3v2_free_extra_meta(&id3v2_extra_meta);
614 av_dict_free(&tmp);646 av_dict_free(&tmp);
615 if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))647 if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))
616 avio_close(s->pb);648 avio_close(s->pb);
@@ -621,23 +653,6 @@ fail: · 4 unmodified lines
621 653
622/*******************************************************/654/*******************************************************/
623 655
624static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
625 AVPacketList **plast_pktl){
626 AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
627 if (!pktl)
628 return NULL;
629
630 if (*packet_buffer)
631 (*plast_pktl)->next = pktl;
632 else
633 *packet_buffer = pktl;
634
635 /* add the packet in the buffered packet list */
636 *plast_pktl = pktl;
637 pktl->pkt= *pkt;
638 return &pktl->pkt;
639}
640
641int av_read_packet(AVFormatContext *s, AVPacket *pkt)656int av_read_packet(AVFormatContext *s, AVPacket *pkt)
642{657{
643 int ret, i;658 int ret, i;
@@ -2722,6 +2737,8 @@ void avformat_free_context(AVFormatContext *s) · 2078 unmodified lines
2722 av_parser_close(st->parser);2737 av_parser_close(st->parser);
2723 av_free_packet(&st->cur_pkt);2738 av_free_packet(&st->cur_pkt);
2724 }2739 }
2740 if (st->attached_pic.data)
2741 av_free_packet(&st->attached_pic);
2725 av_dict_free(&st->metadata);2742 av_dict_free(&st->metadata);
2726 av_freep(&st->index_entries);2743 av_freep(&st->index_entries);
2727 av_freep(&st->codec->extradata);2744 av_freep(&st->codec->extradata);
libavformat/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "libavutil/avutil.h"30#include "libavutil/avutil.h"
31 31
32#define LIBAVFORMAT_VERSION_MAJOR 5432#define LIBAVFORMAT_VERSION_MAJOR 54
33#define LIBAVFORMAT_VERSION_MINOR 133#define LIBAVFORMAT_VERSION_MINOR 2
34#define LIBAVFORMAT_VERSION_MICRO 10034#define LIBAVFORMAT_VERSION_MICRO 100
35 35
36#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \36#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
libavformat/vqf.c+3−3
@@ -220,12 +220,12 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt) · 219 unmodified lines
220 int ret;220 int ret;
221 int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;221 int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;
222 222
223 pkt->pos = avio_tell(s->pb);
224 pkt->stream_index = 0;
225
226 if (av_new_packet(pkt, size+2) < 0)223 if (av_new_packet(pkt, size+2) < 0)
227 return AVERROR(EIO);224 return AVERROR(EIO);
228 225
226 pkt->pos = avio_tell(s->pb);
227 pkt->stream_index = 0;
228
229 pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip229 pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
230 pkt->data[1] = c->last_frame_bits;230 pkt->data[1] = c->last_frame_bits;
231 ret = avio_read(s->pb, pkt->data+2, size);231 ret = avio_read(s->pb, pkt->data+2, size);
libswscale/utils.c+1−1
@@ -1046,7 +1046,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) · 1045 unmodified lines
1046 c->vLumBufSize= c->vLumFilterSize;1046 c->vLumBufSize= c->vLumFilterSize;
1047 c->vChrBufSize= c->vChrFilterSize;1047 c->vChrBufSize= c->vChrFilterSize;
1048 for (i=0; i<dstH; i++) {1048 for (i=0; i<dstH; i++) {
1049 int chrI= (int64_t)i*c->chrDstH / dstH;1049 int chrI = (int64_t) i * c->chrDstH / dstH;
1050 int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1,1050 int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1,
1051 ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));1051 ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));
1052 1052
tests/codec-regression.sh+3−3
@@ -38,13 +38,13 @@ fi · 37 unmodified lines
38 38
39if [ -n "$do_mpeg2_ivlc_qprd" ]; then39if [ -n "$do_mpeg2_ivlc_qprd" ]; then
40# mpeg2 encoding intra vlc qprd40# mpeg2 encoding intra vlc qprd
41do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -trellis 1 -flags +qprd+mv0 -intra_vlc 1 -cmp 2 -subcmp 2 -mbd rd -vcodec mpeg2video -f mpeg2video"41do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -trellis 1 -flags +mv0 -mpv_flags +qp_rd -intra_vlc 1 -cmp 2 -subcmp 2 -mbd rd -vcodec mpeg2video -f mpeg2video"
42do_video_decoding42do_video_decoding
43fi43fi
44 44
45if [ -n "$do_mpeg2_422" ]; then45if [ -n "$do_mpeg2_422" ]; then
46#mpeg2 4:2:2 encoding46#mpeg2 4:2:2 encoding
47do_video_encoding mpeg2_422.mpg "-vb 1000k -bf 2 -trellis 1 -flags +qprd+mv0+ildct+ilme -intra_vlc 1 -mbd rd -vcodec mpeg2video -pix_fmt yuv422p -f mpeg2video"47do_video_encoding mpeg2_422.mpg "-vb 1000k -bf 2 -trellis 1 -flags +mv0+ildct+ilme -mpv_flags +qp_rd -intra_vlc 1 -mbd rd -vcodec mpeg2video -pix_fmt yuv422p -f mpeg2video"
48do_video_decoding48do_video_decoding
49fi49fi
50 50
@@ -143,7 +143,7 @@ do_video_decoding · 92 unmodified lines
143fi143fi
144 144
145if [ -n "$do_mpeg4_qprd" ]; then145if [ -n "$do_mpeg4_qprd" ]; then
146do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -trellis 1 -flags +mv4+qprd+mv0 -cmp 2 -subcmp 2 -mbd rd -an -vcodec mpeg4"146do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -trellis 1 -flags +mv4+mv0 -mpv_flags +qp_rd -cmp 2 -subcmp 2 -mbd rd -an -vcodec mpeg4"
147do_video_decoding147do_video_decoding
148fi148fi
149 149
tests/fate/cdxl.mak+3−0
@@ -10,5 +10,8 @@ fate-cdxl-pal8: CMD = framecrc -i $(SAMPLES)/cdxl/maku.cdxl -pix_fmt rgb24 -fram · 9 unmodified lines
10FATE_CDXL += fate-cdxl-pal8-small10FATE_CDXL += fate-cdxl-pal8-small
11fate-cdxl-pal8-small: CMD = framecrc -i $(SAMPLES)/cdxl/fruit.cdxl -an -pix_fmt rgb24 -frames:v 4611fate-cdxl-pal8-small: CMD = framecrc -i $(SAMPLES)/cdxl/fruit.cdxl -an -pix_fmt rgb24 -frames:v 46
12 12
13FATE_CDXL += fate-cdxl-bitline-ham6
14fate-cdxl-bitline-ham6: CMD = framecrc -i $(SAMPLES)/cdxl/bitline.cdxl -frames:v 10
15
13FATE_TESTS += $(FATE_CDXL)16FATE_TESTS += $(FATE_CDXL)
14fate-cdxl: $(FATE_CDXL)17fate-cdxl: $(FATE_CDXL)
tests/fate/mp3.mak+5−0
@@ -33,6 +33,11 @@ fate-mp3-float-conf-si_block: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-confo · 32 unmodified lines
33fate-mp3-float-conf-si_block: CMP = stddev33fate-mp3-float-conf-si_block: CMP = stddev
34fate-mp3-float-conf-si_block: REF = $(SAMPLES)/mp3-conformance/si_block.pcm34fate-mp3-float-conf-si_block: REF = $(SAMPLES)/mp3-conformance/si_block.pcm
35 35
36FATE_MP3 += fate-mp3-float-extra_overread
37fate-mp3-float-extra_overread: CMD = pcm -c:a mp3float -i $(SAMPLES)/mpegaudio/extra_overread.mp3
38fate-mp3-float-extra_overread: CMP = stddev
39fate-mp3-float-extra_overread: REF = $(SAMPLES)/mpegaudio/extra_overread.pcm
40
36FATE_TESTS += $(FATE_MP3)41FATE_TESTS += $(FATE_MP3)
37fate-mp3: $(FATE_MP3)42fate-mp3: $(FATE_MP3)
38$(FATE_MP3): CMP = stddev43$(FATE_MP3): CMP = stddev
tests/fate/video.mak+1−1
@@ -143,7 +143,7 @@ FATE_VIDEO += fate-mpeg2-field-enc · 142 unmodified lines
143fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an143fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an
144 144
145FATE_VIDEO += fate-nuv145FATE_VIDEO += fate-nuv
146fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv146fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv -an
147 147
148FATE_VIDEO += fate-qpeg148FATE_VIDEO += fate-qpeg
149fate-qpeg: CMD = framecrc -i $(SAMPLES)/qpeg/Clock.avi -an -pix_fmt rgb24149fate-qpeg: CMD = framecrc -i $(SAMPLES)/qpeg/Clock.avi -an -pix_fmt rgb24
tests/ref/fate/cdxl-bitline-ham6+11−0
@@ -0,0 +1,11 @@
1#tb 0: 12/601
20, 0, 0, 1, 63180, 0xcda82c16
30, 1, 1, 1, 63180, 0xa6097bf9
40, 2, 2, 1, 63180, 0x4c2fb091
50, 3, 3, 1, 63180, 0xc597db00
60, 4, 4, 1, 63180, 0xfa581ccd
70, 5, 5, 1, 63180, 0x3e51498f
80, 6, 6, 1, 63180, 0xe3495396
90, 7, 7, 1, 63180, 0x425f5f02
100, 8, 8, 1, 63180, 0x6077465f
110, 9, 9, 1, 63180, 0x923ba29c
tests/ref/fate/nuv+0−19
@@ -1,29 +1,10 @@
1#tb 0: 100/29971#tb 0: 100/2997
2#tb 1: 1/44100
31, 0, 0, 1024, 4096, 0x00000000
41, 1024, 1024, 1024, 4096, 0x4dfae7a6
51, 2048, 2048, 1024, 4096, 0x3fd9f5c6
61, 3072, 3072, 1024, 4096, 0x7b86e310
71, 4096, 4096, 1024, 4096, 0x611cece5
81, 5120, 5120, 1024, 4096, 0xb7d8e872
90, 4, 4, 1, 460800, 0x54aedafe20, 4, 4, 1, 460800, 0x54aedafe
101, 6144, 6144, 1024, 4096, 0x072ef72b
111, 7168, 7168, 1024, 4096, 0xb3560144
120, 5, 5, 1, 460800, 0xb7aa8b5630, 5, 5, 1, 460800, 0xb7aa8b56
131, 8192, 8192, 1024, 4096, 0x0a3d119e
140, 6, 6, 1, 460800, 0x283ea3b540, 6, 6, 1, 460800, 0x283ea3b5
151, 9216, 9216, 1024, 4096, 0xbe391aa4
161, 10240, 10240, 1024, 4096, 0x28f7c6e5
170, 7, 7, 1, 460800, 0x283ea3b550, 7, 7, 1, 460800, 0x283ea3b5
181, 11264, 11264, 1024, 4096, 0xca9d9df2
190, 8, 8, 1, 460800, 0x10e577de60, 8, 8, 1, 460800, 0x10e577de
201, 12288, 12288, 1024, 4096, 0x5c6b95a9
210, 9, 9, 1, 460800, 0x4e091ee270, 9, 9, 1, 460800, 0x4e091ee2
221, 13312, 13312, 1024, 4096, 0x0bdfc0bf
231, 14336, 14336, 1024, 4096, 0xd95a9277
240, 10, 10, 1, 460800, 0x2ea8882880, 10, 10, 1, 460800, 0x2ea88828
251, 15360, 15360, 1024, 4096, 0xae2bef2c
260, 11, 11, 1, 460800, 0x4b7f4df090, 11, 11, 1, 460800, 0x4b7f4df0
271, 16384, 16384, 1024, 4096, 0xbf031e83
281, 17408, 17408, 1024, 4096, 0x4c83e2d1
290, 12, 12, 1, 460800, 0xa57f20d0100, 12, 12, 1, 460800, 0xa57f20d0
tests/ref/lavf/ffm+1−1
@@ -1,3 +1,3 @@
14ef091d638bb20b8eaef5b3a0d6f97b7 *./tests/data/lavf/lavf.ffm18ce2ea9a73a1187647df7bf3c8e1b8fd *./tests/data/lavf/lavf.ffm
2376832 ./tests/data/lavf/lavf.ffm2376832 ./tests/data/lavf/lavf.ffm
3./tests/data/lavf/lavf.ffm CRC=0xf361ed743./tests/data/lavf/lavf.ffm CRC=0xf361ed74
tests/ref/vsynth1/prores_kostya+1−1
@@ -1,4 +1,4 @@
140e7637e04991dbe9a23fe109f95bfc8 *./tests/data/vsynth1/prores_kostya.mov1f8fe98b7f9bb66857c81dbca409a9037 *./tests/data/vsynth1/prores_kostya.mov
23858901 ./tests/data/vsynth1/prores_kostya.mov23858901 ./tests/data/vsynth1/prores_kostya.mov
30a4153637d0cc0a88a8bcbf04cfaf8c6 *./tests/data/prores_kostya.vsynth1.out.yuv30a4153637d0cc0a88a8bcbf04cfaf8c6 *./tests/data/prores_kostya.vsynth1.out.yuv
4stddev: 3.17 PSNR: 38.09 MAXDIFF: 39 bytes: 7603200/ 76032004stddev: 3.17 PSNR: 38.09 MAXDIFF: 39 bytes: 7603200/ 7603200
tests/ref/vsynth2/prores_kostya+1−1
@@ -1,4 +1,4 @@
1ed8b8a94da049518af8f95c5da736e57 *./tests/data/vsynth2/prores_kostya.mov126adb18726c08dde23bc4bee2eb591e2 *./tests/data/vsynth2/prores_kostya.mov
23884586 ./tests/data/vsynth2/prores_kostya.mov23884586 ./tests/data/vsynth2/prores_kostya.mov
3ca2f6c1162635dedfa468c90f1fdc0ef *./tests/data/prores_kostya.vsynth2.out.yuv3ca2f6c1162635dedfa468c90f1fdc0ef *./tests/data/prores_kostya.vsynth2.out.yuv
4stddev: 0.92 PSNR: 48.77 MAXDIFF: 10 bytes: 7603200/ 76032004stddev: 0.92 PSNR: 48.77 MAXDIFF: 10 bytes: 7603200/ 7603200

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t