FFmpeg
Loading...
Searching...
No Matches
flvdec.c
Go to the documentation of this file.
1/*
2 * FLV decoding.
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/imgutils.h"
22
23#include "codec_internal.h"
24#include "flvdec.h"
25#include "h263dec.h"
26#include "mpegvideo.h"
27#include "mpegvideodec.h"
28
30{
31 int format, width, height;
32
33 /* picture header */
34 if (get_bits(&h->gb, 17) != 1) {
35 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
37 }
38 format = get_bits(&h->gb, 5);
39 if (format != 0 && format != 1) {
40 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
42 }
43 h->flv = format;
44 h->picture_number = get_bits(&h->gb, 8); /* picture timestamp */
45 format = get_bits(&h->gb, 3);
46 switch (format) {
47 case 0:
48 width = get_bits(&h->gb, 8);
49 height = get_bits(&h->gb, 8);
50 break;
51 case 1:
52 width = get_bits(&h->gb, 16);
53 height = get_bits(&h->gb, 16);
54 break;
55 case 2:
56 width = 352;
57 height = 288;
58 break;
59 case 3:
60 width = 176;
61 height = 144;
62 break;
63 case 4:
64 width = 128;
65 height = 96;
66 break;
67 case 5:
68 width = 320;
69 height = 240;
70 break;
71 case 6:
72 width = 160;
73 height = 120;
74 break;
75 default:
76 width = height = 0;
77 break;
78 }
79 if (av_image_check_size(width, height, 0, h->c.avctx))
80 return AVERROR(EINVAL);
81 h->c.width = width;
82 h->c.height = height;
83
84 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->gb, 2);
85 h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;
86 if (h->c.droppable)
87 h->c.pict_type = AV_PICTURE_TYPE_P;
88
89 skip_bits1(&h->gb); /* deblocking flag */
90 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
91
92 h->h263_long_vectors = 0;
93
94 /* PEI */
95 if (skip_1stop_8data_bits(&h->gb) < 0)
97
98 if (h->ehc_mode)
99 h->c.avctx->sample_aspect_ratio= (AVRational){1,2};
100
101 if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
102 av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
103 h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type),
104 h->flv, h->c.qscale, h->picture_number);
105 }
106
107 return 0;
108}
109
111 .p.name = "flv",
112 CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
113 .p.type = AVMEDIA_TYPE_VIDEO,
114 .p.id = AV_CODEC_ID_FLV1,
115 .priv_data_size = sizeof(H263DecContext),
118 .close = ff_mpv_decode_close,
120 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
122 .p.max_lowres = 3,
123};
static const char *const format[]
Definition af_aiir.c:444
const FFCodec ff_flv_decoder
Definition flvdec.c:110
#define FF_DEBUG_PICT_INFO
Definition avcodec.h:1393
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition get_bits.h:693
static void skip_bits1(GetBitContext *s)
Definition get_bits.h:416
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition codec.h:41
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_FLV1
Definition codec_id.h:71
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition imgutils.c:318
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition utils.c:40
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
misc image utilities
int ff_flv_decode_picture_header(H263DecContext *const h)
Definition flvdec.c:29
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition h263dec.c:94
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition h263dec.c:443
mpegvideo header.
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
mpegvideo decoder header.
Rational number (pair of numerator and denominator).
Definition rational.h:58
#define av_log(a,...)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89