Mercurial > libavformat.hg
annotate jpeg.c @ 1534:4bf9dc98e127 libavformat
add support for tta in matroska
author | aurel |
---|---|
date | Mon, 20 Nov 2006 20:16:32 +0000 |
parents | 0899bfe4105c |
children |
rev | line source |
---|---|
0 | 1 /* |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
2 * JPEG image format |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
3 * Copyright (c) 2003 Fabrice Bellard. |
0 | 4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
21 #include "avformat.h" | |
22 | |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
23 static int jpeg_probe(AVProbeData *pd) |
0 | 24 { |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
25 if (pd->buf_size >= 64 && |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
26 pd->buf[0] == 0xff && pd->buf[1] == 0xd8 && pd->buf[2] == 0xff) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
27 return AVPROBE_SCORE_MAX; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
28 else |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
29 return 0; |
0 | 30 } |
31 | |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
32 typedef struct JpegOpaque { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
33 int (*alloc_cb)(void *opaque, AVImageInfo *info); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
34 void *opaque; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
35 int ret_code; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
36 } JpegOpaque; |
0 | 37 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
38 /* called by the codec to allocate the image */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
39 static int jpeg_get_buffer(AVCodecContext *c, AVFrame *picture) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
40 { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
41 JpegOpaque *jctx = c->opaque; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
42 AVImageInfo info1, *info = &info1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
43 int ret, i; |
0 | 44 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
45 info->width = c->width; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
46 info->height = c->height; |
114 | 47 switch(c->pix_fmt) { |
48 case PIX_FMT_YUV420P: | |
49 info->pix_fmt = PIX_FMT_YUVJ420P; | |
50 break; | |
51 case PIX_FMT_YUV422P: | |
52 info->pix_fmt = PIX_FMT_YUVJ422P; | |
53 break; | |
54 case PIX_FMT_YUV444P: | |
55 info->pix_fmt = PIX_FMT_YUVJ444P; | |
56 break; | |
57 default: | |
58 return -1; | |
59 } | |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
60 ret = jctx->alloc_cb(jctx->opaque, info); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
61 if (ret) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
62 jctx->ret_code = ret; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
63 return -1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
64 } else { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
65 for(i=0;i<3;i++) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
66 picture->data[i] = info->pict.data[i]; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
67 picture->linesize[i] = info->pict.linesize[i]; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
68 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
69 return 0; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
70 } |
0 | 71 } |
72 | |
885 | 73 static void jpeg_img_copy(uint8_t *dst, int dst_wrap, |
65 | 74 uint8_t *src, int src_wrap, |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
75 int width, int height) |
0 | 76 { |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
77 for(;height > 0; height--) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
78 memcpy(dst, src, width); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
79 dst += dst_wrap; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
80 src += src_wrap; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
81 } |
0 | 82 } |
83 | |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
84 /* XXX: libavcodec is broken for truncated jpegs! */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
85 #define IO_BUF_SIZE (1024*1024) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
86 |
885 | 87 static int jpeg_read(ByteIOContext *f, |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
88 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque) |
0 | 89 { |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
90 AVCodecContext *c; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
91 AVFrame *picture, picture1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
92 int len, size, got_picture, i; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
93 uint8_t *inbuf_ptr, inbuf[IO_BUF_SIZE]; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
94 JpegOpaque jctx; |
0 | 95 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
96 jctx.alloc_cb = alloc_cb; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
97 jctx.opaque = opaque; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
98 jctx.ret_code = -1; /* default return code is error */ |
885 | 99 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
100 c = avcodec_alloc_context(); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
101 if (!c) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
102 return -1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
103 picture= avcodec_alloc_frame(); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
104 if (!picture) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
105 av_free(c); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
106 return -1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
107 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
108 c->opaque = &jctx; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
109 c->get_buffer = jpeg_get_buffer; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
110 c->flags |= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
111 if (avcodec_open(c, &mjpeg_decoder) < 0) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
112 goto fail1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
113 for(;;) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
114 size = get_buffer(f, inbuf, sizeof(inbuf)); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
115 if (size == 0) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
116 break; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
117 inbuf_ptr = inbuf; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
118 while (size > 0) { |
885 | 119 len = avcodec_decode_video(c, &picture1, &got_picture, |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
120 inbuf_ptr, size); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
121 if (len < 0) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
122 goto fail; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
123 if (got_picture) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
124 goto the_end; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
125 size -= len; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
126 inbuf_ptr += len; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
127 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
128 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
129 the_end: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
130 /* XXX: currently, the mjpeg decoder does not use AVFrame, so we |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
131 must do it by hand */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
132 if (jpeg_get_buffer(c, picture) < 0) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
133 goto fail; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
134 for(i=0;i<3;i++) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
135 int w, h; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
136 w = c->width; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
137 h = c->height; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
138 if (i >= 1) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
139 switch(c->pix_fmt) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
140 default: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
141 case PIX_FMT_YUV420P: |
48 | 142 w = (w + 1) >> 1; |
143 h = (h + 1) >> 1; | |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
144 break; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
145 case PIX_FMT_YUV422P: |
48 | 146 w = (w + 1) >> 1; |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
147 break; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
148 case PIX_FMT_YUV444P: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
149 break; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
150 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
151 } |
321 | 152 jpeg_img_copy(picture->data[i], picture->linesize[i], |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
153 picture1.data[i], picture1.linesize[i], |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
154 w, h); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
155 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
156 jctx.ret_code = 0; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
157 fail: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
158 avcodec_close(c); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
159 fail1: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
160 av_free(picture); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
161 av_free(c); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
162 return jctx.ret_code; |
0 | 163 } |
164 | |
1169 | 165 #if defined(CONFIG_MUXERS) && defined(CONFIG_MJPEG_ENCODER) |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
166 static int jpeg_write(ByteIOContext *pb, AVImageInfo *info) |
0 | 167 { |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
168 AVCodecContext *c; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
169 uint8_t *outbuf = NULL; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
170 int outbuf_size, ret, size, i; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
171 AVFrame *picture; |
5 | 172 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
173 ret = -1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
174 c = avcodec_alloc_context(); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
175 if (!c) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
176 return -1; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
177 picture = avcodec_alloc_frame(); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
178 if (!picture) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
179 goto fail2; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
180 c->width = info->width; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
181 c->height = info->height; |
114 | 182 /* XXX: currently move that to the codec ? */ |
183 switch(info->pix_fmt) { | |
184 case PIX_FMT_YUVJ420P: | |
185 c->pix_fmt = PIX_FMT_YUV420P; | |
186 break; | |
187 case PIX_FMT_YUVJ422P: | |
188 c->pix_fmt = PIX_FMT_YUV422P; | |
189 break; | |
190 case PIX_FMT_YUVJ444P: | |
191 c->pix_fmt = PIX_FMT_YUV444P; | |
192 break; | |
193 default: | |
194 goto fail1; | |
195 } | |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
196 for(i=0;i<3;i++) { |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
197 picture->data[i] = info->pict.data[i]; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
198 picture->linesize[i] = info->pict.linesize[i]; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
199 } |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
200 /* set the quality */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
201 picture->quality = 3; /* XXX: a parameter should be used */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
202 c->flags |= CODEC_FLAG_QSCALE; |
885 | 203 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
204 if (avcodec_open(c, &mjpeg_encoder) < 0) |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
205 goto fail1; |
885 | 206 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
207 /* XXX: needs to sort out that size problem */ |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
208 outbuf_size = 1000000; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
209 outbuf = av_malloc(outbuf_size); |
0 | 210 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
211 size = avcodec_encode_video(c, outbuf, outbuf_size, picture); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
212 if (size < 0) |
0 | 213 goto fail; |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
214 put_buffer(pb, outbuf, size); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
215 put_flush_packet(pb); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
216 ret = 0; |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
217 |
0 | 218 fail: |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
219 avcodec_close(c); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
220 av_free(outbuf); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
221 fail1: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
222 av_free(picture); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
223 fail2: |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
224 av_free(c); |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
225 return ret; |
0 | 226 } |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
321
diff
changeset
|
227 #endif //CONFIG_MUXERS |
0 | 228 |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
229 AVImageFormat jpeg_image_format = { |
0 | 230 "jpeg", |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
231 "jpg,jpeg", |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
232 jpeg_probe, |
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
233 jpeg_read, |
114 | 234 (1 << PIX_FMT_YUVJ420P) | (1 << PIX_FMT_YUVJ422P) | (1 << PIX_FMT_YUVJ444P), |
1169 | 235 #if defined(CONFIG_MUXERS) && defined(CONFIG_MJPEG_ENCODER) |
47
45308962220f
added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
5
diff
changeset
|
236 jpeg_write, |
215
99f4032097e0
Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents:
114
diff
changeset
|
237 #else |
99f4032097e0
Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents:
114
diff
changeset
|
238 NULL, |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
321
diff
changeset
|
239 #endif //CONFIG_MUXERS |
0 | 240 }; |