annotate img.c @ 1491:89f88d324eea libavformat

rename cropTbl -> ff_cropTbl
author mru
date Sun, 12 Nov 2006 20:08:09 +0000
parents 0899bfe4105c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Image format
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1291
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1291
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1291
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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: 1291
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1291
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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: 1291
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
11
932b59c66c60 mingw patch by (Bill Eldridge <bill at rfa dot org>)
michaelni
parents: 10
diff changeset
22
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 int width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 int height;
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
26 int img_first;
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
27 int img_last;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 int img_number;
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
29 int img_count;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 int img_size;
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
31 AVImageFormat *img_fmt;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
32 int pix_fmt;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 int is_pipe;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 char path[1024];
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
35 /* temporary usage */
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
36 void *ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 } VideoData;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
39
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
40 /* return -1 if no image found */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
41 static int find_image_range(int *pfirst_index, int *plast_index,
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
42 const char *path)
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
43 {
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
44 char buf[1024];
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
45 int range, last_index, range1, first_index;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
46
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
47 /* find the first image */
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
48 for(first_index = 0; first_index < 5; first_index++) {
1291
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
49 if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0)
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
50 goto fail;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
51 if (url_exist(buf))
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
52 break;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
53 }
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
54 if (first_index == 5)
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
55 goto fail;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
56
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
57 /* find the last image */
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
58 last_index = first_index;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
59 for(;;) {
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
60 range = 0;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
61 for(;;) {
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
62 if (!range)
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
63 range1 = 1;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
64 else
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
65 range1 = 2 * range;
1291
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
66 if (av_get_frame_filename(buf, sizeof(buf), path,
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
67 last_index + range1) < 0)
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
68 goto fail;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
69 if (!url_exist(buf))
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
70 break;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
71 range = range1;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
72 /* just in case... */
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
73 if (range >= (1 << 30))
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
74 goto fail;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
75 }
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
76 /* we are sure than image last_index + range exists */
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
77 if (!range)
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
78 break;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
79 last_index += range;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
80 }
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
81 *pfirst_index = first_index;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
82 *plast_index = last_index;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
83 return 0;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
84 fail:
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
85 return -1;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
86 }
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
87
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
88
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
89 static int image_probe(AVProbeData *p)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 {
1291
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
91 if (av_filename_number_test(p->filename) && guess_image_format(p->filename))
582
c5ff083848b4 prefer image2 over image
michael
parents: 482
diff changeset
92 return AVPROBE_SCORE_MAX-1;
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
93 else
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
94 return 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
97 static int read_header_alloc_cb(void *opaque, AVImageInfo *info)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
99 VideoData *s = opaque;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
100
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
101 s->width = info->width;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
102 s->height = info->height;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
103 s->pix_fmt = info->pix_fmt;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
104 /* stop image reading but no error */
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
105 return 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
108 static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
110 VideoData *s = s1->priv_data;
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
111 int ret, first_index, last_index;
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
112 char buf[1024];
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
113 ByteIOContext pb1, *f = &pb1;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
114 AVStream *st;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
115
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
116 st = av_new_stream(s1, 0);
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
117 if (!st) {
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
118 return -ENOMEM;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
119 }
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
120
1003
2d57ce58f576 simplify AVFormatParameters NULL checks
michael
parents: 896
diff changeset
121 if (ap->image_format)
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
122 s->img_fmt = ap->image_format;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
123
639
0b52743104ac integer overflows, heap corruption
michael
parents: 582
diff changeset
124 pstrcpy(s->path, sizeof(s->path), s1->filename);
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
125 s->img_number = 0;
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
126 s->img_count = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
127
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
128 /* find format */
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
129 if (s1->iformat->flags & AVFMT_NOFILE)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
130 s->is_pipe = 0;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
131 else
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
132 s->is_pipe = 1;
743
af4e24d6310c switch to native time bases
michael
parents: 639
diff changeset
133
1003
2d57ce58f576 simplify AVFormatParameters NULL checks
michael
parents: 896
diff changeset
134 if (!ap->time_base.num) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
135 st->codec->time_base= (AVRational){1,25};
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
136 } else {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
137 st->codec->time_base= ap->time_base;
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
138 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
139
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
140 if (!s->is_pipe) {
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
141 if (find_image_range(&first_index, &last_index, s->path) < 0)
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
142 goto fail;
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
143 s->img_first = first_index;
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
144 s->img_last = last_index;
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
145 s->img_number = first_index;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
146 /* compute duration */
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
147 st->start_time = 0;
743
af4e24d6310c switch to native time bases
michael
parents: 639
diff changeset
148 st->duration = last_index - first_index + 1;
1291
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
149 if (av_get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
189
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
150 goto fail;
e3cfb9131dfa update duration and start_time
bellard
parents: 88
diff changeset
151 if (url_fopen(f, buf, URL_RDONLY) < 0)
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
152 goto fail;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
153 } else {
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
154 f = &s1->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
156
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
157 ret = av_read_image(f, s1->filename, s->img_fmt, read_header_alloc_cb, s);
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
158 if (ret < 0)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
159 goto fail1;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
160
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
161 if (!s->is_pipe) {
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
162 url_fclose(f);
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
163 } else {
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
164 url_fseek(f, 0, SEEK_SET);
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
165 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
166
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
167 st->codec->codec_type = CODEC_TYPE_VIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
168 st->codec->codec_id = CODEC_ID_RAWVIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
169 st->codec->width = s->width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
170 st->codec->height = s->height;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
171 st->codec->pix_fmt = s->pix_fmt;
459
ce1a3e82328b segfault fix
michael
parents: 439
diff changeset
172 s->img_size = avpicture_get_size(s->pix_fmt, (s->width+15)&(~15), (s->height+15)&(~15));
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
173
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 return 0;
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
175 fail1:
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
176 if (!s->is_pipe)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
177 url_fclose(f);
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
178 fail:
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
179 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
182 static int read_packet_alloc_cb(void *opaque, AVImageInfo *info)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
184 VideoData *s = opaque;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
186 if (info->width != s->width ||
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
187 info->height != s->height)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
188 return -1;
459
ce1a3e82328b segfault fix
michael
parents: 439
diff changeset
189 avpicture_fill(&info->pict, s->ptr, info->pix_fmt, (info->width+15)&(~15), (info->height+15)&(~15));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 VideoData *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 char filename[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 ByteIOContext f1, *f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 if (!s->is_pipe) {
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
201 /* loop over input */
1175
8b53c0f3e7ad add loop_input to AVFormatContext, getting rid of old hack
mru
parents: 1169
diff changeset
202 if (s1->loop_input && s->img_number > s->img_last) {
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
203 s->img_number = s->img_first;
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
204 }
1291
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
205 if (av_get_frame_filename(filename, sizeof(filename),
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
206 s->path, s->img_number) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
207 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 f = &f1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 if (url_fopen(f, filename, URL_RDONLY) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
210 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 f = &s1->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 if (url_feof(f))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
214 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 av_new_packet(pkt, s->img_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 pkt->stream_index = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
220 s->ptr = pkt->data;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
221 ret = av_read_image(f, filename, s->img_fmt, read_packet_alloc_cb, s);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 if (!s->is_pipe) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 url_fclose(f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 av_free_packet(pkt);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
228 return AVERROR_IO; /* signal EOF */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 } else {
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
230 /* XXX: computing this pts is not necessary as it is done in
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
231 the generic code too */
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
232 pkt->pts = av_rescale((int64_t)s->img_count * s1->streams[0]->codec->time_base.num, s1->streams[0]->time_base.den, s1->streams[0]->codec->time_base.den) / s1->streams[0]->time_base.num;
199
66a05c4f8350 suppressed frame number modulus hack - added loop_input hack which I find easier to understand
bellard
parents: 189
diff changeset
233 s->img_count++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 s->img_number++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 static int img_read_close(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 /******************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 /* image output */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
247 static int img_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
249 VideoData *img = s->priv_data;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
250 AVStream *st;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
251 AVImageFormat *img_fmt;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
254 /* find output image format */
1003
2d57ce58f576 simplify AVFormatParameters NULL checks
michael
parents: 896
diff changeset
255 if (ap->image_format) {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
256 img_fmt = ap->image_format;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
257 } else {
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
258 img_fmt = guess_image_format(s->filename);
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
259 }
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
260 if (!img_fmt)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
261 return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
263 if (s->nb_streams != 1)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
264 return -1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
265
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
266 st = s->streams[0];
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
267 /* we select the first matching format */
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
268 for(i=0;i<PIX_FMT_NB;i++) {
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
269 if (img_fmt->supported_pixel_formats & (1 << i))
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
270 break;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 }
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
272 if (i >= PIX_FMT_NB)
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
273 return -1;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
274 img->img_fmt = img_fmt;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
275 img->pix_fmt = i;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
276 st->codec->pix_fmt = img->pix_fmt;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 static int img_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 VideoData *img = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 img->img_number = 1;
639
0b52743104ac integer overflows, heap corruption
michael
parents: 582
diff changeset
285 pstrcpy(img->path, sizeof(img->path), s->filename);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 /* find format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 if (s->oformat->flags & AVFMT_NOFILE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 img->is_pipe = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 img->is_pipe = 1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
292
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
296 static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 VideoData *img = s->priv_data;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
299 AVStream *st = s->streams[pkt->stream_index];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 ByteIOContext pb1, *pb;
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
301 AVPicture *picture;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
302 int width, height, ret;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 char filename[1024];
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
304 AVImageInfo info;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
306 width = st->codec->width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
307 height = st->codec->height;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
308
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
309 picture = (AVPicture *)pkt->data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
311 if (!img->is_pipe) {
1291
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
312 if (av_get_frame_filename(filename, sizeof(filename),
185190bdc185 Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents: 1175
diff changeset
313 img->path, img->img_number) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
314 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 pb = &pb1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 if (url_fopen(pb, filename, URL_WRONLY) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
317 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 }
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
321 info.width = width;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
322 info.height = height;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
323 info.pix_fmt = st->codec->pix_fmt;
280
75e061728d92 recommit of
michael
parents: 241
diff changeset
324 info.interleaved = 0; /* FIXME: there should be a way to set it right */
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
325 info.pict = *picture;
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
326 ret = av_write_image(pb, img->img_fmt, &info);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 if (!img->is_pipe) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 url_fclose(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 img->img_number++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 static int img_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
340 /* input */
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
341 #ifdef CONFIG_IMAGE_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
342 AVInputFormat image_demuxer = {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
343 "image",
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
344 "image sequence",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 sizeof(VideoData),
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
346 image_probe,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 img_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 img_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 img_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 NULL,
439
michael
parents: 280
diff changeset
351 NULL,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 AVFMT_NOFILE | AVFMT_NEEDNUMBER,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
354 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
355 #ifdef CONFIG_IMAGEPIPE_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
356 AVInputFormat imagepipe_demuxer = {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
357 "imagepipe",
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
358 "piped image sequence",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 sizeof(VideoData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 NULL, /* no probe */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 img_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 img_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 img_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
366 #endif
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
367
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
368 /* output */
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
369 #ifdef CONFIG_IMAGE_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
370 AVOutputFormat image_muxer = {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
371 "image",
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
372 "image sequence",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 "",
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
374 "",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 sizeof(VideoData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 CODEC_ID_NONE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 CODEC_ID_RAWVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 img_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 img_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 img_write_trailer,
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
381 AVFMT_NOFILE | AVFMT_NEEDNUMBER | AVFMT_RAWPICTURE,
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
382 img_set_parameters,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
384 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
385 #ifdef CONFIG_IMAGEPIPE_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
386 AVOutputFormat imagepipe_muxer = {
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
387 "imagepipe",
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
388 "piped image sequence",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 "",
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
390 "",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 sizeof(VideoData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 CODEC_ID_NONE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 CODEC_ID_RAWVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 img_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 img_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 img_write_trailer,
21
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
397 AVFMT_RAWPICTURE,
20
3d52de18ecc3 added still image support
bellard
parents: 12
diff changeset
398 img_set_parameters,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
400 #endif