annotate libmpdemux/muxer_lavf.c @ 15850:8d00902ba64a

unification of the sync tag
author gabrov
date Wed, 29 Jun 2005 11:04:00 +0000
parents 41fd530bd7a9
children b939c687986f
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;
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
175 if(stream->wf+1 && stream->wf->cbSize)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
176 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
177 ctx->extradata = av_malloc(stream->wf->cbSize);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
178 if(ctx->extradata != NULL)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
179 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
180 ctx->extradata_size = stream->wf->cbSize;
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
181 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
182 }
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
183 else
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
184 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! couldn't allocate %d bytes for extradata\n",
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
185 stream->wf->cbSize);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
186 }
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
187 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
188 else if(stream->type == MUXER_TYPE_VIDEO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
189 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
190 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
191 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
192 ctx->width = stream->bih->biWidth;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
193 ctx->height = stream->bih->biHeight;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
194 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
195 #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
196 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
197 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
198 #else
15011
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
199 ctx->frame_rate = stream->h.dwRate;
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
200 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
201 #endif
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
202 if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER)))
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
203 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
204 ctx->extradata = av_malloc(stream->bih->biSize - sizeof(BITMAPINFOHEADER));
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
205 if(ctx->extradata != NULL)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
206 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
207 ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
208 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
209 }
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
210 else
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
211 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! couldn't allocate %d bytes for extradata\n",
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
212 stream->bih->biSize - sizeof(BITMAPINFOHEADER));
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
213 }
14757
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 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
216
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
217 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
218 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
219 muxer_t *muxer = (muxer_t*) stream->muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
220 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
221 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
222 AVPacket pkt;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
223
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
224 stream->size += len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
225
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
226 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
227 {
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
228 av_init_packet(&pkt);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
229 pkt.size = len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
230 pkt.stream_index= spriv->avstream->index;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
231 pkt.data = stream->buffer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
232
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
233 if(flags & AVIIF_KEYFRAME)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
234 pkt.flags |= PKT_FLAG_KEY;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
235 else
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
236 pkt.flags = 0;
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 //pkt.pts = AV_NOPTS_VALUE;
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
240 #if LIBAVFORMAT_BUILD >= 4624
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
241 pkt.pts = (stream->timer / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
242 #else
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
243 pkt.pts = AV_TIME_BASE * stream->timer;
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
244 #endif
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
245 //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
246
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
247 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
248 {
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
249 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
250 }
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
251 }
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
252
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
253 if(stream->h.dwSampleSize) // CBR
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
254 stream->h.dwLength += len / stream->h.dwSampleSize;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
255 else // VBR
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
256 stream->h.dwLength++;
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 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
259 return;
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
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 static void write_header(muxer_t *muxer)
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 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
266
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
267 av_write_header(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
268 muxer->cont_write_header = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
269 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
270 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
271
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 static void write_trailer(muxer_t *muxer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
274 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
275 int i;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
276 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
277
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
278 av_write_trailer(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
279 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
280 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
281 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
282 av_freep(&(priv->oc->streams[i]));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
283 }
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 url_fclose(&(priv->oc->pb));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
286
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
287 av_free(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
288 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
289
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
290 extern char *out_filename;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
291 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
292 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
293 muxer_priv_t *priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
294 AVOutputFormat *fmt = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
295 char mp_filename[256] = "menc://stream.dummy";
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 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
298 if(priv == NULL)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
299 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
300
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
301 av_register_all();
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 priv->oc = av_alloc_format_context();
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
304 if(!priv->oc)
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 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
307 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
308 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
309
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
310 if(conf_format)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
311 fmt = guess_format(conf_format, NULL, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
312 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
313 fmt = guess_format(NULL, out_filename, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
314 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
315 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
316 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
317 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
318 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
319 priv->oc->oformat = fmt;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
320
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
321
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
322 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
323 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
324 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
325 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
326 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
327
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
328 register_protocol(&mp_protocol);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
329
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
330 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
331 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
332 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
333 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
334 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
335
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
336 ((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
337
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
338 muxer->priv = (void *) priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
339 muxer->cont_new_stream = &lavf_new_stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
340 muxer->cont_write_chunk = &write_chunk;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
341 muxer->cont_write_header = &write_header;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
342 muxer->cont_write_index = &write_trailer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
343 muxer->fix_stream_parameters = &fix_parameters;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
344 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
345 return 1;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
346
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
347 fail:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
348 free(priv);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
349 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
350 }