[FFmpeg-cvslog] output_example: use avformat_alloc_output_context()

Michael Niedermayer git at videolan.org
Sat Apr 30 22:08:52 CEST 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Apr 30 20:44:09 2011 +0200| [ce62b35c313c2618c2e3b49cae3441b3a7dd29fe] | committer: Michael Niedermayer

output_example: use avformat_alloc_output_context()
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/output-example.c |   27 +++++----------------------
 1 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/libavformat/output-example.c b/libavformat/output-example.c
index ddd16f1..ac35ff0 100644
--- a/libavformat/output-example.c
+++ b/libavformat/output-example.c
@@ -442,26 +442,16 @@ int main(int argc, char **argv)
 
     filename = argv[1];
 
-    /* auto detect the output format from the name. default is
-       mpeg. */
-    fmt = av_guess_format(NULL, filename, NULL);
-    if (!fmt) {
+    /* allocate the output media context */
+    oc = avformat_alloc_output_context(NULL, NULL, filename);
+    if (!oc) {
         printf("Could not deduce output format from file extension: using MPEG.\n");
-        fmt = av_guess_format("mpeg", NULL, NULL);
+        oc = avformat_alloc_output_context("mpeg", NULL, filename);
     }
-    if (!fmt) {
-        fprintf(stderr, "Could not find suitable output format\n");
-        exit(1);
-    }
-
-    /* allocate the output media context */
-    oc = avformat_alloc_context();
     if (!oc) {
-        fprintf(stderr, "Memory error\n");
         exit(1);
     }
-    oc->oformat = fmt;
-    snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
+    fmt= oc->oformat;
 
     /* add the audio and video streams using the default format codecs
        and initialize the codecs */
@@ -474,13 +464,6 @@ int main(int argc, char **argv)
         audio_st = add_audio_stream(oc, fmt->audio_codec);
     }
 
-    /* set the output parameters (must be done even if no
-       parameters). */
-    if (av_set_parameters(oc, NULL) < 0) {
-        fprintf(stderr, "Invalid output format parameters\n");
-        exit(1);
-    }
-
     av_dump_format(oc, 0, filename, 1);
 
     /* now that all the parameters are set, we can open the audio and



More information about the ffmpeg-cvslog mailing list