annotate ffmenc.c @ 3418:1e1c7967ba6c libavformat

Make update_initial_durations() also work if a dts occured before a sequence header (that is a few known dts/pts but no known durations previously) cnnts1.mpg is one sample affected by this.
author michael
date Tue, 03 Jun 2008 00:50:22 +0000
parents 54e578571711
children 7a0230981402
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
3348
4d492fccf79b split ffm de/muxer
bcoudurier
parents: 3347
diff changeset
2 * FFM (ffserver live feed) muxer
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
3348
4d492fccf79b split ffm de/muxer
bcoudurier
parents: 3347
diff changeset
21
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include "avformat.h"
3348
4d492fccf79b split ffm de/muxer
bcoudurier
parents: 3347
diff changeset
23 #include "ffm.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 /* disable pts hack for testing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 int ffm_nopts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 int fill_size, h;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2222
diff changeset
32 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 fill_size = ffm->packet_end - ffm->packet_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 memset(ffm->packet_ptr, 0, fill_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 862
diff changeset
37 if (url_ftell(pb) % ffm->packet_size)
318
54e915169d48 Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents: 277
diff changeset
38 av_abort();
54e915169d48 Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents: 277
diff changeset
39
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 /* put header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 put_be16(pb, PACKET_ID);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 put_be16(pb, fill_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 put_be64(pb, ffm->pts);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 h = ffm->frame_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 if (ffm->first_packet)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 h |= 0x8000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 put_be16(pb, h);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet);
751
dcb459ca11eb Flush the ffm packet to the wire (or file) whenever we flush the ffm packet.
philipjsg
parents: 744
diff changeset
49 put_flush_packet(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 /* prepare next packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 ffm->frame_offset = 0; /* no key frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 ffm->pts = 0; /* no pts */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 ffm->packet_ptr = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 ffm->first_packet = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 /* 'first' is true if first data of a frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 static void ffm_write_data(AVFormatContext *s,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 187
diff changeset
60 const uint8_t *buf, int size,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 34
diff changeset
61 int64_t pts, int first)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 if (first && ffm->frame_offset == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 if (first && ffm->pts == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 ffm->pts = pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 /* write as many packets as needed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 len = ffm->packet_end - ffm->packet_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 memcpy(ffm->packet_ptr, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 ffm->packet_ptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 if (ffm->packet_ptr >= ffm->packet_end) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 /* special case : no pts in packet : we leave the current one */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 if (ffm->pts == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 ffm->pts = pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 static int ffm_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 FFMStream *fst;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2222
diff changeset
96 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 int bit_rate, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 ffm->packet_size = FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 /* header */
862
aa0abab5e320 fix feed read_header, avoid using put_tag in write_header, to be consistent with read_header, also some minor cosmetics
alex
parents: 858
diff changeset
103 put_le32(pb, MKTAG('F', 'F', 'M', '1'));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 put_be32(pb, ffm->packet_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 /* XXX: store write position in other file ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 put_be64(pb, ffm->packet_size); /* current write position */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 put_be32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 st = s->streams[i];
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
112 bit_rate += st->codec->bit_rate;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 put_be32(pb, bit_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 /* list of streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 fst = av_mallocz(sizeof(FFMStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 if (!fst)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 goto fail;
502
813b0119a98e ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents: 468
diff changeset
122 av_set_pts_info(st, 64, 1, 1000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 st->priv_data = fst;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
125 codec = st->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 /* generic info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 put_be32(pb, codec->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 put_byte(pb, codec->codec_type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 put_be32(pb, codec->bit_rate);
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
130 put_be32(pb, st->quality);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 put_be32(pb, codec->flags);
744
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
132 put_be32(pb, codec->flags2);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
133 put_be32(pb, codec->debug);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 /* specific info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 switch(codec->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 case CODEC_TYPE_VIDEO:
743
af4e24d6310c switch to native time bases
michael
parents: 683
diff changeset
137 put_be32(pb, codec->time_base.num);
af4e24d6310c switch to native time bases
michael
parents: 683
diff changeset
138 put_be32(pb, codec->time_base.den);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 put_be16(pb, codec->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 put_be16(pb, codec->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 put_be16(pb, codec->gop_size);
744
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
142 put_be32(pb, codec->pix_fmt);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 put_byte(pb, codec->qmin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 put_byte(pb, codec->qmax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 put_byte(pb, codec->max_qdiff);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 put_be16(pb, (int) (codec->qcompress * 10000.0));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 put_be16(pb, (int) (codec->qblur * 10000.0));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 put_be32(pb, codec->bit_rate_tolerance);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 put_strz(pb, codec->rc_eq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 put_be32(pb, codec->rc_max_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 put_be32(pb, codec->rc_min_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 put_be32(pb, codec->rc_buffer_size);
823
e8b4454b997d remove non portable get/put_be64_double()
michael
parents: 820
diff changeset
153 put_be64(pb, av_dbl2int(codec->i_quant_factor));
e8b4454b997d remove non portable get/put_be64_double()
michael
parents: 820
diff changeset
154 put_be64(pb, av_dbl2int(codec->b_quant_factor));
e8b4454b997d remove non portable get/put_be64_double()
michael
parents: 820
diff changeset
155 put_be64(pb, av_dbl2int(codec->i_quant_offset));
e8b4454b997d remove non portable get/put_be64_double()
michael
parents: 820
diff changeset
156 put_be64(pb, av_dbl2int(codec->b_quant_offset));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 put_be32(pb, codec->dct_algo);
744
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
158 put_be32(pb, codec->strict_std_compliance);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
159 put_be32(pb, codec->max_b_frames);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
160 put_be32(pb, codec->luma_elim_threshold);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
161 put_be32(pb, codec->chroma_elim_threshold);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
162 put_be32(pb, codec->mpeg_quant);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
163 put_be32(pb, codec->intra_dc_precision);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
164 put_be32(pb, codec->me_method);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
165 put_be32(pb, codec->mb_decision);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
166 put_be32(pb, codec->nsse_weight);
da5b3b9e898e Add in many fields that have been added to the Codec structure. This means
philipjsg
parents: 743
diff changeset
167 put_be32(pb, codec->frame_skip_cmp);
823
e8b4454b997d remove non portable get/put_be64_double()
michael
parents: 820
diff changeset
168 put_be64(pb, av_dbl2int(codec->rc_buffer_aggressivity));
1809
491581a2b9a7 codec_tag settable via VideoTag, and transmit codec_tag in ffm
alex
parents: 1787
diff changeset
169 put_be32(pb, codec->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 put_be32(pb, codec->sample_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 put_le16(pb, codec->channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 put_le16(pb, codec->frame_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 default:
537
558a093b04db do not call (av_)abort()
michael
parents: 502
diff changeset
177 return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 /* hack to have real time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 if (ffm_nopts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 fst->pts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 fst->pts = av_gettime();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 /* flush until end of block reached */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 while ((url_ftell(pb) % ffm->packet_size) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 put_byte(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 /* init packet mux */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 ffm->packet_ptr = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;
537
558a093b04db do not call (av_)abort()
michael
parents: 502
diff changeset
195 assert(ffm->packet_end >= ffm->packet);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 ffm->frame_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 ffm->pts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 ffm->first_packet = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 av_freep(&st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 390
diff changeset
209 static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 390
diff changeset
211 AVStream *st = s->streams[pkt->stream_index];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 FFMStream *fst = st->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 34
diff changeset
213 int64_t pts;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 34
diff changeset
214 uint8_t header[FRAME_HEADER_SIZE];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 pts = fst->pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 /* packet size & key_frame */
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 390
diff changeset
218 header[0] = pkt->stream_index;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 header[1] = 0;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 390
diff changeset
220 if (pkt->flags & PKT_FLAG_KEY)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 header[1] |= FLAG_KEY_FRAME;
3312
20ea7e918398 remove useless var
bcoudurier
parents: 3311
diff changeset
222 AV_WB24(header+2, pkt->size);
3310
66d5e19f7b77 use duration from pkt
bcoudurier
parents: 3309
diff changeset
223 AV_WB24(header+5, pkt->duration);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
3312
20ea7e918398 remove useless var
bcoudurier
parents: 3311
diff changeset
225 ffm_write_data(s, pkt->data, pkt->size, pts, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226
3311
c603ff471631 10l, fix compilation
bcoudurier
parents: 3310
diff changeset
227 fst->pts += pkt->duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 static int ffm_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2222
diff changeset
233 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 /* flush packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 if (ffm->packet_ptr > ffm->packet)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 if (!url_is_streamed(pb)) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 34
diff changeset
243 int64_t size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 /* update the write offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 size = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 url_fseek(pb, 8, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 put_be64(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
254 AVOutputFormat ffm_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 "ffm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 "ffm format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 "ffm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 sizeof(FFMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 /* not really used */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 CODEC_ID_MPEG1VIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 ffm_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 ffm_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 ffm_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 };