3 #include <netinet/in.h>
4 #include <linux/videodev.h>
5 #include <linux/soundcard.h>
17 AVFormat *first_format;
18 /* XXX: suppress it ! */
21 const char *comment_string =
22 "+title=Test Video +author=FFMpeg +copyright=Free +comment=Generated by FFMpeg 1.0";
24 void register_avformat(AVFormat *format)
28 while (*p != NULL) p = &(*p)->next;
33 AVFormat *guess_format(const char *short_name, const char *filename, const char *mime_type)
35 AVFormat *fmt, *fmt_found;
40 /* find the proper file type */
46 if (fmt->name && short_name && !strcmp(fmt->name, short_name))
48 if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))
50 if (filename && fmt->extensions) {
51 ext = strrchr(filename, '.');
57 while (*p != '\0' && *p != ',')
60 if (!strcasecmp(ext1, ext)) {
70 if (score > score_max) {
79 /* return TRUE if val is a prefix of str. If it returns TRUE, ptr is
80 set to the next character in 'str' after the prefix */
81 int strstart(const char *str, const char *val, const char **ptr)
98 int raw_write_header(struct AVFormatContext *s)
103 int raw_write_audio(struct AVFormatContext *s,
104 unsigned char *buf, int size)
106 put_buffer(&s->pb, buf, size);
107 put_flush_packet(&s->pb);
111 int raw_write_video(struct AVFormatContext *s,
112 unsigned char *buf, int size)
114 put_buffer(&s->pb, buf, size);
115 put_flush_packet(&s->pb);
119 int raw_write_trailer(struct AVFormatContext *s)
124 AVFormat mp2_format = {
126 "MPEG audio layer 2",
137 AVFormat ac3_format = {
150 AVFormat h263_format = {
163 AVFormat mpeg1video_format = {
176 /* encoder management */
177 AVEncoder *first_encoder;
179 void register_avencoder(AVEncoder *format)
183 while (*p != NULL) p = &(*p)->next;
188 int avencoder_open(AVEncodeContext *avctx, AVEncoder *codec)
192 avctx->codec = codec;
193 avctx->frame_number = 0;
194 avctx->priv_data = malloc(codec->priv_data_size);
195 if (!avctx->priv_data)
197 memset(avctx->priv_data, 0, codec->priv_data_size);
198 ret = avctx->codec->init(avctx);
200 free(avctx->priv_data);
201 avctx->priv_data = NULL;
207 int avencoder_encode(AVEncodeContext *avctx, UINT8 *buf, int buf_size, void *data)
211 ret = avctx->codec->encode(avctx, buf, buf_size, data);
212 avctx->frame_number++;
216 int avencoder_close(AVEncodeContext *avctx)
218 if (avctx->codec->close)
219 avctx->codec->close(avctx);
220 free(avctx->priv_data);
221 avctx->priv_data = NULL;
225 AVEncoder *avencoder_find(enum CodecID id)
238 void avencoder_string(char *buf, int buf_size, AVEncodeContext *enc)
240 switch(enc->codec->type) {
241 case CODEC_TYPE_VIDEO:
242 snprintf(buf, buf_size,
243 "Video: %s, %dx%d, %d fps, %d kb/s",
244 enc->codec->name, enc->width, enc->height, enc->rate, enc->bit_rate / 1000);
246 case CODEC_TYPE_AUDIO:
247 snprintf(buf, buf_size,
248 "Audio: %s, %d Hz, %s, %d kb/s",
249 enc->codec->name, enc->rate,
250 enc->channels == 2 ? "stereo" : "mono",
251 enc->bit_rate / 1000);
260 int init_put_byte(PutByteContext *s,
261 unsigned char *buffer,
264 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
265 int (*write_seek)(void *opaque, long long offset, int whence))
269 s->buf_end = buffer + buffer_size;
271 s->write_packet = write_packet;
272 s->write_seek = write_seek;
278 static void flush_buffer(PutByteContext *s)
280 if (s->buf_ptr > s->buffer) {
282 s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
283 s->pos += s->buf_ptr - s->buffer;
285 s->buf_ptr = s->buffer;
288 void put_byte(PutByteContext *s, int b)
291 if (s->buf_ptr >= s->buf_end)
295 void put_buffer(PutByteContext *s, unsigned char *buf, int size)
300 len = (s->buf_end - s->buf_ptr);
303 memcpy(s->buf_ptr, buf, len);
306 if (s->buf_ptr >= s->buf_end)
314 void put_flush_packet(PutByteContext *s)
319 /* XXX: this seek is not correct if we go after the end of the written data */
320 long long put_seek(PutByteContext *s, long long offset, int whence)
324 if (whence != SEEK_CUR && whence != SEEK_SET)
326 if (whence == SEEK_CUR)
327 offset += s->pos + s->buf_ptr - s->buffer;
329 offset1 = offset - s->pos;
330 if (offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
331 /* can do the seek inside the buffer */
332 s->buf_ptr = s->buffer + offset1;
337 s->write_seek(s->opaque, offset, whence);
342 long long put_pos(PutByteContext *s)
344 return put_seek(s, 0, SEEK_CUR);
347 void put_le32(PutByteContext *s, unsigned int val)
350 put_byte(s, val >> 8);
351 put_byte(s, val >> 16);
352 put_byte(s, val >> 24);
355 void put_le64(PutByteContext *s, unsigned long long val)
357 put_le32(s, val & 0xffffffff);
358 put_le32(s, val >> 32);
361 void put_le16(PutByteContext *s, unsigned int val)
364 put_byte(s, val >> 8);
367 void put_tag(PutByteContext *s, char *tag)