Mercurial > mplayer.hg
annotate libmpdemux/muxer_lavf.c @ 21696:68d7472231cf
consistent naming for revision tags
author | diego |
---|---|
date | Thu, 21 Dec 2006 08:09:32 +0000 |
parents | ca9da45d13e9 |
children | 4f317822d1fc |
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> |
17485 | 6 #include <limits.h> |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
7 #include "config.h" |
17012 | 8 #include "version.h" |
9 #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
|
10 #include "help_mp.h" |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
11 |
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 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
15 #include "stream.h" |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
16 #include "muxer.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" |
17354 | 20 #ifdef USE_LIBAVFORMAT_SO |
21 #include <ffmpeg/avformat.h> | |
22 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
23 #include "avformat.h" |
17354 | 24 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
25 |
15058 | 26 extern unsigned int codec_get_wav_tag(int id); |
27 extern enum CodecID codec_get_bmp_id(unsigned int tag); | |
28 extern enum CodecID codec_get_wav_id(unsigned int tag); | |
29 | |
18554 | 30 extern char *info_name; |
31 extern char *info_artist; | |
32 extern char *info_genre; | |
33 extern char *info_subject; | |
34 extern char *info_copyright; | |
35 extern char *info_sourceform; | |
36 extern char *info_comment; | |
37 | |
38 void pstrcpy(char *buf, int buf_size, const char *str); | |
39 | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
40 typedef struct { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
41 //AVInputFormat *avif; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
42 AVFormatContext *oc; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
43 ByteIOContext pb; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
44 int audio_streams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
45 int video_streams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
46 int64_t last_pts; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
47 } muxer_priv_t; |
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 typedef struct { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
50 int64_t last_pts; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
51 AVStream *avstream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
52 } muxer_stream_priv_t; |
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 char *conf_format = NULL; |
17079
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
55 static int conf_allow_lavf = 0; |
17480
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
56 static int mux_rate= 0; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
57 static int mux_packet_size= 0; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
58 static float mux_preload= 0.5; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
59 static float mux_max_delay= 0.7; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
60 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
61 m_option_t lavfopts_conf[] = { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
62 {"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
|
63 {"i_certify_that_my_video_stream_does_not_use_b_frames", &conf_allow_lavf, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
17480
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
64 {"muxrate", &mux_rate, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL}, |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
65 {"packetsize", &mux_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL}, |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
66 {"preload", &mux_preload, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL}, |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
67 {"delay", &mux_max_delay, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL}, |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
68 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
69 {NULL, NULL, 0, 0, 0, 0, NULL} |
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 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
|
73 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
74 return 0; |
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 int mp_close(URLContext *h) |
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 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
80 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
81 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
82 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
83 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
|
84 { |
20740 | 85 mp_msg(MSGT_MUXER, MSGL_WARN, "READ %d\n", size); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
86 return -1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
87 } |
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 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
|
90 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
91 muxer_t *muxer = (muxer_t*)h->priv_data; |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
92 return stream_write_buffer(muxer->stream, buf, size); |
14757
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
95 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
|
96 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
97 muxer_t *muxer = (muxer_t*)h->priv_data; |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
98 if(whence == SEEK_CUR) |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
99 { |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
100 off_t cur = stream_tell(muxer->stream); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
101 if(cur == -1) |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
102 return -1; |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
103 pos += cur; |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
104 } |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
105 else if(whence == SEEK_END) |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
106 { |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
107 off_t size=0; |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
108 if(stream_control(muxer->stream, STREAM_CTRL_GET_SIZE, &size) == STREAM_UNSUPORTED || size < pos) |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
109 return -1; |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
110 pos = size - pos; |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
111 } |
20740 | 112 mp_msg(MSGT_MUXER, MSGL_DBG2, "SEEK %"PRIu64"\n", (int64_t)pos); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
113 if(!stream_seek(muxer->stream, pos)) |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
114 return -1; |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21372
diff
changeset
|
115 return 0; |
14757
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
118 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
119 static URLProtocol mp_protocol = { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
120 "menc", |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
121 mp_open, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
122 mp_read, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
123 mp_write, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
124 mp_seek, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
125 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
|
126 NULL |
14757
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
129 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
|
130 { |
17846 | 131 muxer_priv_t *priv = muxer->priv; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
132 muxer_stream_t *stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
133 muxer_stream_priv_t *spriv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
134 AVCodecContext *ctx; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
135 |
17829 | 136 if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO)) |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
137 { |
17846 | 138 mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOW TYPE %d\n", type); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
139 return NULL; |
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 |
17830 | 142 stream = calloc(1, sizeof(muxer_stream_t)); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
143 if(!stream) |
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 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
|
146 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
147 } |
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
|
148 muxer->streams[muxer->avih.dwStreams] = stream; |
17830 | 149 stream->b_buffer = malloc(2048); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
150 if(!stream->b_buffer) |
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 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
|
153 free(stream); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
154 return NULL; |
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 stream->b_buffer_size = 2048; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
157 stream->b_buffer_ptr = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
158 stream->b_buffer_len = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
159 |
17830 | 160 spriv = calloc(1, sizeof(muxer_stream_priv_t)); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
161 if(!spriv) |
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 free(stream); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
164 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
165 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
166 stream->priv = spriv; |
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 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
|
169 if(!spriv->avstream) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
170 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
171 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
|
172 return NULL; |
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 spriv->avstream->stream_copy = 1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
175 |
16001 | 176 ctx = spriv->avstream->codec; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
177 ctx->codec_id = muxer->avih.dwStreams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
178 switch(type) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
179 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
180 case MUXER_TYPE_VIDEO: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
181 ctx->codec_type = CODEC_TYPE_VIDEO; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
182 break; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
183 case MUXER_TYPE_AUDIO: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
184 ctx->codec_type = CODEC_TYPE_AUDIO; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
185 break; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
186 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
187 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
188 muxer->avih.dwStreams++; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
189 stream->muxer = muxer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
190 stream->type = type; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
191 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
|
192 return stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
193 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
194 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
195 |
15058 | 196 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
|
197 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
198 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
|
199 AVCodecContext *ctx; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
200 |
16001 | 201 ctx = spriv->avstream->codec; |
19073
8b52dad54b1d
Remove #if LIBAVCODEC_BUILD >= XXX and #if LIBAVFORMAT_BUILD >= XXX jungle.
diego
parents:
18554
diff
changeset
|
202 |
19360
d4d72e5eea07
pass average bitrate from encoder to (lavf) muxer
michael
parents:
19073
diff
changeset
|
203 ctx->bit_rate= stream->avg_rate; |
d4d72e5eea07
pass average bitrate from encoder to (lavf) muxer
michael
parents:
19073
diff
changeset
|
204 if(stream->wf && stream->wf->nAvgBytesPerSec && !ctx->bit_rate) |
17846 | 205 ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8; |
17480
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
206 ctx->rc_buffer_size= stream->vbv_size; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
207 ctx->rc_max_rate= stream->max_rate; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
208 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
209 if(stream->type == MUXER_TYPE_AUDIO) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
210 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
211 ctx->codec_id = codec_get_wav_id(stream->wf->wFormatTag); |
17482 | 212 #if 0 //breaks aac in mov at least |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
213 ctx->codec_tag = codec_get_wav_tag(ctx->codec_id); |
17482 | 214 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
215 mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag); |
15005 | 216 ctx->sample_rate = stream->wf->nSamplesPerSec; |
217 // 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
|
218 ctx->channels = stream->wf->nChannels; |
15011 | 219 if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0) |
220 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
|
221 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
|
222 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
|
223 ctx->block_align, stream->wf->nBlockAlign, stream->wf->nAvgBytesPerSec); |
17484 | 224 ctx->block_align = stream->h.dwSampleSize; |
15500 | 225 if(stream->wf+1 && stream->wf->cbSize) |
226 { | |
227 ctx->extradata = av_malloc(stream->wf->cbSize); | |
228 if(ctx->extradata != NULL) | |
229 { | |
230 ctx->extradata_size = stream->wf->cbSize; | |
231 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size); | |
232 } | |
233 else | |
234 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! couldn't allocate %d bytes for extradata\n", | |
235 stream->wf->cbSize); | |
236 } | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
237 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
238 else if(stream->type == MUXER_TYPE_VIDEO) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
239 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
240 ctx->codec_id = codec_get_bmp_id(stream->bih->biCompression); |
17482 | 241 if(ctx->codec_id <= 0) |
242 ctx->codec_tag= stream->bih->biCompression; | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
243 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
|
244 ctx->width = stream->bih->biWidth; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
245 ctx->height = stream->bih->biHeight; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
246 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
|
247 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
|
248 ctx->time_base.num = stream->h.dwScale; |
15500 | 249 if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER))) |
250 { | |
251 ctx->extradata = av_malloc(stream->bih->biSize - sizeof(BITMAPINFOHEADER)); | |
252 if(ctx->extradata != NULL) | |
253 { | |
254 ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER); | |
255 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size); | |
256 } | |
257 else | |
258 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! couldn't allocate %d bytes for extradata\n", | |
259 stream->bih->biSize - sizeof(BITMAPINFOHEADER)); | |
260 } | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
261 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
262 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
263 |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17485
diff
changeset
|
264 static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags, double dts, double pts) |
14757
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 muxer_t *muxer = (muxer_t*) stream->muxer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
267 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
|
268 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
|
269 AVPacket pkt; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
270 |
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
|
271 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
|
272 { |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
273 av_init_packet(&pkt); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
274 pkt.size = len; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
275 pkt.stream_index= spriv->avstream->index; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
276 pkt.data = stream->buffer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
277 |
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
|
278 if(flags & AVIIF_KEYFRAME) |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
279 pkt.flags |= PKT_FLAG_KEY; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
280 else |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
281 pkt.flags = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
282 |
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 //pkt.pts = AV_NOPTS_VALUE; |
15314 | 285 pkt.pts = (stream->timer / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5); |
286 //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
|
287 |
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
|
288 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
|
289 { |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
290 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
|
291 } |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
292 } |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
293 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
294 return; |
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 |
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 static void write_header(muxer_t *muxer) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
299 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
300 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
|
301 |
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
|
302 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
|
303 av_write_header(priv->oc); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
304 muxer->cont_write_header = NULL; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
307 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
308 static void write_trailer(muxer_t *muxer) |
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 int i; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
311 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
|
312 |
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
|
313 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
|
314 av_write_trailer(priv->oc); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
315 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
|
316 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
317 av_freep(&(priv->oc->streams[i])); |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
320 url_fclose(&(priv->oc->pb)); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
321 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
322 av_free(priv->oc); |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
325 extern char *out_filename; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
326 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
|
327 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
328 muxer_priv_t *priv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
329 AVOutputFormat *fmt = NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
330 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
|
331 |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
332 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
|
333 if (!conf_allow_lavf) { |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
334 mp_msg(MSGT_MUXER, MSGL_FATAL, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
335 "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
|
336 "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
|
337 " -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
|
338 "on the command line.\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
339 } else { |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
340 mp_msg(MSGT_MUXER, MSGL_WARN, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
341 "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
|
342 } |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
343 mp_msg(MSGT_MUXER, MSGL_WARN, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
344 "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
|
345 "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
|
346 "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
|
347 "*******************************************************************************\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
348 if (!conf_allow_lavf) return 0; |
14757
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 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
|
351 if(priv == NULL) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
352 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
353 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
354 av_register_all(); |
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 priv->oc = av_alloc_format_context(); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
357 if(!priv->oc) |
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 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
|
360 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
361 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
362 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
363 if(conf_format) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
364 fmt = guess_format(conf_format, NULL, NULL); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
365 if(! fmt) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
366 fmt = guess_format(NULL, out_filename, NULL); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
367 if(! fmt) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
368 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
369 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
|
370 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
371 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
372 priv->oc->oformat = fmt; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
373 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
374 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
375 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
|
376 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
377 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
|
378 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
379 } |
17480
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
380 priv->oc->packet_size= mux_packet_size; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
381 priv->oc->mux_rate= mux_rate; |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
382 priv->oc->preload= (int)(mux_preload*AV_TIME_BASE); |
3993a5fad89a
pass vbv_size & max_rate from encoder to muxer over muxer_stream_t (if this is wrong/silly/10000000l then dont hesitate to flame / reverse)
michael
parents:
17479
diff
changeset
|
383 priv->oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); |
18554 | 384 if (info_name) |
385 pstrcpy(priv->oc->title , sizeof(priv->oc->title ), info_name ); | |
386 if (info_artist) | |
387 pstrcpy(priv->oc->author , sizeof(priv->oc->author ), info_artist ); | |
388 if (info_genre) | |
389 pstrcpy(priv->oc->genre , sizeof(priv->oc->genre ), info_genre ); | |
390 if (info_copyright) | |
391 pstrcpy(priv->oc->copyright, sizeof(priv->oc->copyright), info_copyright); | |
392 if (info_comment) | |
393 pstrcpy(priv->oc->comment , sizeof(priv->oc->comment ), info_comment ); | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
394 register_protocol(&mp_protocol); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
395 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
396 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
|
397 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
398 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
|
399 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
400 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
401 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
402 ((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
|
403 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
404 muxer->priv = (void *) priv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
405 muxer->cont_new_stream = &lavf_new_stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
406 muxer->cont_write_chunk = &write_chunk; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
407 muxer->cont_write_header = &write_header; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
408 muxer->cont_write_index = &write_trailer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
409 muxer->fix_stream_parameters = &fix_parameters; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
410 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
|
411 return 1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
412 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
413 fail: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
414 free(priv); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
415 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
416 } |