Mercurial > mplayer.hg
annotate libmpdemux/muxer_lavf.c @ 17079:c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
support to it. Otherwise users will generate files with totally
nonsensical pts if they use B frames! (And they are already doing so
-- see mplayer-users list!)
If anyone wants to volunteer to add AVParser support, go right ahead!
But until then, do not remove this check. :)
author | rfelker |
---|---|
date | Fri, 02 Dec 2005 19:43:36 +0000 |
parents | cf6bfdf41143 |
children | 60189cd9bbc8 |
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" |
17012 | 7 #include "version.h" |
8 #include "mp_msg.h" | |
17065
cf6bfdf41143
Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents:
17023
diff
changeset
|
9 #include "help_mp.h" |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
10 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
11 #include "bswap.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
12 #include "aviheader.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
13 #include "ms_hdr.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
14 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
15 #include "muxer.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
16 #include "stream.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
17 #include "demuxer.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
18 #include "stheader.h" |
17012 | 19 #include "m_option.h" |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
20 #include "avformat.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
21 |
15058 | 22 extern unsigned int codec_get_wav_tag(int id); |
23 extern enum CodecID codec_get_bmp_id(unsigned int tag); | |
24 extern enum CodecID codec_get_wav_id(unsigned int tag); | |
25 | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
26 typedef struct { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
27 //AVInputFormat *avif; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
28 AVFormatContext *oc; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
29 ByteIOContext pb; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
30 int audio_streams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
31 int video_streams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
32 int64_t last_pts; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
33 } muxer_priv_t; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
34 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
35 typedef struct { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
36 int64_t last_pts; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
37 AVStream *avstream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
38 } muxer_stream_priv_t; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
39 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
40 static char *conf_format = NULL; |
17079
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
41 static int conf_allow_lavf = 0; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
42 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
43 m_option_t lavfopts_conf[] = { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
44 {"format", &(conf_format), CONF_TYPE_STRING, 0, 0, 0, NULL}, |
17079
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
45 {"i_certify_that_my_video_stream_does_not_use_b_frames", &conf_allow_lavf, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
46 {NULL, NULL, 0, 0, 0, 0, NULL} |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
49 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
|
50 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
51 return 0; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
54 static int mp_close(URLContext *h) |
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 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
57 } |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
60 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
|
61 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
62 fprintf(stderr, "READ %d\n", size); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
63 return -1; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
66 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
|
67 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
68 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
|
69 return fwrite(buf, 1, size, muxer->file); |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
72 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
|
73 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
74 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
|
75 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
|
76 return fseeko(muxer->file, pos, whence); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
77 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
78 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
79 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
80 static URLProtocol mp_protocol = { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
81 "menc", |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
82 mp_open, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
83 mp_read, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
84 mp_write, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
85 mp_seek, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
86 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
|
87 NULL |
14757
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
90 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
|
91 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
92 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
|
93 muxer_stream_t *stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
94 muxer_stream_priv_t *spriv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
95 AVCodecContext *ctx; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
96 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
97 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
|
98 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
99 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
|
100 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
101 } |
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 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
|
104 if(!stream) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
105 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
106 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
|
107 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
108 } |
17023
dd5be8f8d16d
buffering in the muxer layer; patch by Corey Hickey (bugfood-ml ad fatooh punctum org) plus small fixes by me
nicodvb
parents:
17012
diff
changeset
|
109 muxer->streams[muxer->avih.dwStreams] = stream; |
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
|
110 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
|
111 if(!stream->b_buffer) |
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 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
|
114 free(stream); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
115 return NULL; |
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 stream->b_buffer_size = 2048; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
118 stream->b_buffer_ptr = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
119 stream->b_buffer_len = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
120 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
121 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
|
122 if(!spriv) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
123 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
124 free(stream); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
125 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
126 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
127 stream->priv = spriv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
128 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
129 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
|
130 if(!spriv->avstream) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
131 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
132 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
|
133 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
134 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
135 spriv->avstream->stream_copy = 1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
136 |
16001 | 137 #if LIBAVFORMAT_BUILD >= 4629 |
138 ctx = spriv->avstream->codec; | |
139 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
140 ctx = &(spriv->avstream->codec); |
16001 | 141 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
142 ctx->codec_id = muxer->avih.dwStreams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
143 switch(type) |
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 case MUXER_TYPE_VIDEO: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
146 ctx->codec_type = CODEC_TYPE_VIDEO; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
147 break; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
148 case MUXER_TYPE_AUDIO: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
149 ctx->codec_type = CODEC_TYPE_AUDIO; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
150 break; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
153 muxer->avih.dwStreams++; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
154 stream->muxer = muxer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
155 stream->type = type; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
156 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
|
157 return stream; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
160 |
15058 | 161 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
|
162 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
163 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
|
164 AVCodecContext *ctx; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
165 |
16001 | 166 #if LIBAVFORMAT_BUILD >= 4629 |
167 ctx = spriv->avstream->codec; | |
168 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
169 ctx = &(spriv->avstream->codec); |
16001 | 170 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
171 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
172 if(stream->type == MUXER_TYPE_AUDIO) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
173 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8; |
15005 | 178 ctx->sample_rate = stream->wf->nSamplesPerSec; |
179 // 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
|
180 ctx->channels = stream->wf->nChannels; |
15011 | 181 if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0) |
182 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
|
183 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
|
184 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
|
185 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
|
186 ctx->block_align = stream->wf->nBlockAlign; |
15500 | 187 if(stream->wf+1 && stream->wf->cbSize) |
188 { | |
189 ctx->extradata = av_malloc(stream->wf->cbSize); | |
190 if(ctx->extradata != NULL) | |
191 { | |
192 ctx->extradata_size = stream->wf->cbSize; | |
193 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size); | |
194 } | |
195 else | |
196 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! couldn't allocate %d bytes for extradata\n", | |
197 stream->wf->cbSize); | |
198 } | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
199 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
200 else if(stream->type == MUXER_TYPE_VIDEO) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
201 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
202 ctx->codec_id = codec_get_bmp_id(stream->bih->biCompression); |
16200 | 203 ctx->codec_tag= stream->bih->biCompression; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
204 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
|
205 ctx->width = stream->bih->biWidth; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
206 ctx->height = stream->bih->biHeight; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
207 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
|
208 #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
|
209 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
|
210 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
|
211 #else |
15011 | 212 ctx->frame_rate = stream->h.dwRate; |
213 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
|
214 #endif |
15500 | 215 if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER))) |
216 { | |
217 ctx->extradata = av_malloc(stream->bih->biSize - sizeof(BITMAPINFOHEADER)); | |
218 if(ctx->extradata != NULL) | |
219 { | |
220 ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER); | |
221 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size); | |
222 } | |
223 else | |
224 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! couldn't allocate %d bytes for extradata\n", | |
225 stream->bih->biSize - sizeof(BITMAPINFOHEADER)); | |
226 } | |
14757
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 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
229 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
230 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
|
231 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
232 muxer_t *muxer = (muxer_t*) stream->muxer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
233 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
|
234 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
|
235 AVPacket pkt; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
236 |
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
|
237 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
|
238 { |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
239 av_init_packet(&pkt); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
240 pkt.size = len; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
241 pkt.stream_index= spriv->avstream->index; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
242 pkt.data = stream->buffer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
243 |
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
|
244 if(flags & AVIIF_KEYFRAME) |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
245 pkt.flags |= PKT_FLAG_KEY; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
246 else |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
247 pkt.flags = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
248 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
249 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
250 //pkt.pts = AV_NOPTS_VALUE; |
15314 | 251 #if LIBAVFORMAT_BUILD >= 4624 |
252 pkt.pts = (stream->timer / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5); | |
253 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
254 pkt.pts = AV_TIME_BASE * stream->timer; |
15314 | 255 #endif |
256 //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
|
257 |
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
|
258 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
|
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 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
|
261 } |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
262 } |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
263 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
264 return; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
265 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
266 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
267 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
268 static void write_header(muxer_t *muxer) |
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 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
|
271 |
17065
cf6bfdf41143
Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents:
17023
diff
changeset
|
272 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingHeader); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
273 av_write_header(priv->oc); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
274 muxer->cont_write_header = NULL; |
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 |
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 static void write_trailer(muxer_t *muxer) |
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 int i; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
281 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
|
282 |
17065
cf6bfdf41143
Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents:
17023
diff
changeset
|
283 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingTrailer); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
284 av_write_trailer(priv->oc); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
285 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
|
286 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
287 av_freep(&(priv->oc->streams[i])); |
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 url_fclose(&(priv->oc->pb)); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
291 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
292 av_free(priv->oc); |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
295 extern char *out_filename; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
296 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
|
297 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
298 muxer_priv_t *priv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
299 AVOutputFormat *fmt = NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
300 char mp_filename[256] = "menc://stream.dummy"; |
17079
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
301 |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
302 mp_msg(MSGT_MUXER, MSGL_WARN, "** MUXER_LAVF *****************************************************************\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
303 if (!conf_allow_lavf) { |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
304 mp_msg(MSGT_MUXER, MSGL_FATAL, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
305 "If you wish to use libavformat muxing, you must ensure that your video stream\n" |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
306 "does not contain B frames (out of order decoding) and specify:\n" |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
307 " -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames\n" |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
308 "on the command line.\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
309 } else { |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
310 mp_msg(MSGT_MUXER, MSGL_WARN, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
311 "You have certified that your video stream does not contain B frames.\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
312 } |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
313 mp_msg(MSGT_MUXER, MSGL_WARN, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
314 "REMEMBER: MEncoder's libavformat muxing is presently broken and will generate\n" |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
315 "INCORRECT files in the presence of B frames. Moreover, due to bugs MPlayer\n" |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
316 "will play these INCORRECT files as if nothing were wrong!\n" |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
317 "*******************************************************************************\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
318 if (!conf_allow_lavf) return 0; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
319 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
320 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
|
321 if(priv == NULL) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
322 return 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 av_register_all(); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
325 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
326 priv->oc = av_alloc_format_context(); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
327 if(!priv->oc) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
328 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
329 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
|
330 goto fail; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
333 if(conf_format) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
334 fmt = guess_format(conf_format, NULL, NULL); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
335 if(! fmt) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
336 fmt = guess_format(NULL, out_filename, NULL); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
337 if(! fmt) |
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 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
|
340 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
341 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
342 priv->oc->oformat = fmt; |
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 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
|
346 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
347 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
|
348 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
349 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
350 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
351 register_protocol(&mp_protocol); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
352 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
353 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
|
354 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
355 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
|
356 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
357 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
358 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
359 ((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
|
360 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
361 muxer->priv = (void *) priv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
362 muxer->cont_new_stream = &lavf_new_stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
363 muxer->cont_write_chunk = &write_chunk; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
364 muxer->cont_write_header = &write_header; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
365 muxer->cont_write_index = &write_trailer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
366 muxer->fix_stream_parameters = &fix_parameters; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
367 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
|
368 return 1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
369 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
370 fail: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
371 free(priv); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
372 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
373 } |