1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include "stream.h"
int stream_init(struct Stream *stream, AVFormatContext *s, int codec_id, int sample_rate, int format, const AVChannelLayout *layout, AVDictionary **opts)
{
int err;
AVStream *av_stream;
if ((av_stream = avformat_new_stream(s, NULL)) == NULL)
return AVERROR(ENOMEM);
av_stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
av_stream->codecpar->codec_id = codec_id;
av_stream->codecpar->sample_rate = sample_rate;
av_stream->codecpar->format = format;
av_stream->codecpar->ch_layout = *layout;
if ((err = avformat_init_output(s, opts)) < 0)
return err;
stream->av_stream = av_stream;
stream->s = s;
return 0;
}
int stream_send (struct Stream *stream, AVPacket *pkt)
{
int err;
int64_t duration;
// NOTE:
// Before encoding;
// - frame_out->pts DOES matter
//
// After encoding;
// - pkt->pts is set to something
// - pkt->timebase is unset, but would be '1 / output_sample_rate'
// - pkt->duration is set to the amount of sample in the packet
// - pkt->dts seems to be pkt->pts
pkt->stream_index = stream->av_stream->index;
//av_packet_rescale_ts(pkt_out, encoder->time_base, stream->time_base);
//print_pts(pkt_out, &stream->time_base);
duration = pkt->duration;
if ((err = av_interleaved_write_frame(stream->s, pkt)) < 0)
return err;
return duration;
}
|