From: simock85 <[email protected]>

added -f option to declare the output format
---
 libavformat/output-example.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavformat/output-example.c b/libavformat/output-example.c
index 6c604c2..dc588d3 100644
--- a/libavformat/output-example.c
+++ b/libavformat/output-example.c
@@ -442,15 +442,15 @@ static void close_video(AVFormatContext *oc, VideoOut 
*out)
 int main(int argc, char **argv)
 {
     const char *filename;
-    AVOutputFormat *fmt;
+    AVOutputFormat *fmt = NULL;
     AVFormatContext *oc;
     AVStream *audio_st, *video_st;
     double audio_pts, video_pts;
     VideoOut *out;
     AudioOut *aout;
     int opt;
-    float duration;
-    int framerate;
+    float duration = STREAM_DURATION;
+    int framerate = STREAM_FRAME_RATE;
     int tot_frames;
     int i;
 
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
     av_register_all();
 
     if (argc < 2) {
-        printf("usage: %s [-d stream_duration] [-r frame_rate] output_file\n"
+        printf("usage: %s [-d stream_duration] [-r frame_rate] [-f format] 
output_file\n"
                "API example program to output a media file with libavformat.\n"
                "The output format is automatically guessed according to the 
file extension.\n"
                "Raw images can also be output by using '%%d' in the filename\n"
@@ -466,14 +466,14 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    duration = STREAM_DURATION;
-    framerate = STREAM_FRAME_RATE;
-
-    while ((opt = getopt(argc, argv, "d:r:")) != -1) {
+    while ((opt = getopt(argc, argv, "d:f:r:")) != -1) {
         switch(opt) {
         case 'd':
             duration = atof(optarg);
             break;
+        case 'f':
+            fmt = av_guess_format(optarg, NULL, NULL);
+            break;
         case 'r':
             framerate = atoi(optarg);
             break;
@@ -485,7 +485,11 @@ int main(int argc, char **argv)
 
     /* auto detect the output format from the name. default is
        mpeg. */
-    fmt = av_guess_format(NULL, filename, NULL);
+
+    if (!fmt) {
+        printf("Trying to deduce output format from file extension\n");
+        fmt = av_guess_format(NULL, filename, NULL);
+    }
     if (!fmt) {
         printf("Could not deduce output format from file extension: using 
MPEG.\n");
         fmt = av_guess_format("mpeg", NULL, NULL);
-- 
1.7.4.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to