aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/muxing.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-08-03 17:57:45 +0200
committerStefano Sabatini <stefasab@gmail.com>2012-08-07 20:04:19 +0200
commit13bbc464ed949c7ec46a1147d6f3c496d320386c (patch)
treee741b2e053b04000ea808cc6aed67c62c0214294 /doc/examples/muxing.c
parent8993c256950067f29bc750140514ef6a1f5fd05d (diff)
downloadffmpeg-13bbc464ed949c7ec46a1147d6f3c496d320386c.tar.gz
examples/muxing: set codec in the codec context
Make add_{audio,video}_stream return the found codec, and pass it to avcodec_open2() through open_{audio,video} functions. Fix failure: No codec provided to avcodec_open2(). could not open codec This is also consistent with the use of the avcodec_open2() API in the codebase.
Diffstat (limited to 'doc/examples/muxing.c')
-rw-r--r--doc/examples/muxing.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index 4e62b8727a..130c0184ce 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -57,20 +57,20 @@ static int audio_input_frame_size;
/*
* add an audio output stream
*/
-static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id)
+static AVStream *add_audio_stream(AVFormatContext *oc, AVCodec **codec,
+ enum CodecID codec_id)
{
AVCodecContext *c;
AVStream *st;
- AVCodec *codec;
/* find the audio encoder */
- codec = avcodec_find_encoder(codec_id);
- if (!codec) {
+ *codec = avcodec_find_encoder(codec_id);
+ if (!(*codec)) {
fprintf(stderr, "codec not found\n");
exit(1);
}
- st = avformat_new_stream(oc, codec);
+ st = avformat_new_stream(oc, *codec);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
@@ -92,14 +92,14 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id)
return st;
}
-static void open_audio(AVFormatContext *oc, AVStream *st)
+static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
{
AVCodecContext *c;
c = st->codec;
/* open it */
- if (avcodec_open2(c, NULL, NULL) < 0) {
+ if (avcodec_open2(c, codec, NULL) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
@@ -182,20 +182,20 @@ static uint8_t *video_outbuf;
static int frame_count, video_outbuf_size;
/* Add a video output stream. */
-static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
+static AVStream *add_video_stream(AVFormatContext *oc, AVCodec **codec,
+ enum CodecID codec_id)
{
AVCodecContext *c;
AVStream *st;
- AVCodec *codec;
/* find the video encoder */
- codec = avcodec_find_encoder(codec_id);
- if (!codec) {
+ *codec = avcodec_find_encoder(codec_id);
+ if (!(*codec)) {
fprintf(stderr, "codec not found\n");
exit(1);
}
- st = avformat_new_stream(oc, codec);
+ st = avformat_new_stream(oc, *codec);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
@@ -203,7 +203,7 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
c = st->codec;
- avcodec_get_context_defaults3(c, codec);
+ avcodec_get_context_defaults3(c, *codec);
c->codec_id = codec_id;
@@ -245,14 +245,14 @@ static AVFrame *alloc_picture(enum PixelFormat pix_fmt, int width, int height)
return picture;
}
-static void open_video(AVFormatContext *oc, AVStream *st)
+static void open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st)
{
AVCodecContext *c;
c = st->codec;
/* open the codec */
- if (avcodec_open2(c, NULL, NULL) < 0) {
+ if (avcodec_open2(c, codec, NULL) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
@@ -412,6 +412,7 @@ int main(int argc, char **argv)
AVOutputFormat *fmt;
AVFormatContext *oc;
AVStream *audio_st, *video_st;
+ AVCodec *audio_codec, *video_codec;
double audio_pts, video_pts;
int i;
@@ -445,18 +446,18 @@ int main(int argc, char **argv)
video_st = NULL;
audio_st = NULL;
if (fmt->video_codec != CODEC_ID_NONE) {
- video_st = add_video_stream(oc, fmt->video_codec);
+ video_st = add_video_stream(oc, &video_codec, fmt->video_codec);
}
if (fmt->audio_codec != CODEC_ID_NONE) {
- audio_st = add_audio_stream(oc, fmt->audio_codec);
+ audio_st = add_audio_stream(oc, &audio_codec, fmt->audio_codec);
}
/* Now that all the parameters are set, we can open the audio and
* video codecs and allocate the necessary encode buffers. */
if (video_st)
- open_video(oc, video_st);
+ open_video(oc, video_codec, video_st);
if (audio_st)
- open_audio(oc, audio_st);
+ open_audio(oc, audio_codec, audio_st);
av_dump_format(oc, 0, filename, 1);