annotate libmpdemux/muxer_lavf.c @ 15478:868fa16142df

ftp is handled by the modular stream manager
author nicodvb
date Sun, 15 May 2005 08:47:55 +0000
parents 5ca3a981d62a
children 41fd530bd7a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
1 #include <stdio.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
2 #include <stdlib.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
3 #include <string.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
4 #include <sys/types.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
5 #include <inttypes.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
6 #include "config.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
7 #include "../version.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
8 #include "../mp_msg.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
9
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
10 #include "bswap.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
11 #include "aviheader.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
12 #include "ms_hdr.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
13
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
14 #include "muxer.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
15 #include "stream.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
16 #include "demuxer.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
17 #include "stheader.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
18 #include "../m_option.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
19 #include "avformat.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
20
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
21 extern unsigned int codec_get_wav_tag(int id);
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
22 extern enum CodecID codec_get_bmp_id(unsigned int tag);
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
23 extern enum CodecID codec_get_wav_id(unsigned int tag);
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
24
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
25 typedef struct {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
26 //AVInputFormat *avif;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
27 AVFormatContext *oc;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
28 ByteIOContext pb;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
29 int audio_streams;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
30 int video_streams;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
31 int64_t last_pts;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
32 } muxer_priv_t;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
33
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
34 typedef struct {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
35 int64_t last_pts;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
36 AVStream *avstream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
37 } muxer_stream_priv_t;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
38
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
39 static char *conf_format = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
40
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
41 m_option_t lavfopts_conf[] = {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
42 {"format", &(conf_format), CONF_TYPE_STRING, 0, 0, 0, NULL},
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
43 {NULL, NULL, 0, 0, 0, 0, NULL}
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
44 };
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
45
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
46 static int mp_open(URLContext *h, const char *filename, int flags)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
47 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
48 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
49 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
50
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
51 static int mp_close(URLContext *h)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
52 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
53 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
54 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
55
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
56
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
57 static int mp_read(URLContext *h, unsigned char *buf, int size)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
58 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
59 fprintf(stderr, "READ %d\n", size);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
60 return -1;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
61 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
62
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
63 static int mp_write(URLContext *h, unsigned char *buf, int size)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
64 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
65 muxer_t *muxer = (muxer_t*)h->priv_data;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
66 return fwrite(buf, 1, size, muxer->file);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
67 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
68
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
69 static offset_t mp_seek(URLContext *h, offset_t pos, int whence)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
70 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
71 muxer_t *muxer = (muxer_t*)h->priv_data;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
72 fprintf(stderr, "SEEK %llu\n", pos);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
73 return fseeko(muxer->file, pos, whence);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
74 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
75
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
76
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
77 static URLProtocol mp_protocol = {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
78 "menc",
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
79 mp_open,
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
80 mp_read,
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
81 mp_write,
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
82 mp_seek,
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
83 mp_close,
15198
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
84 NULL
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
85 };
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
86
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
87 static muxer_stream_t* lavf_new_stream(muxer_t *muxer, int type)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
88 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
89 muxer_priv_t *priv = (muxer_priv_t*) muxer->priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
90 muxer_stream_t *stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
91 muxer_stream_priv_t *spriv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
92 AVCodecContext *ctx;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
93
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
94 if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO))
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
95 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
96 mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOW TYPE %d\n", type);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
97 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
98 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
99
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
100 stream = (muxer_stream_t*) calloc(1, sizeof(muxer_stream_t));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
101 if(!stream)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
102 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
103 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc muxer_stream, EXIT\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
104 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
105 }
15198
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
106 stream->b_buffer = (unsigned char *)malloc(2048);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
107 if(!stream->b_buffer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
108 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
109 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc b_buffer, EXIT\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
110 free(stream);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
111 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
112 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
113 stream->b_buffer_size = 2048;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
114 stream->b_buffer_ptr = 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
115 stream->b_buffer_len = 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
116
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
117 spriv = (muxer_stream_priv_t*) calloc(1, sizeof(muxer_stream_priv_t));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
118 if(!spriv)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
119 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
120 free(stream);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
121 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
122 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
123 stream->priv = spriv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
124
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
125 spriv->avstream = av_new_stream(priv->oc, 1);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
126 if(!spriv->avstream)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
127 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
128 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc avstream, EXIT\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
129 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
130 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
131 spriv->avstream->stream_copy = 1;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
132
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
133 ctx = &(spriv->avstream->codec);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
134 ctx->codec_id = muxer->avih.dwStreams;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
135 switch(type)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
136 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
137 case MUXER_TYPE_VIDEO:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
138 ctx->codec_type = CODEC_TYPE_VIDEO;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
139 break;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
140 case MUXER_TYPE_AUDIO:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
141 ctx->codec_type = CODEC_TYPE_AUDIO;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
142 break;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
143 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
144
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
145 muxer->avih.dwStreams++;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
146 stream->muxer = muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
147 stream->type = type;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
148 mp_msg(MSGT_MUXER, MSGL_V, "ALLOCATED STREAM N. %d, type=%d\n", muxer->avih.dwStreams, type);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
149 return stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
150 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
151
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
152
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
153 static void fix_parameters(muxer_stream_t *stream)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
154 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
155 muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
156 AVCodecContext *ctx;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
157
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
158 ctx = &(spriv->avstream->codec);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
159
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
160 if(stream->type == MUXER_TYPE_AUDIO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
161 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
162 ctx->codec_id = codec_get_wav_id(stream->wf->wFormatTag);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
163 ctx->codec_tag = codec_get_wav_tag(ctx->codec_id);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
164 mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
165 ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8;
15005
4abf8628ee74 1000l (dwSampleSize != nSamplesPerSec)
michael
parents: 14757
diff changeset
166 ctx->sample_rate = stream->wf->nSamplesPerSec;
4abf8628ee74 1000l (dwSampleSize != nSamplesPerSec)
michael
parents: 14757
diff changeset
167 // mp_msg(MSGT_MUXER, MSGL_INFO, "stream->h.dwSampleSize: %d\n", stream->h.dwSampleSize);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
168 ctx->channels = stream->wf->nChannels;
15011
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
169 if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0)
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
170 ctx->frame_size= (stream->h.dwScale * (int64_t)ctx->sample_rate) / stream->h.dwRate;
15198
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
171 mp_msg(MSGT_MUXER, MSGL_V, "MUXER_LAVF(audio stream) frame_size: %d, scale: %u, sps: %u, rate: %u, ctx->block_align = stream->wf->nBlockAlign; %d=%d stream->wf->nAvgBytesPerSec:%d\n",
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
172 ctx->frame_size, stream->h.dwScale, ctx->sample_rate, stream->h.dwRate,
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
173 ctx->block_align, stream->wf->nBlockAlign, stream->wf->nAvgBytesPerSec);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
174 ctx->block_align = stream->wf->nBlockAlign;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
175 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
176 else if(stream->type == MUXER_TYPE_VIDEO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
177 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
178 ctx->codec_id = codec_get_bmp_id(stream->bih->biCompression);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
179 mp_msg(MSGT_MUXER, MSGL_INFO, "VIDEO CODEC ID: %d\n", ctx->codec_id);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
180 ctx->width = stream->bih->biWidth;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
181 ctx->height = stream->bih->biHeight;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
182 ctx->bit_rate = 800000;
15309
cfbd8e4b3ede at lest this fixes build.. there's no way muxer_lavf is working right yet tho with mencoder's broken timestamps
rfelker
parents: 15198
diff changeset
183 #if (LIBAVFORMAT_BUILD >= 4624)
cfbd8e4b3ede at lest this fixes build.. there's no way muxer_lavf is working right yet tho with mencoder's broken timestamps
rfelker
parents: 15198
diff changeset
184 ctx->time_base.den = stream->h.dwRate;
cfbd8e4b3ede at lest this fixes build.. there's no way muxer_lavf is working right yet tho with mencoder's broken timestamps
rfelker
parents: 15198
diff changeset
185 ctx->time_base.num = stream->h.dwScale;
cfbd8e4b3ede at lest this fixes build.. there's no way muxer_lavf is working right yet tho with mencoder's broken timestamps
rfelker
parents: 15198
diff changeset
186 #else
15011
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
187 ctx->frame_rate = stream->h.dwRate;
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
188 ctx->frame_rate_base = stream->h.dwScale;
15309
cfbd8e4b3ede at lest this fixes build.. there's no way muxer_lavf is working right yet tho with mencoder's broken timestamps
rfelker
parents: 15198
diff changeset
189 #endif
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
190 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
191 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
192
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
193 static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
194 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
195 muxer_t *muxer = (muxer_t*) stream->muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
196 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
197 muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
198 AVPacket pkt;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
199
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
200 stream->size += len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
201
15198
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
202 if(len)
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
203 {
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
204 av_init_packet(&pkt);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
205 pkt.size = len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
206 pkt.stream_index= spriv->avstream->index;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
207 pkt.data = stream->buffer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
208
15198
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
209 if(flags & AVIIF_KEYFRAME)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
210 pkt.flags |= PKT_FLAG_KEY;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
211 else
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
212 pkt.flags = 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
213
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
214
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
215 //pkt.pts = AV_NOPTS_VALUE;
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
216 #if LIBAVFORMAT_BUILD >= 4624
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
217 pkt.pts = (stream->timer / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
218 #else
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
219 pkt.pts = AV_TIME_BASE * stream->timer;
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
220 #endif
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
221 //fprintf(stderr, "%Ld %Ld id:%d tb:%f %f\n", pkt.dts, pkt.pts, pkt.stream_index, av_q2d(priv->oc->streams[pkt.stream_index]->time_base), stream->timer);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
222
15198
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
223 if(av_interleaved_write_frame(priv->oc, &pkt) != 0) //av_write_frame(priv->oc, &pkt)
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
224 {
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
225 mp_msg(MSGT_MUXER, MSGL_ERR, "Error while writing frame\n");
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
226 }
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
227 }
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
228
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
229 if(stream->h.dwSampleSize) // CBR
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
230 stream->h.dwLength += len / stream->h.dwSampleSize;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
231 else // VBR
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
232 stream->h.dwLength++;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
233
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
234 stream->timer = (double) stream->h.dwLength * stream->h.dwScale / stream->h.dwRate;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
235 return;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
236 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
237
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
238
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
239 static void write_header(muxer_t *muxer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
240 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
241 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
242
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
243 av_write_header(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
244 muxer->cont_write_header = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
245 mp_msg(MSGT_MUXER, MSGL_INFO, "WRITTEN HEADER\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
246 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
247
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
248
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
249 static void write_trailer(muxer_t *muxer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
250 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
251 int i;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
252 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
253
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
254 av_write_trailer(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
255 mp_msg(MSGT_MUXER, MSGL_INFO, "WRITTEN TRAILER\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
256 for(i = 0; i < priv->oc->nb_streams; i++)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
257 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
258 av_freep(&(priv->oc->streams[i]));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
259 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
260
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
261 url_fclose(&(priv->oc->pb));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
262
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
263 av_free(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
264 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
265
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
266 extern char *out_filename;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
267 int muxer_init_muxer_lavf(muxer_t *muxer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
268 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
269 muxer_priv_t *priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
270 AVOutputFormat *fmt = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
271 char mp_filename[256] = "menc://stream.dummy";
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
272
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
273 priv = (muxer_priv_t *) calloc(1, sizeof(muxer_priv_t));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
274 if(priv == NULL)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
275 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
276
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
277 av_register_all();
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
278
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
279 priv->oc = av_alloc_format_context();
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
280 if(!priv->oc)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
281 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
282 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't get format context\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
283 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
284 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
285
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
286 if(conf_format)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
287 fmt = guess_format(conf_format, NULL, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
288 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
289 fmt = guess_format(NULL, out_filename, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
290 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
291 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
292 mp_msg(MSGT_MUXER, MSGL_FATAL, "CAN'T GET SPECIFIED FORMAT\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
293 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
294 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
295 priv->oc->oformat = fmt;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
296
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
297
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
298 if(av_set_parameters(priv->oc, NULL) < 0)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
299 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
300 mp_msg(MSGT_MUXER, MSGL_FATAL, "Invalid output format parameters\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
301 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
302 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
303
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
304 register_protocol(&mp_protocol);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
305
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
306 if(url_fopen(&priv->oc->pb, mp_filename, URL_WRONLY))
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
307 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
308 mp_msg(MSGT_MUXER, MSGL_FATAL, "Coulnd't open outfile\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
309 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
310 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
311
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
312 ((URLContext*)(priv->oc->pb.opaque))->priv_data= muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
313
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
314 muxer->priv = (void *) priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
315 muxer->cont_new_stream = &lavf_new_stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
316 muxer->cont_write_chunk = &write_chunk;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
317 muxer->cont_write_header = &write_header;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
318 muxer->cont_write_index = &write_trailer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
319 muxer->fix_stream_parameters = &fix_parameters;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
320 mp_msg(MSGT_MUXER, MSGL_INFO, "OK, exit\n");
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
321 return 1;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
322
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
323 fail:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
324 free(priv);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
325 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
326 }