annotate libmpdemux/muxer_lavf.c @ 30934:2852fa664021

Add HAVE_STRERROR_R definition for FFmpeg to config.h.
author diego
date Sun, 28 Mar 2010 19:02:58 +0000
parents 9fc9d1e788aa
children d05a77bed63f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
2 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
5 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
7 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
12 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
14 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
17 */
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 27656
diff changeset
18
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
19 #include <stdio.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
20 #include <stdlib.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
21 #include <string.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
22 #include <sys/types.h>
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
23 #include <inttypes.h>
17485
8d25d5b720de limits.h for INT_MAX
michael
parents: 17484
diff changeset
24 #include <limits.h>
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
25 #include "config.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
26 #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
27 #include "help_mp.h"
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
28
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
29 #include "aviheader.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
30 #include "ms_hdr.h"
26695
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
31 #include "av_opts.h"
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
32
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 22220
diff changeset
33 #include "stream/stream.h"
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
34 #include "muxer.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
35 #include "demuxer.h"
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
36 #include "stheader.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
37 #include "m_option.h"
26069
1318e956c092 FFmpeg now uses different (unified) #include paths.
diego
parents: 25117
diff changeset
38 #include "libavformat/avformat.h"
23602
a7dc7b4c1401 pstrcpy -> av_strlcpy
reimar
parents: 23321
diff changeset
39 #include "libavutil/avstring.h"
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
40
26328
11aac031b4b7 Split the lavf taglists out of the lavf muxer to allow using libmpmux
albeu
parents: 26069
diff changeset
41 #include "mp_taglists.h"
24124
d2f65b67e568 Add missing pixelformat conversion function prototype
reimar
parents: 23956
diff changeset
42
26328
11aac031b4b7 Split the lavf taglists out of the lavf muxer to allow using libmpmux
albeu
parents: 26069
diff changeset
43 enum PixelFormat imgfmt2pixfmt(int fmt);
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
44
18554
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
45 extern char *info_name;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
46 extern char *info_artist;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
47 extern char *info_genre;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
48 extern char *info_subject;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
49 extern char *info_copyright;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
50 extern char *info_sourceform;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
51 extern char *info_comment;
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
52
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
53 #define BIO_BUFFER_SIZE 32768
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
54
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
55 typedef struct {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
56 //AVInputFormat *avif;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
57 AVFormatContext *oc;
25117
c6702b710b2c Bring (de)muxer_lavf up to date with the libavformat API changes introduced by FFmpeg commit r11071.
iive
parents: 25107
diff changeset
58 ByteIOContext *pb;
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
59 int audio_streams;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
60 int video_streams;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
61 int64_t last_pts;
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
62 uint8_t buffer[BIO_BUFFER_SIZE];
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
63 } muxer_priv_t;
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 typedef struct {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
66 int64_t last_pts;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
67 AVStream *avstream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
68 } muxer_stream_priv_t;
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 static char *conf_format = 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
71 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
72 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
73 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
74 static float mux_max_delay= 0.7;
26695
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
75 static char *mux_avopt = NULL;
14757
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 m_option_t lavfopts_conf[] = {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
78 {"format", &(conf_format), CONF_TYPE_STRING, 0, 0, 0, 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
79 {"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
80 {"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
81 {"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
82 {"delay", &mux_max_delay, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL},
26695
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
83 {"o", &mux_avopt, CONF_TYPE_STRING, 0, 0, 0, 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
84
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
85 {NULL, NULL, 0, 0, 0, 0, NULL}
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
86 };
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
87
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
88 static int mp_write(void *opaque, uint8_t *buf, int size)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
89 {
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
90 muxer_t *muxer = opaque;
21660
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
91 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
92 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
93
27656
3029d0e351a5 fix compilation w/ FFmpeg r15533
gpoirier
parents: 26816
diff changeset
94 static int64_t mp_seek(void *opaque, int64_t pos, int whence)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
95 {
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
96 muxer_t *muxer = opaque;
21660
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
97 if(whence == SEEK_CUR)
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
98 {
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
99 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
100 if(cur == -1)
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
101 return -1;
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
102 pos += cur;
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
103 }
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
104 else if(whence == SEEK_END)
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
105 {
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
106 off_t size=0;
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 24124
diff changeset
107 if(stream_control(muxer->stream, STREAM_CTRL_GET_SIZE, &size) == STREAM_UNSUPPORTED || size < pos)
21660
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
108 return -1;
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
109 pos = size - pos;
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
110 }
20740
a2a3094c5c09 fprintf -> mp_msg
michael
parents: 19360
diff changeset
111 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
112 if(!stream_seek(muxer->stream, pos))
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
113 return -1;
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21372
diff changeset
114 return 0;
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
115 }
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 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
119 {
17846
27e97a75ef70 recommitted version 1.22 + Rich's 1.25
nicodvb
parents: 17834
diff changeset
120 muxer_priv_t *priv = muxer->priv;
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
121 muxer_stream_t *stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
122 muxer_stream_priv_t *spriv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
123 AVCodecContext *ctx;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
124
17829
ff148faa7ed5 fixed C99-ism introduced with previous commit
nicodvb
parents: 17828
diff changeset
125 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
126 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
127 mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOWN TYPE %d\n", type);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
128 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
129 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
130
17830
e640ecc0be46 fix cosmetics noticed during nico's 10l
rfelker
parents: 17829
diff changeset
131 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
132 if(!stream)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
133 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
134 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate muxer_stream, EXIT.\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
135 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
136 }
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
137 muxer->streams[muxer->avih.dwStreams] = stream;
17830
e640ecc0be46 fix cosmetics noticed during nico's 10l
rfelker
parents: 17829
diff changeset
138 stream->b_buffer = malloc(2048);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
139 if(!stream->b_buffer)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
140 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
141 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate b_buffer, EXIT.\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
142 free(stream);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
143 return NULL;
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 stream->b_buffer_size = 2048;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
146 stream->b_buffer_ptr = 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
147 stream->b_buffer_len = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
148
17830
e640ecc0be46 fix cosmetics noticed during nico's 10l
rfelker
parents: 17829
diff changeset
149 spriv = calloc(1, sizeof(muxer_stream_priv_t));
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
150 if(!spriv)
14757
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 free(stream);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
153 return NULL;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
154 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
155 stream->priv = spriv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
156
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
157 spriv->avstream = av_new_stream(priv->oc, 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
158 if(!spriv->avstream)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
159 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
160 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate avstream, EXIT.\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
161 return NULL;
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 spriv->avstream->stream_copy = 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
164
16001
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
165 ctx = spriv->avstream->codec;
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
166 ctx->codec_id = muxer->avih.dwStreams;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
167 switch(type)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
168 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
169 case MUXER_TYPE_VIDEO:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
170 ctx->codec_type = CODEC_TYPE_VIDEO;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
171 break;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
172 case MUXER_TYPE_AUDIO:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
173 ctx->codec_type = CODEC_TYPE_AUDIO;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
174 break;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
175 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
176
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
177 muxer->avih.dwStreams++;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
178 stream->muxer = muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
179 stream->type = type;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
180 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
181 return stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
182 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
183
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
184
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 15011
diff changeset
185 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
186 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
187 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
188 AVCodecContext *ctx;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
189
16001
b939c687986f LIBAVFORMAT_BUILD >= 4629
michael
parents: 15500
diff changeset
190 ctx = spriv->avstream->codec;
19073
8b52dad54b1d Remove #if LIBAVCODEC_BUILD >= XXX and #if LIBAVFORMAT_BUILD >= XXX jungle.
diego
parents: 18554
diff changeset
191
19360
d4d72e5eea07 pass average bitrate from encoder to (lavf) muxer
michael
parents: 19073
diff changeset
192 ctx->bit_rate= stream->avg_rate;
d4d72e5eea07 pass average bitrate from encoder to (lavf) muxer
michael
parents: 19073
diff changeset
193 if(stream->wf && stream->wf->nAvgBytesPerSec && !ctx->bit_rate)
17846
27e97a75ef70 recommitted version 1.22 + Rich's 1.25
nicodvb
parents: 17834
diff changeset
194 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
195 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
196 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
197
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
198 if(stream->type == MUXER_TYPE_AUDIO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
199 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
200 ctx->codec_id = av_codec_get_id(mp_wav_taglists, stream->wf->wFormatTag);
17482
e6dc1aeaf8a5 fix aac in mov/mp4
michael
parents: 17480
diff changeset
201 #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
202 ctx->codec_tag = codec_get_wav_tag(ctx->codec_id);
17482
e6dc1aeaf8a5 fix aac in mov/mp4
michael
parents: 17480
diff changeset
203 #endif
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
204 mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag);
15005
4abf8628ee74 1000l (dwSampleSize != nSamplesPerSec)
michael
parents: 14757
diff changeset
205 ctx->sample_rate = stream->wf->nSamplesPerSec;
4abf8628ee74 1000l (dwSampleSize != nSamplesPerSec)
michael
parents: 14757
diff changeset
206 // 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
207 ctx->channels = stream->wf->nChannels;
15011
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
208 if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0)
83077e6742e7 various (de)muxer_lavf fixes
michael
parents: 15005
diff changeset
209 ctx->frame_size= (stream->h.dwScale * (int64_t)ctx->sample_rate) / stream->h.dwRate;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
210 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",
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
211 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
212 ctx->block_align, stream->wf->nBlockAlign, stream->wf->nAvgBytesPerSec);
17484
43ac198cb5cf correct block align
michael
parents: 17482
diff changeset
213 ctx->block_align = stream->h.dwSampleSize;
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
214 if(stream->wf+1 && stream->wf->cbSize)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
215 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
216 ctx->extradata = av_malloc(stream->wf->cbSize);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
217 if(ctx->extradata != NULL)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
218 {
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
219 ctx->extradata_size = stream->wf->cbSize;
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
220 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
221 }
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
222 else
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
223 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! Could not allocate %d bytes for extradata.\n",
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
224 stream->wf->cbSize);
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
225 }
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
226 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
227 else if(stream->type == MUXER_TYPE_VIDEO)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
228 {
21966
d9494ca70ca7 Simplify by using av_codec_get_id and include riff.h only in demux_lavf.c
reimar
parents: 21961
diff changeset
229 ctx->codec_id = av_codec_get_id(mp_bmp_taglists, stream->bih->biCompression);
21960
0b4d2b0e8722 support -ffourcc with -of lavf
reimar
parents: 21822
diff changeset
230 if(ctx->codec_id <= 0 || force_fourcc)
17482
e6dc1aeaf8a5 fix aac in mov/mp4
michael
parents: 17480
diff changeset
231 ctx->codec_tag= stream->bih->biCompression;
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
232 mp_msg(MSGT_MUXER, MSGL_INFO, "VIDEO CODEC ID: %d\n", ctx->codec_id);
23320
5ea7c5d20f09 PIX_FMT_NONE is -1, not 0, so if stream->imgfmt is 0, ctx->pix_fmt gets
corey
parents: 23309
diff changeset
233 if (stream->imgfmt)
23321
ab8f2f9afd51 cosmetics: fix indentation for previous commit
corey
parents: 23320
diff changeset
234 ctx->pix_fmt = imgfmt2pixfmt(stream->imgfmt);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
235 ctx->width = stream->bih->biWidth;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
236 ctx->height = stream->bih->biHeight;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
237 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
238 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
239 ctx->time_base.num = stream->h.dwScale;
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
240 if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER)))
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
241 {
21810
7a36d3332133 sizeof() is long, thus %d format in error message is wrong.
reimar
parents: 21771
diff changeset
242 ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER);
7a36d3332133 sizeof() is long, thus %d format in error message is wrong.
reimar
parents: 21771
diff changeset
243 ctx->extradata = av_malloc(ctx->extradata_size);
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
244 if(ctx->extradata != NULL)
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
245 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
21810
7a36d3332133 sizeof() is long, thus %d format in error message is wrong.
reimar
parents: 21771
diff changeset
246 else
7a36d3332133 sizeof() is long, thus %d format in error message is wrong.
reimar
parents: 21771
diff changeset
247 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
248 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! Could not allocate %d bytes for extradata.\n",
21810
7a36d3332133 sizeof() is long, thus %d format in error message is wrong.
reimar
parents: 21771
diff changeset
249 ctx->extradata_size);
7a36d3332133 sizeof() is long, thus %d format in error message is wrong.
reimar
parents: 21771
diff changeset
250 ctx->extradata_size = 0;
15500
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
251 }
41fd530bd7a9 mux extradata
nicodvb
parents: 15314
diff changeset
252 }
14757
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 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
255
17487
fa17424b4c7b change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents: 17485
diff changeset
256 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
257 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
258 muxer_t *muxer = (muxer_t*) stream->muxer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
259 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
260 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
261 AVPacket pkt;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
262
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
263 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
264 {
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
265 av_init_packet(&pkt);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
266 pkt.size = len;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
267 pkt.stream_index= spriv->avstream->index;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
268 pkt.data = stream->buffer;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
269
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
270 if(flags & AVIIF_KEYFRAME)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
271 pkt.flags |= PKT_FLAG_KEY;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
272 else
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
273 pkt.flags = 0;
23955
c4c4712cebae make muxer store the provided timestamps
michael
parents: 23602
diff changeset
274
c4c4712cebae make muxer store the provided timestamps
michael
parents: 23602
diff changeset
275 pkt.dts = (dts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
c4c4712cebae make muxer store the provided timestamps
michael
parents: 23602
diff changeset
276 pkt.pts = (pts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
15314
5ca3a981d62a fix timestamps
michael
parents: 15309
diff changeset
277 //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);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
278
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
279 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
280 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
281 mp_msg(MSGT_MUXER, MSGL_ERR, "Error while writing frame.\n");
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
282 }
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 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
284
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
285 return;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
286 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
287
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
288
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
289 static void write_header(muxer_t *muxer)
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 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
292
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
293 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
294 av_write_header(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
295 muxer->cont_write_header = NULL;
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
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
299 static void write_trailer(muxer_t *muxer)
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 int i;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
302 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
303
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
304 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
305 av_write_trailer(priv->oc);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
306 for(i = 0; i < priv->oc->nb_streams; i++)
14757
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 av_freep(&(priv->oc->streams[i]));
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
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
311 av_freep(&priv->oc->pb);
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
312
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
313 av_free(priv->oc);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
314 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
315
22198
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
316 static void list_formats(void) {
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
317 AVOutputFormat *fmt;
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
318 mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf output formats:\n");
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
319 for (fmt = first_oformat; fmt; fmt = fmt->next)
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
320 mp_msg(MSGT_DEMUX, MSGL_INFO, "%15s : %s\n", fmt->name, fmt->long_name);
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
321 }
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
322
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
323 extern char *out_filename;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
324 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
325 {
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
326 muxer_priv_t *priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
327 AVOutputFormat *fmt = NULL;
17079
c3893e949327 muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents: 17065
diff changeset
328
22198
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
329 av_register_all();
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
330
22220
3687d95f3715 Don't segfault if no -format is given for lavf
uau
parents: 22198
diff changeset
331 if (conf_format && strcmp(conf_format, "help") == 0) {
22198
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
332 list_formats();
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
333 return 0;
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
334 }
0d59af1f4156 Print list of lavf muxer formats with format=help.
reimar
parents: 21966
diff changeset
335
17079
c3893e949327 muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents: 17065
diff changeset
336 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
337 mp_msg(MSGT_MUXER, MSGL_WARN,
23956
a0d1fe96bdb8 get rid of this idiotic i_certify_that_my_video_stream_does_not_use_b_frames
michael
parents: 23955
diff changeset
338 "REMEMBER: MEncoder's libavformat muxing is presently broken and can generate\n"
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
339 "INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer\n"
17079
c3893e949327 muxer_lavf MUST be disabled by default until someone adds AVParser
rfelker
parents: 17065
diff changeset
340 "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
341 "*******************************************************************************\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
342
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 29920
diff changeset
343 priv = calloc(1, sizeof(muxer_priv_t));
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
344 if(priv == NULL)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
345 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
346
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
347 priv->oc = av_alloc_format_context();
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
348 if(!priv->oc)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
349 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
350 mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not get format context.\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
351 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
352 }
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
353
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
354 if(conf_format)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
355 fmt = guess_format(conf_format, NULL, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
356 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
357 fmt = guess_format(NULL, out_filename, NULL);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
358 if(! fmt)
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
359 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
360 mp_msg(MSGT_MUXER, MSGL_FATAL, "Cannot get specified format.\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
361 goto fail;
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 priv->oc->oformat = fmt;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
364
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
365
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
366 if(av_set_parameters(priv->oc, NULL) < 0)
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
367 {
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
368 mp_msg(MSGT_MUXER, MSGL_FATAL, "invalid output format parameters\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
369 goto fail;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
370 }
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
371 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
372 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
373 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
374 priv->oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
18554
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
375 if (info_name)
23602
a7dc7b4c1401 pstrcpy -> av_strlcpy
reimar
parents: 23321
diff changeset
376 av_strlcpy(priv->oc->title , info_name, sizeof(priv->oc->title ));
18554
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
377 if (info_artist)
23602
a7dc7b4c1401 pstrcpy -> av_strlcpy
reimar
parents: 23321
diff changeset
378 av_strlcpy(priv->oc->author , info_artist, sizeof(priv->oc->author ));
18554
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
379 if (info_genre)
23602
a7dc7b4c1401 pstrcpy -> av_strlcpy
reimar
parents: 23321
diff changeset
380 av_strlcpy(priv->oc->genre , info_genre, sizeof(priv->oc->genre ));
18554
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
381 if (info_copyright)
23602
a7dc7b4c1401 pstrcpy -> av_strlcpy
reimar
parents: 23321
diff changeset
382 av_strlcpy(priv->oc->copyright, info_copyright, sizeof(priv->oc->copyright));
18554
ebf5efd78cb6 metadata support
michael
parents: 17846
diff changeset
383 if (info_comment)
23602
a7dc7b4c1401 pstrcpy -> av_strlcpy
reimar
parents: 23321
diff changeset
384 av_strlcpy(priv->oc->comment , info_comment, sizeof(priv->oc->comment ));
26695
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
385
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
386 if(mux_avopt){
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
387 if(parse_avopts(priv->oc, mux_avopt) < 0){
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
388 mp_msg(MSGT_MUXER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal.\n", mux_avopt);
26695
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
389 goto fail;
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
390 }
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
391 }
1af41774481b AVOptions support for lavf muxing.
michael
parents: 26690
diff changeset
392
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
393 priv->oc->pb = av_alloc_put_byte(priv->buffer, BIO_BUFFER_SIZE, 1, muxer, NULL, mp_write, mp_seek);
29920
4f740437ed2b Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents: 29263
diff changeset
394 if ((muxer->stream->flags & MP_STREAM_SEEK) != MP_STREAM_SEEK)
26816
e77942d2d664 Use av_alloc_put_byte instead of custom protocol.
reimar
parents: 26702
diff changeset
395 priv->oc->pb->is_streamed = 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
396
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
397 muxer->priv = (void *) priv;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
398 muxer->cont_new_stream = &lavf_new_stream;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
399 muxer->cont_write_chunk = &write_chunk;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
400 muxer->cont_write_header = &write_header;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
401 muxer->cont_write_index = &write_trailer;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
402 muxer->fix_stream_parameters = &fix_parameters;
26702
b5e7063ffade cosmetics: wording/spelling fixes
diego
parents: 26695
diff changeset
403 mp_msg(MSGT_MUXER, MSGL_INFO, "OK, exit.\n");
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
404 return 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
405
14757
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
406 fail:
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
407 free(priv);
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
408 return 0;
7a2adc5e8928 initial, extremely experimental, libavformat muxer; don't expect anything to work yet
nicodvb
parents:
diff changeset
409 }