[FFmpeg-cvslog] examples/muxing: add missing error checks

Stefano Sabatini git at videolan.org
Mon Oct 15 15:36:58 CEST 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Mon Oct 15 15:33:58 2012 +0200| [6133149e0c70f570291c9b685a0be38fde58efe1] | committer: Stefano Sabatini

examples/muxing: add missing error checks

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6133149e0c70f570291c9b685a0be38fde58efe1
---

 doc/examples/muxing.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index 6daeb9e..c6b0294 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -115,6 +115,10 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
     samples = av_malloc(audio_input_frame_size *
                         av_get_bytes_per_sample(c->sample_fmt) *
                         c->channels);
+    if (!samples) {
+        fprintf(stderr, "Could not allocate audio samples buffer\n");
+        exit(1);
+    }
 }
 
 /* Prepare a 16 bit dummy audio frame of 'frame_size' samples and
@@ -139,7 +143,7 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
     AVCodecContext *c;
     AVPacket pkt = { 0 }; // data and size must be 0;
     AVFrame *frame = avcodec_alloc_frame();
-    int got_packet;
+    int got_packet, ret;
 
     av_init_packet(&pkt);
     c = st->codec;
@@ -152,7 +156,12 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
                              av_get_bytes_per_sample(c->sample_fmt) *
                              c->channels, 1);
 
-    avcodec_encode_audio2(c, &pkt, frame, &got_packet);
+    ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
+    if (ret < 0) {
+        fprintf(stderr, "Error encoding audio frame\n");
+        exit(1);
+    }
+
     if (!got_packet)
         return;
 



More information about the ffmpeg-cvslog mailing list