]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - ffmpeg.c
WMA: extend exponent range to 95
[frescor/ffmpeg.git] / ffmpeg.c
index 3df78f9befc85e15b49a11606acbf0f68742faa8..5d6d994d42a86b3edaae6b678c9015247fc4fb41 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -91,6 +91,7 @@ static const OptionDef options[];
 
 #define MAX_FILES 20
 
+static char *last_asked_format = NULL;
 static AVFormatContext *input_files[MAX_FILES];
 static int64_t input_files_ts_offset[MAX_FILES];
 static double input_files_ts_scale[MAX_FILES][MAX_STREAMS];
@@ -109,8 +110,6 @@ static int nb_stream_maps;
 static AVMetaDataMap meta_data_maps[MAX_FILES];
 static int nb_meta_data_maps;
 
-static AVInputFormat *file_iformat;
-static AVOutputFormat *file_oformat;
 static int frame_width  = 0;
 static int frame_height = 0;
 static float frame_aspect_ratio = 0;
@@ -483,6 +482,10 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
         st = av_mallocz(sizeof(AVStream));
         memcpy(st, ic->streams[i], sizeof(AVStream));
         st->codec = avcodec_alloc_context();
+        if (!st->codec) {
+            print_error(filename, AVERROR(ENOMEM));
+            av_exit(1);
+        }
         memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));
         s->streams[i] = st;
 
@@ -1253,6 +1256,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
     AVSubtitle subtitle, *subtitle_to_free;
     int got_subtitle;
     AVPacket avpkt;
+    int bps = av_get_bits_per_sample_format(ist->st->codec->sample_fmt)>>3;
 
     if(ist->next_pts == AV_NOPTS_VALUE)
         ist->next_pts= ist->pts;
@@ -1275,7 +1279,8 @@ static int output_packet(AVInputStream *ist, int ist_index,
     handle_eof:
         ist->pts= ist->next_pts;
 
-        if(avpkt.size && avpkt.size != pkt->size && verbose>0)
+        if(avpkt.size && avpkt.size != pkt->size &&
+           !(ist->st->codec->codec->capabilities & CODEC_CAP_SUBFRAMES) && verbose>0)
             fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
 
         /* decode the packet if needed */
@@ -1306,7 +1311,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
                     continue;
                 }
                 data_buf = (uint8_t *)samples;
-                ist->next_pts += ((int64_t)AV_TIME_BASE/2 * data_size) /
+                ist->next_pts += ((int64_t)AV_TIME_BASE/bps * data_size) /
                     (ist->st->codec->sample_rate * ist->st->codec->channels);
                 break;}
             case CODEC_TYPE_VIDEO:
@@ -2378,12 +2383,7 @@ static void opt_format(const char *arg)
         fprintf(stderr, "pgmyuv format is deprecated, use image2\n");
     }
 
-    file_iformat = av_find_input_format(arg);
-    file_oformat = guess_format(arg, NULL, NULL);
-    if (!file_iformat && !file_oformat) {
-        fprintf(stderr, "Unknown input or output format: %s\n", arg);
-        av_exit(1);
-    }
+    last_asked_format = arg;
 }
 
 static void opt_video_rc_override_string(const char *arg)
@@ -2825,9 +2825,15 @@ static void opt_input_file(const char *filename)
 {
     AVFormatContext *ic;
     AVFormatParameters params, *ap = &params;
+    AVInputFormat *file_iformat = NULL;
     int err, i, ret, rfps, rfps_base;
     int64_t timestamp;
 
+    if (last_asked_format) {
+        file_iformat = av_find_input_format(last_asked_format);
+        last_asked_format = NULL;
+    }
+
     if (!strcmp(filename, "-"))
         filename = "pipe:";
 
@@ -2836,6 +2842,10 @@ static void opt_input_file(const char *filename)
 
     /* get default parameters from command line */
     ic = avformat_alloc_context();
+    if (!ic) {
+        print_error(filename, AVERROR(ENOMEM));
+        av_exit(1);
+    }
 
     memset(ap, 0, sizeof(*ap));
     ap->prealloced_context = 1;
@@ -2975,8 +2985,6 @@ static void opt_input_file(const char *filename)
         dump_format(ic, nb_input_files, filename, 0);
 
     nb_input_files++;
-    file_iformat = NULL;
-    file_oformat = NULL;
 
     video_channel = 0;
 
@@ -3327,13 +3335,25 @@ static void opt_output_file(const char *filename)
     int use_video, use_audio, use_subtitle;
     int input_has_video, input_has_audio, input_has_subtitle;
     AVFormatParameters params, *ap = &params;
+    AVOutputFormat *file_oformat;
 
     if (!strcmp(filename, "-"))
         filename = "pipe:";
 
     oc = avformat_alloc_context();
+    if (!oc) {
+        print_error(filename, AVERROR(ENOMEM));
+        av_exit(1);
+    }
 
-    if (!file_oformat) {
+    if (last_asked_format) {
+        file_oformat = guess_format(last_asked_format, NULL, NULL);
+        if (!file_oformat) {
+            fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
+            av_exit(1);
+        }
+        last_asked_format = NULL;
+    } else {
         file_oformat = guess_format(NULL, filename, NULL);
         if (!file_oformat) {
             fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
@@ -3456,10 +3476,6 @@ static void opt_output_file(const char *filename)
     oc->flags |= AVFMT_FLAG_NONBLOCK;
 
     set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);
-
-    /* reset some options */
-    file_oformat = NULL;
-    file_iformat = NULL;
 }
 
 /* same option as mencoder */
@@ -3759,19 +3775,19 @@ static int opt_preset(const char *opt, const char *arg)
                            FFMPEG_DATADIR,
                          };
 
-    for(i=!base[0]; i<2 && !f; i++){
-        snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i ? "" : "/.ffmpeg", arg);
-        f= fopen(filename, "r");
-        if(!f){
-            char *codec_name= *opt == 'v' ? video_codec_name :
-                              *opt == 'a' ? audio_codec_name :
-                                            subtitle_codec_name;
-            snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i],  i ? "" : "/.ffmpeg", codec_name, arg);
+    if (*opt != 'f') {
+        for(i=!base[0]; i<2 && !f; i++){
+            snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i ? "" : "/.ffmpeg", arg);
             f= fopen(filename, "r");
+            if(!f){
+                char *codec_name= *opt == 'v' ? video_codec_name :
+                                  *opt == 'a' ? audio_codec_name :
+                                                subtitle_codec_name;
+                snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i],  i ? "" : "/.ffmpeg", codec_name, arg);
+                f= fopen(filename, "r");
+            }
         }
-    }
-    if(!f && ((arg[0]=='.' && arg[1]=='/') || arg[0]=='/' ||
-              is_dos_path(arg))){
+    } else {
         av_strlcpy(filename, arg, sizeof(filename));
         f= fopen(filename, "r");
     }
@@ -3812,7 +3828,10 @@ static const OptionDef options[] = {
     { "L", OPT_EXIT, {(void*)show_license}, "show license" },
     { "h", OPT_EXIT, {(void*)show_help}, "show help" },
     { "version", OPT_EXIT, {(void*)show_version}, "show version" },
-    { "formats", OPT_EXIT, {(void*)show_formats}, "show available formats, codecs, protocols, ..." },
+    { "formats"  , OPT_EXIT, {(void*)show_formats  }, "show available formats" },
+    { "codecs"   , OPT_EXIT, {(void*)show_codecs   }, "show available codecs" },
+    { "bsfs"     , OPT_EXIT, {(void*)show_bsfs     }, "show available bit stream filters" },
+    { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" },
     { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
     { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
     { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
@@ -3836,7 +3855,7 @@ static const OptionDef options[] = {
     { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
     { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
     { "v", HAS_ARG | OPT_FUNC2, {(void*)opt_verbose}, "set ffmpeg verbosity level", "number" },
-    { "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "logging level number or string" },
+    { "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
     { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
     { "threads", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
     { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
@@ -3929,6 +3948,7 @@ static const OptionDef options[] = {
     { "apre", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_preset}, "set the audio options to the indicated preset", "preset" },
     { "vpre", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" },
     { "spre", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" },
+    { "fpre", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options to the indicated preset file", "filename" },
 
     { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
     { NULL, },