summaryrefslogtreecommitdiff
path: root/libavformat/output-example.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-01-28 20:12:45 +0100
committerAnton Khirnov <anton@khirnov.net>2012-02-24 09:44:17 +0100
commit6e9ed7c7ae4699130a365da5d08b186ce605c068 (patch)
treec90c1ec2bb7926bc94022e5e282dabfd5729e5a8 /libavformat/output-example.c
parent447363870f2f91e125e07ac2d0820359a5d86b06 (diff)
lavf/output-example: more proper usage of the new API.
Passing the codec into avformat_new_stream() is preferred.
Diffstat (limited to 'libavformat/output-example.c')
-rw-r--r--libavformat/output-example.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/libavformat/output-example.c b/libavformat/output-example.c
index 50290aa264..38ce37715a 100644
--- a/libavformat/output-example.c
+++ b/libavformat/output-example.c
@@ -64,16 +64,22 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id)
{
AVCodecContext *c;
AVStream *st;
+ AVCodec *codec;
+
+ /* find the audio encoder */
+ codec = avcodec_find_encoder(codec_id);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
- st = avformat_new_stream(oc, NULL);
+ st = avformat_new_stream(oc, codec);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
c = st->codec;
- c->codec_id = codec_id;
- c->codec_type = AVMEDIA_TYPE_AUDIO;
/* put sample parameters */
c->sample_fmt = AV_SAMPLE_FMT_S16;
@@ -91,19 +97,11 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id)
static void open_audio(AVFormatContext *oc, AVStream *st)
{
AVCodecContext *c;
- AVCodec *codec;
c = st->codec;
- /* find the audio encoder */
- codec = avcodec_find_encoder(c->codec_id);
- if (!codec) {
- fprintf(stderr, "codec not found\n");
- exit(1);
- }
-
/* open it */
- if (avcodec_open2(c, codec, NULL) < 0) {
+ if (avcodec_open2(c, NULL, NULL) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
@@ -199,16 +197,22 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
{
AVCodecContext *c;
AVStream *st;
+ AVCodec *codec;
+
+ /* find the video encoder */
+ codec = avcodec_find_encoder(codec_id);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
- st = avformat_new_stream(oc, NULL);
+ st = avformat_new_stream(oc, codec);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
c = st->codec;
- c->codec_id = codec_id;
- c->codec_type = AVMEDIA_TYPE_VIDEO;
/* put sample parameters */
c->bit_rate = 400000;
@@ -262,20 +266,12 @@ static AVFrame *alloc_picture(enum PixelFormat pix_fmt, int width, int height)
static void open_video(AVFormatContext *oc, AVStream *st)
{
- AVCodec *codec;
AVCodecContext *c;
c = st->codec;
- /* find the video encoder */
- codec = avcodec_find_encoder(c->codec_id);
- if (!codec) {
- fprintf(stderr, "codec not found\n");
- exit(1);
- }
-
/* open the codec */
- if (avcodec_open2(c, codec, NULL) < 0) {
+ if (avcodec_open2(c, NULL, NULL) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}