Mercurial > mplayer.hg
annotate libmpdemux/muxer_lavf.c @ 17841:73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
Fixes MinGW compilation (caused by missing -liconv), this solution seems best
to me because of e.g. cross-compilation issues just adding -liconv might cause.
author | reimar |
---|---|
date | Sun, 12 Mar 2006 23:06:09 +0000 |
parents | d378f2f39537 |
children | 27e97a75ef70 |
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 "bswap.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
13 #include "aviheader.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
14 #include "ms_hdr.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
15 |
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 "stream.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
18 #include "demuxer.h" |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
19 #include "stheader.h" |
17012 | 20 #include "m_option.h" |
17354 | 21 #ifdef USE_LIBAVFORMAT_SO |
22 #include <ffmpeg/avformat.h> | |
23 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
24 #include "avformat.h" |
17354 | 25 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
26 |
15058 | 27 extern unsigned int codec_get_wav_tag(int id); |
28 extern enum CodecID codec_get_bmp_id(unsigned int tag); | |
29 extern enum CodecID codec_get_wav_id(unsigned int tag); | |
30 | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
31 typedef struct { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
32 //AVInputFormat *avif; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
33 AVFormatContext *oc; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
34 ByteIOContext pb; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
35 int audio_streams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
36 int video_streams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
37 int64_t last_pts; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
38 } muxer_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 typedef struct { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
41 int64_t last_pts; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
42 AVStream *avstream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
43 } muxer_stream_priv_t; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
44 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
45 static char *conf_format = NULL; |
17079
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
52 m_option_t lavfopts_conf[] = { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
53 {"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
|
54 {"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
|
55 {"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
|
56 {"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
|
57 {"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
|
58 {"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
|
59 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
60 {NULL, NULL, 0, 0, 0, 0, NULL} |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
61 }; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
62 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
63 static int mp_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
|
64 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
65 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
66 } |
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 static int mp_close(URLContext *h) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
69 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
70 return 0; |
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 |
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 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
|
75 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
76 fprintf(stderr, "READ %d\n", size); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
77 return -1; |
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 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
|
81 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
82 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
|
83 return fwrite(buf, 1, size, muxer->file); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
84 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
85 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
86 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
|
87 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
88 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
|
89 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
|
90 return fseeko(muxer->file, pos, whence); |
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 |
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 static URLProtocol mp_protocol = { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
95 "menc", |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
96 mp_open, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
97 mp_read, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
98 mp_write, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
99 mp_seek, |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
100 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
|
101 NULL |
14757
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
104 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
|
105 { |
17829 | 106 muxer_priv_t *priv; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
107 muxer_stream_t *stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
108 muxer_stream_priv_t *spriv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
109 AVCodecContext *ctx; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
110 |
17829 | 111 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
|
112 { |
17829 | 113 mp_msg(MSGT_MUXER, MSGL_ERR, "NULL MUXER PASSED OR UNKNOW TYPE %d\n", type); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
114 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
115 } |
17830 | 116 priv = muxer->priv; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
117 |
17830 | 118 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
|
119 if(!stream) |
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 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
|
122 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
123 } |
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
|
124 muxer->streams[muxer->avih.dwStreams] = stream; |
17830 | 125 stream->b_buffer = malloc(2048); |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
126 if(!stream->b_buffer) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
127 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
128 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc b_buffer, EXIT\n"); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
129 free(stream); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
130 return NULL; |
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 stream->b_buffer_size = 2048; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
133 stream->b_buffer_ptr = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
134 stream->b_buffer_len = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
135 |
17830 | 136 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
|
137 if(!spriv) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
138 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
139 free(stream); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
140 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
141 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
142 stream->priv = spriv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
143 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
144 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
|
145 if(!spriv->avstream) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
146 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
147 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
|
148 return NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
149 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
150 spriv->avstream->stream_copy = 1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
151 |
16001 | 152 #if LIBAVFORMAT_BUILD >= 4629 |
153 ctx = spriv->avstream->codec; | |
154 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
155 ctx = &(spriv->avstream->codec); |
16001 | 156 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
157 ctx->codec_id = muxer->avih.dwStreams; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
158 switch(type) |
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 case MUXER_TYPE_VIDEO: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
161 ctx->codec_type = CODEC_TYPE_VIDEO; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
162 break; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
163 case MUXER_TYPE_AUDIO: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
164 ctx->codec_type = CODEC_TYPE_AUDIO; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
165 break; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
166 } |
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 muxer->avih.dwStreams++; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
169 stream->muxer = muxer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
170 stream->type = type; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
171 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
|
172 return stream; |
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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
175 |
15058 | 176 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
|
177 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
178 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
|
179 AVCodecContext *ctx; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
180 |
16001 | 181 #if LIBAVFORMAT_BUILD >= 4629 |
182 ctx = spriv->avstream->codec; | |
183 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
184 ctx = &(spriv->avstream->codec); |
16001 | 185 #endif |
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
|
186 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
|
187 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
|
188 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
189 if(stream->type == MUXER_TYPE_AUDIO) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
190 { |
17833
b3ee00937967
check stream->wf and stream->bih before using them in fix_parameters(). Fixes cid 43
nicodvb
parents:
17830
diff
changeset
|
191 if(!stream->wf) |
b3ee00937967
check stream->wf and stream->bih before using them in fix_parameters(). Fixes cid 43
nicodvb
parents:
17830
diff
changeset
|
192 return; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
193 ctx->codec_id = codec_get_wav_id(stream->wf->wFormatTag); |
17482 | 194 #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
|
195 ctx->codec_tag = codec_get_wav_tag(ctx->codec_id); |
17482 | 196 #endif |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
197 mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag); |
17834
d378f2f39537
in fix_parameters() move assignment of audio bitrate to the proper block (the bitrate for video is actually hardcoded to 800000)
nicodvb
parents:
17833
diff
changeset
|
198 if(stream->wf->nAvgBytesPerSec) |
d378f2f39537
in fix_parameters() move assignment of audio bitrate to the proper block (the bitrate for video is actually hardcoded to 800000)
nicodvb
parents:
17833
diff
changeset
|
199 ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8; |
15005 | 200 ctx->sample_rate = stream->wf->nSamplesPerSec; |
201 // 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
|
202 ctx->channels = stream->wf->nChannels; |
15011 | 203 if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0) |
204 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
|
205 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
|
206 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
|
207 ctx->block_align, stream->wf->nBlockAlign, stream->wf->nAvgBytesPerSec); |
17484 | 208 ctx->block_align = stream->h.dwSampleSize; |
15500 | 209 if(stream->wf+1 && stream->wf->cbSize) |
210 { | |
211 ctx->extradata = av_malloc(stream->wf->cbSize); | |
212 if(ctx->extradata != NULL) | |
213 { | |
214 ctx->extradata_size = stream->wf->cbSize; | |
215 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size); | |
216 } | |
217 else | |
218 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! couldn't allocate %d bytes for extradata\n", | |
219 stream->wf->cbSize); | |
220 } | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
221 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
222 else if(stream->type == MUXER_TYPE_VIDEO) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
223 { |
17833
b3ee00937967
check stream->wf and stream->bih before using them in fix_parameters(). Fixes cid 43
nicodvb
parents:
17830
diff
changeset
|
224 if(!stream->bih) |
b3ee00937967
check stream->wf and stream->bih before using them in fix_parameters(). Fixes cid 43
nicodvb
parents:
17830
diff
changeset
|
225 return; |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
226 ctx->codec_id = codec_get_bmp_id(stream->bih->biCompression); |
17482 | 227 if(ctx->codec_id <= 0) |
228 ctx->codec_tag= stream->bih->biCompression; | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
229 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
|
230 ctx->width = stream->bih->biWidth; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
231 ctx->height = stream->bih->biHeight; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
232 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
|
233 #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
|
234 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
|
235 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
|
236 #else |
15011 | 237 ctx->frame_rate = stream->h.dwRate; |
238 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
|
239 #endif |
15500 | 240 if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER))) |
241 { | |
242 ctx->extradata = av_malloc(stream->bih->biSize - sizeof(BITMAPINFOHEADER)); | |
243 if(ctx->extradata != NULL) | |
244 { | |
245 ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER); | |
246 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size); | |
247 } | |
248 else | |
249 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! couldn't allocate %d bytes for extradata\n", | |
250 stream->bih->biSize - sizeof(BITMAPINFOHEADER)); | |
251 } | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
252 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
253 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
254 |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17485
diff
changeset
|
255 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
|
256 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
257 muxer_t *muxer = (muxer_t*) stream->muxer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
258 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
|
259 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
|
260 AVPacket pkt; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
261 |
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
|
262 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
|
263 { |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
264 av_init_packet(&pkt); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
265 pkt.size = len; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
266 pkt.stream_index= spriv->avstream->index; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
267 pkt.data = stream->buffer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
268 |
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
|
269 if(flags & AVIIF_KEYFRAME) |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
270 pkt.flags |= PKT_FLAG_KEY; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
271 else |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
272 pkt.flags = 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
273 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
274 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
275 //pkt.pts = AV_NOPTS_VALUE; |
15314 | 276 #if LIBAVFORMAT_BUILD >= 4624 |
277 pkt.pts = (stream->timer / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5); | |
278 #else | |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
279 pkt.pts = AV_TIME_BASE * stream->timer; |
15314 | 280 #endif |
281 //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
|
282 |
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
|
283 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
|
284 { |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
285 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
|
286 } |
847a9a75baa0
added missing initializer in URLProtocolo; mux packets only if len > 0; second mencoder's a/v sync model
nicodvb
parents:
15058
diff
changeset
|
287 } |
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 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
289 return; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
290 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
291 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
292 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
293 static void write_header(muxer_t *muxer) |
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 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
|
296 |
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
|
297 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
|
298 av_write_header(priv->oc); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
299 muxer->cont_write_header = NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
300 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
301 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
302 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
303 static void write_trailer(muxer_t *muxer) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
304 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
305 int i; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
306 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
|
307 |
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
|
308 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
|
309 av_write_trailer(priv->oc); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
310 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
|
311 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
312 av_freep(&(priv->oc->streams[i])); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
313 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
314 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
315 url_fclose(&(priv->oc->pb)); |
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_free(priv->oc); |
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 extern char *out_filename; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
321 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
|
322 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
323 muxer_priv_t *priv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
324 AVOutputFormat *fmt = NULL; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
325 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
|
326 |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
327 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
|
328 if (!conf_allow_lavf) { |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
329 mp_msg(MSGT_MUXER, MSGL_FATAL, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
330 "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
|
331 "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
|
332 " -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
|
333 "on the command line.\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
334 } else { |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
335 mp_msg(MSGT_MUXER, MSGL_WARN, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
336 "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
|
337 } |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
338 mp_msg(MSGT_MUXER, MSGL_WARN, |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
339 "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
|
340 "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
|
341 "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
|
342 "*******************************************************************************\n"); |
c3893e949327
muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents:
17065
diff
changeset
|
343 if (!conf_allow_lavf) return 0; |
14757
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 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
|
346 if(priv == NULL) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
347 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
348 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
349 av_register_all(); |
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 priv->oc = av_alloc_format_context(); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
352 if(!priv->oc) |
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 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
|
355 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
356 } |
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 if(conf_format) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
359 fmt = guess_format(conf_format, NULL, NULL); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
360 if(! fmt) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
361 fmt = guess_format(NULL, out_filename, NULL); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
362 if(! fmt) |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
363 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
364 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
|
365 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
366 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
367 priv->oc->oformat = 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 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
370 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
|
371 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
372 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
|
373 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
374 } |
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
|
375 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
|
376 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
|
377 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
|
378 priv->oc->max_delay= (int)(mux_max_delay*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
|
379 |
14757
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
380 register_protocol(&mp_protocol); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
381 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
382 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
|
383 { |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
384 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
|
385 goto fail; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
386 } |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
387 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
388 ((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
|
389 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
390 muxer->priv = (void *) priv; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
391 muxer->cont_new_stream = &lavf_new_stream; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
392 muxer->cont_write_chunk = &write_chunk; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
393 muxer->cont_write_header = &write_header; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
394 muxer->cont_write_index = &write_trailer; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
395 muxer->fix_stream_parameters = &fix_parameters; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
396 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
|
397 return 1; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
398 |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
399 fail: |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
400 free(priv); |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
401 return 0; |
7a2adc5e8928
initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff
changeset
|
402 } |