annotate libmpdemux/muxer_lavf.c @ 16806:fd2722529d77

charset for help_mp-zh_TW.h
author diego
date Wed, 19 Oct 2005 08:13:55 +0000
parents 0a31740dd5e6
children 6ff3379a0862
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;
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16200
diff changeset
72 fprintf(stderr, "SEEK %"PRIu64"\n", (int64_t)pos);
14757
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
16001
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
133 #if LIBAVFORMAT_BUILD >= 4629
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
134 ctx = spriv->avstream->codec;
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
135 #else
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
136 ctx = &(spriv->avstream->codec);
16001
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
137 #endif
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
138 ctx->codec_id = muxer->avih.dwStreams;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
139 switch(type)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
140 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
141 case MUXER_TYPE_VIDEO:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
142 ctx->codec_type = CODEC_TYPE_VIDEO;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
143 break;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
144 case MUXER_TYPE_AUDIO:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
145 ctx->codec_type = CODEC_TYPE_AUDIO;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
146 break;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
147 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
148
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
149 muxer->avih.dwStreams++;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
150 stream->muxer = muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
151 stream->type = type;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
152 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
153 return stream;
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
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
156
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
157 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
158 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
159 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
160 AVCodecContext *ctx;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
161
16001
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
162 #if LIBAVFORMAT_BUILD >= 4629
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
163 ctx = spriv->avstream->codec;
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
164 #else
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
165 ctx = &(spriv->avstream->codec);
16001
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
166 #endif
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
167
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
168 if(stream->type == MUXER_TYPE_AUDIO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
169 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
170 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
171 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
172 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
173 ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8;
15005
4abf8628ee74 1000l (dwSampleSize != nSamplesPerSec)
michael
parents: 14757
diff changeset
174 ctx->sample_rate = stream->wf->nSamplesPerSec;
4abf8628ee74 1000l (dwSampleSize != nSamplesPerSec)
michael
parents: 14757
diff changeset
175 // 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
176 ctx->channels = stream->wf->nChannels;
15011
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
177 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
178 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
179 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
180 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
181 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
182 ctx->block_align = stream->wf->nBlockAlign;
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
183 if(stream->wf+1 && stream->wf->cbSize)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
184 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
185 ctx->extradata = av_malloc(stream->wf->cbSize);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
186 if(ctx->extradata != NULL)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
187 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
188 ctx->extradata_size = stream->wf->cbSize;
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
189 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
190 }
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
191 else
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
192 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
193 stream->wf->cbSize);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
194 }
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
195 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
196 else if(stream->type == MUXER_TYPE_VIDEO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
197 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
198 ctx->codec_id = codec_get_bmp_id(stream->bih->biCompression);
16200
bb505841be0a video fourcc fix
michael
parents: 16001
diff changeset
199 ctx->codec_tag= stream->bih->biCompression;
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
200 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
201 ctx->width = stream->bih->biWidth;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
202 ctx->height = stream->bih->biHeight;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
203 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
204 #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
205 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
206 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
207 #else
15011
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
208 ctx->frame_rate = stream->h.dwRate;
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
209 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
210 #endif
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
211 if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER)))
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
212 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
213 ctx->extradata = av_malloc(stream->bih->biSize - sizeof(BITMAPINFOHEADER));
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
214 if(ctx->extradata != NULL)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
215 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
216 ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
217 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
218 }
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
219 else
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
220 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
221 stream->bih->biSize - sizeof(BITMAPINFOHEADER));
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
222 }
14757
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 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
225
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
226 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
227 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
228 muxer_t *muxer = (muxer_t*) stream->muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
229 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
230 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
231 AVPacket pkt;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
232
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
233 stream->size += len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
234
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
235 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
236 {
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
237 av_init_packet(&pkt);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
238 pkt.size = len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
239 pkt.stream_index= spriv->avstream->index;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
240 pkt.data = stream->buffer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
241
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
242 if(flags & AVIIF_KEYFRAME)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
243 pkt.flags |= PKT_FLAG_KEY;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
244 else
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
245 pkt.flags = 0;
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 //pkt.pts = AV_NOPTS_VALUE;
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
249 #if LIBAVFORMAT_BUILD >= 4624
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
250 pkt.pts = (stream->timer / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
251 #else
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
252 pkt.pts = AV_TIME_BASE * stream->timer;
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
253 #endif
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
254 //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
255
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
256 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
257 {
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
258 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
259 }
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
260 }
847a9a75baa0 added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents: 15058
diff changeset
261
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
262 if(stream->h.dwSampleSize) // CBR
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
263 stream->h.dwLength += len / stream->h.dwSampleSize;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
264 else // VBR
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
265 stream->h.dwLength++;
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 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
268 return;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
269 }
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 static void write_header(muxer_t *muxer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
273 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
274 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
275
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
276 av_write_header(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
277 muxer->cont_write_header = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
278 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
279 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
280
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 static void write_trailer(muxer_t *muxer)
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 int i;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
285 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
286
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
287 av_write_trailer(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
288 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
289 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
290 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
291 av_freep(&(priv->oc->streams[i]));
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
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
294 url_fclose(&(priv->oc->pb));
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
295
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
296 av_free(priv->oc);
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
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
299 extern char *out_filename;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
300 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
301 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
302 muxer_priv_t *priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
303 AVOutputFormat *fmt = NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
304 char mp_filename[256] = "menc://stream.dummy";
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 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
307 if(priv == NULL)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
308 return 0;
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 av_register_all();
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 priv->oc = av_alloc_format_context();
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
313 if(!priv->oc)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
314 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
315 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
316 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
317 }
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 if(conf_format)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
320 fmt = guess_format(conf_format, NULL, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
321 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
322 fmt = guess_format(NULL, out_filename, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
323 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
324 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
325 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
326 goto fail;
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 priv->oc->oformat = fmt;
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
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
331 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
332 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
333 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
334 goto fail;
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
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
337 register_protocol(&mp_protocol);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
338
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
339 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
340 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
341 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
342 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
343 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
344
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
345 ((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
346
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
347 muxer->priv = (void *) priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
348 muxer->cont_new_stream = &lavf_new_stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
349 muxer->cont_write_chunk = &write_chunk;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
350 muxer->cont_write_header = &write_header;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
351 muxer->cont_write_index = &write_trailer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
352 muxer->fix_stream_parameters = &fix_parameters;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
353 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
354 return 1;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
355
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
356 fail:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
357 free(priv);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
358 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
359 }