Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master: (21 commits)
fate: allow testing with libavfilter disabled
x86: XOP/FMA4 CPU detection support
ws_snd: misc cosmetic clean-ups
ws_snd: remove the 2-bit ADPCM table and just subtract 2 instead.
ws_snd: use memcpy() and memset() instead of loops
ws_snd: use samples pointer for loop termination instead of a separate iterator variable.
ws_snd: make sure number of channels is 1
ws_snd: add some checks to prevent buffer overread or overwrite.
ws_snd: decode to AV_SAMPLE_FMT_U8 instead of S16.
flacdec: fix buffer size checking in get_metadata_size()
rtp: Simplify ff_rtp_get_payload_type
rtpenc: Add a payload type private option
rtp: Correct ff_rtp_get_payload_type documentation
avconv: replace all fprintf() by av_log().
avconv: change av_log verbosity from ERROR to FATAL for fatal errors.
cmdutils: replace fprintf() by av_log()
avtools: parse loglevel before all the other options.
oggdec: add support for Xiph's CELT codec
sol: return error if av_get_packet() fails.
cosmetics: reindent and pretty-print
...

Conflicts:
avconv.c
cmdutils.c
libavcodec/avcodec.h
libavcodec/version.h
libavformat/oggparsecelt.c
libavformat/utils.c
libavutil/avutil.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/09/27 09:14:37
Showing 27 changed files
... ...
@@ -59,6 +59,7 @@ easier to use. The changes are:
59 59
 - audio support to lavfi input device added
60 60
 - libcdio-paranoia input device for audio CD grabbing
61 61
 - Apple ProRes decoder
62
+- CELT in Ogg demuxing
62 63
 
63 64
 
64 65
 version 0.8:
... ...
@@ -138,7 +138,6 @@ static int audio_volume = 256;
138 138
 
139 139
 static int exit_on_error = 0;
140 140
 static int using_stdin = 0;
141
-static int verbose = 1;
142 141
 static int run_as_daemon  = 0;
143 142
 static int q_pressed = 0;
144 143
 static int64_t video_size = 0;
... ...
@@ -622,9 +621,8 @@ void exit_program(int ret)
622 622
 #endif
623 623
 
624 624
     if (received_sigterm) {
625
-        fprintf(stderr,
626
-            "Received signal %d: terminating.\n",
627
-            (int) received_sigterm);
625
+        av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n",
626
+               (int) received_sigterm);
628 627
         exit (255);
629 628
     }
630 629
 
... ...
@@ -635,7 +633,7 @@ static void assert_avoptions(AVDictionary *m)
635 635
 {
636 636
     AVDictionaryEntry *t;
637 637
     if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
638
-        av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
638
+        av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
639 639
         exit_program(1);
640 640
     }
641 641
 }
... ...
@@ -646,12 +644,12 @@ static void assert_codec_experimental(AVCodecContext *c, int encoder)
646 646
     AVCodec *codec;
647 647
     if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
648 648
         c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
649
-        av_log(NULL, AV_LOG_ERROR, "%s '%s' is experimental and might produce bad "
649
+        av_log(NULL, AV_LOG_FATAL, "%s '%s' is experimental and might produce bad "
650 650
                 "results.\nAdd '-strict experimental' if you want to use it.\n",
651 651
                 codec_string, c->codec->name);
652 652
         codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id);
653 653
         if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))
654
-            av_log(NULL, AV_LOG_ERROR, "Or use the non experimental %s '%s'.\n",
654
+            av_log(NULL, AV_LOG_FATAL, "Or use the non experimental %s '%s'.\n",
655 655
                    codec_string, codec->name);
656 656
         exit_program(1);
657 657
     }
... ...
@@ -747,9 +745,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx
747 747
             av_free_packet(pkt);
748 748
             new_pkt.destruct= av_destruct_packet;
749 749
         } else if(a<0){
750
-            fprintf(stderr, "%s failed for stream %d, codec %s",
751
-                    bsfc->filter->name, pkt->stream_index,
752
-                    avctx->codec ? avctx->codec->name : "copy");
750
+            av_log(NULL, AV_LOG_ERROR, "%s failed for stream %d, codec %s",
751
+                   bsfc->filter->name, pkt->stream_index,
752
+                   avctx->codec ? avctx->codec->name : "copy");
753 753
             print_error("", a);
754 754
             if (exit_on_error)
755 755
                 exit_program(1);
... ...
@@ -795,14 +793,14 @@ need_realloc:
795 795
     audio_out_size += FF_MIN_BUFFER_SIZE;
796 796
 
797 797
     if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){
798
-        fprintf(stderr, "Buffer sizes too large\n");
798
+        av_log(NULL, AV_LOG_FATAL, "Buffer sizes too large\n");
799 799
         exit_program(1);
800 800
     }
801 801
 
802 802
     av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size);
803 803
     av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size);
804 804
     if (!audio_buf || !audio_out){
805
-        fprintf(stderr, "Out of memory in do_audio_out\n");
805
+        av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n");
806 806
         exit_program(1);
807 807
     }
808 808
 
... ...
@@ -834,15 +832,15 @@ need_realloc:
834 834
             ost->audio_resample = 0;
835 835
         } else {
836 836
             if (dec->sample_fmt != AV_SAMPLE_FMT_S16)
837
-                fprintf(stderr, "Warning, using s16 intermediate sample format for resampling\n");
837
+                av_log(NULL, AV_LOG_WARNING, "Using s16 intermediate sample format for resampling\n");
838 838
             ost->resample = av_audio_resample_init(enc->channels,    dec->channels,
839 839
                                                    enc->sample_rate, dec->sample_rate,
840 840
                                                    enc->sample_fmt,  dec->sample_fmt,
841 841
                                                    16, 10, 0, 0.8);
842 842
             if (!ost->resample) {
843
-                fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
844
-                        dec->channels, dec->sample_rate,
845
-                        enc->channels, enc->sample_rate);
843
+                av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
844
+                       dec->channels, dec->sample_rate,
845
+                       enc->channels, enc->sample_rate);
846 846
                 exit_program(1);
847 847
             }
848 848
         }
... ...
@@ -856,9 +854,9 @@ need_realloc:
856 856
         ost->reformat_ctx = av_audio_convert_alloc(enc->sample_fmt, 1,
857 857
                                                    dec->sample_fmt, 1, NULL, 0);
858 858
         if (!ost->reformat_ctx) {
859
-            fprintf(stderr, "Cannot convert %s sample format to %s sample format\n",
860
-                av_get_sample_fmt_name(dec->sample_fmt),
861
-                av_get_sample_fmt_name(enc->sample_fmt));
859
+            av_log(NULL, AV_LOG_FATAL, "Cannot convert %s sample format to %s sample format\n",
860
+                   av_get_sample_fmt_name(dec->sample_fmt),
861
+                   av_get_sample_fmt_name(enc->sample_fmt));
862 862
             exit_program(1);
863 863
         }
864 864
         ost->reformat_pair=MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt);
... ...
@@ -877,8 +875,7 @@ need_realloc:
877 877
                     byte_delta= FFMAX(byte_delta, -size);
878 878
                     size += byte_delta;
879 879
                     buf  -= byte_delta;
880
-                    if(verbose > 2)
881
-                        fprintf(stderr, "discarding %d audio samples\n", (int)-delta);
880
+                    av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n", (int)-delta);
882 881
                     if(!size)
883 882
                         return;
884 883
                     ist->is_start=0;
... ...
@@ -896,14 +893,13 @@ need_realloc:
896 896
                     memcpy(input_tmp + byte_delta, buf, size);
897 897
                     buf= input_tmp;
898 898
                     size += byte_delta;
899
-                    if(verbose > 2)
900
-                        fprintf(stderr, "adding %d audio samples of silence\n", (int)delta);
899
+                    av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", (int)delta);
901 900
                 }
902 901
             }else if(audio_sync_method>1){
903 902
                 int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
904 903
                 av_assert0(ost->audio_resample);
905
-                if(verbose > 2)
906
-                    fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
904
+                av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
905
+                       delta, comp, enc->sample_rate);
907 906
 //                fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
908 907
                 av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
909 908
             }
... ...
@@ -943,7 +939,7 @@ need_realloc:
943 943
     if (enc->frame_size > 1) {
944 944
         /* output resampled raw samples */
945 945
         if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) {
946
-            fprintf(stderr, "av_fifo_realloc2() failed\n");
946
+            av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n");
947 947
             exit_program(1);
948 948
         }
949 949
         av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL);
... ...
@@ -961,7 +957,7 @@ need_realloc:
961 961
             ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
962 962
                                        (short *)audio_buf);
963 963
             if (ret < 0) {
964
-                fprintf(stderr, "Audio encoding failed\n");
964
+                av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
965 965
                 exit_program(1);
966 966
             }
967 967
             audio_size += ret;
... ...
@@ -988,7 +984,7 @@ need_realloc:
988 988
             size_out = size_out*coded_bps/8;
989 989
 
990 990
         if(size_out > audio_out_size){
991
-            fprintf(stderr, "Internal error, buffer size too small\n");
991
+            av_log(NULL, AV_LOG_FATAL, "Internal error, buffer size too small\n");
992 992
             exit_program(1);
993 993
         }
994 994
 
... ...
@@ -996,7 +992,7 @@ need_realloc:
996 996
         ret = avcodec_encode_audio(enc, audio_out, size_out,
997 997
                                    (short *)buftmp);
998 998
         if (ret < 0) {
999
-            fprintf(stderr, "Audio encoding failed\n");
999
+            av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
1000 1000
             exit_program(1);
1001 1001
         }
1002 1002
         audio_size += ret;
... ...
@@ -1035,7 +1031,7 @@ static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void *
1035 1035
         if(avpicture_deinterlace(picture2, picture,
1036 1036
                                  dec->pix_fmt, dec->width, dec->height) < 0) {
1037 1037
             /* if error, do not deinterlace */
1038
-            fprintf(stderr, "Deinterlacing failed\n");
1038
+            av_log(NULL, AV_LOG_WARNING, "Deinterlacing failed\n");
1039 1039
             av_free(buf);
1040 1040
             buf = NULL;
1041 1041
             picture2 = picture;
... ...
@@ -1062,7 +1058,7 @@ static void do_subtitle_out(AVFormatContext *s,
1062 1062
     AVPacket pkt;
1063 1063
 
1064 1064
     if (pts == AV_NOPTS_VALUE) {
1065
-        fprintf(stderr, "Subtitle packets must have a pts\n");
1065
+        av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
1066 1066
         if (exit_on_error)
1067 1067
             exit_program(1);
1068 1068
         return;
... ...
@@ -1091,7 +1087,7 @@ static void do_subtitle_out(AVFormatContext *s,
1091 1091
         subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
1092 1092
                                                     subtitle_out_max_size, sub);
1093 1093
         if (subtitle_out_size < 0) {
1094
-            fprintf(stderr, "Subtitle encoding failed\n");
1094
+            av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
1095 1095
             exit_program(1);
1096 1096
         }
1097 1097
 
... ...
@@ -1163,7 +1159,7 @@ static void do_video_resample(OutputStream *ost,
1163 1163
                                                    enc->width, enc->height, enc->pix_fmt,
1164 1164
                                                    ost->sws_flags, NULL, NULL, NULL);
1165 1165
             if (ost->img_resample_ctx == NULL) {
1166
-                fprintf(stderr, "Cannot get resampling context\n");
1166
+                av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n");
1167 1167
                 exit_program(1);
1168 1168
             }
1169 1169
         }
... ...
@@ -1174,7 +1170,7 @@ static void do_video_resample(OutputStream *ost,
1174 1174
     if (resample_changed) {
1175 1175
         avfilter_graph_free(&ost->graph);
1176 1176
         if (configure_video_filters(ist, ost)) {
1177
-            fprintf(stderr, "Error reinitializing filters!\n");
1177
+            av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
1178 1178
             exit_program(1);
1179 1179
         }
1180 1180
     }
... ...
@@ -1226,12 +1222,10 @@ static void do_video_out(AVFormatContext *s,
1226 1226
 //fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames);
1227 1227
         if (nb_frames == 0){
1228 1228
             ++nb_frames_drop;
1229
-            if (verbose>2)
1230
-                fprintf(stderr, "*** drop!\n");
1229
+            av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
1231 1230
         }else if (nb_frames > 1) {
1232 1231
             nb_frames_dup += nb_frames - 1;
1233
-            if (verbose>2)
1234
-                fprintf(stderr, "*** %d dup!\n", nb_frames-1);
1232
+            av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames-1);
1235 1233
         }
1236 1234
     }else
1237 1235
         ost->sync_opts= lrintf(sync_ipts);
... ...
@@ -1292,7 +1286,7 @@ static void do_video_out(AVFormatContext *s,
1292 1292
                                        bit_buffer, bit_buffer_size,
1293 1293
                                        &big_picture);
1294 1294
             if (ret < 0) {
1295
-                fprintf(stderr, "Video encoding failed\n");
1295
+                av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
1296 1296
                 exit_program(1);
1297 1297
             }
1298 1298
 
... ...
@@ -1378,6 +1372,7 @@ static void print_report(OutputFile *output_files,
1378 1378
     int64_t pts = INT64_MAX;
1379 1379
     static int64_t last_time = -1;
1380 1380
     static int qp_histogram[52];
1381
+    int hours, mins, secs, us;
1381 1382
 
1382 1383
     if (!is_last_report) {
1383 1384
         int64_t cur_time;
... ...
@@ -1454,43 +1449,39 @@ static void print_report(OutputFile *output_files,
1454 1454
                                       ost->st->time_base, AV_TIME_BASE_Q));
1455 1455
     }
1456 1456
 
1457
-    if (verbose > 0 || is_last_report) {
1458
-        int hours, mins, secs, us;
1459
-        secs = pts / AV_TIME_BASE;
1460
-        us = pts % AV_TIME_BASE;
1461
-        mins = secs / 60;
1462
-        secs %= 60;
1463
-        hours = mins / 60;
1464
-        mins %= 60;
1465
-
1466
-        bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
1467
-
1468
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1469
-                 "size=%8.0fkB time=", total_size / 1024.0);
1470
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1471
-                 "%02d:%02d:%02d.%02d ", hours, mins, secs,
1472
-                 (100 * us) / AV_TIME_BASE);
1473
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1474
-                 "bitrate=%6.1fkbits/s", bitrate);
1475
-
1476
-        if (nb_frames_dup || nb_frames_drop)
1477
-          snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
1478
-                  nb_frames_dup, nb_frames_drop);
1479
-
1480
-        if (verbose >= 0)
1481
-            fprintf(stderr, "%s    \r", buf);
1482
-
1483
-        fflush(stderr);
1484
-    }
1457
+    secs = pts / AV_TIME_BASE;
1458
+    us = pts % AV_TIME_BASE;
1459
+    mins = secs / 60;
1460
+    secs %= 60;
1461
+    hours = mins / 60;
1462
+    mins %= 60;
1463
+
1464
+    bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
1465
+
1466
+    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1467
+             "size=%8.0fkB time=", total_size / 1024.0);
1468
+    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1469
+             "%02d:%02d:%02d.%02d ", hours, mins, secs,
1470
+             (100 * us) / AV_TIME_BASE);
1471
+    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1472
+             "bitrate=%6.1fkbits/s", bitrate);
1473
+
1474
+    if (nb_frames_dup || nb_frames_drop)
1475
+        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
1476
+                nb_frames_dup, nb_frames_drop);
1485 1477
 
1486
-    if (is_last_report && verbose >= 0){
1478
+    av_log(NULL, is_last_report ? AV_LOG_WARNING : AV_LOG_INFO, "%s    \r", buf);
1479
+
1480
+    fflush(stderr);
1481
+
1482
+    if (is_last_report) {
1487 1483
         int64_t raw= audio_size + video_size + extra_size;
1488
-        fprintf(stderr, "\n");
1489
-        fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
1490
-                video_size/1024.0,
1491
-                audio_size/1024.0,
1492
-                extra_size/1024.0,
1493
-                100.0*(total_size - raw)/raw
1484
+        av_log(NULL, AV_LOG_INFO, "\n");
1485
+        av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
1486
+               video_size/1024.0,
1487
+               audio_size/1024.0,
1488
+               extra_size/1024.0,
1489
+               100.0*(total_size - raw)/raw
1494 1490
         );
1495 1491
     }
1496 1492
 }
... ...
@@ -1554,7 +1545,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
1554 1554
                     ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
1555 1555
                 }
1556 1556
                 if (ret < 0) {
1557
-                    fprintf(stderr, "Audio encoding failed\n");
1557
+                    av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
1558 1558
                     exit_program(1);
1559 1559
                 }
1560 1560
                 audio_size += ret;
... ...
@@ -1563,7 +1554,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
1563 1563
             case AVMEDIA_TYPE_VIDEO:
1564 1564
                 ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
1565 1565
                 if (ret < 0) {
1566
-                    fprintf(stderr, "Video encoding failed\n");
1566
+                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
1567 1567
                     exit_program(1);
1568 1568
                 }
1569 1569
                 video_size += ret;
... ...
@@ -1635,11 +1626,10 @@ static int output_packet(InputStream *ist, int ist_index,
1635 1635
     handle_eof:
1636 1636
         ist->pts= ist->next_pts;
1637 1637
 
1638
-        if(avpkt.size && avpkt.size != pkt->size &&
1639
-           ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){
1640
-            fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
1638
+        if(avpkt.size && avpkt.size != pkt->size)
1639
+            av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,
1640
+                   "Multiple frames in a packet from stream %d\n", pkt->stream_index);
1641 1641
             ist->showed_multi_packet_warning=1;
1642
-        }
1643 1642
 
1644 1643
         /* decode the packet if needed */
1645 1644
         decoded_data_buf = NULL; /* fail safe */
... ...
@@ -1981,7 +1971,7 @@ static int transcode_init(OutputFile *output_files,
1981 1981
         os = output_files[i].ctx;
1982 1982
         if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) {
1983 1983
             av_dump_format(os, i, os->filename, 1);
1984
-            fprintf(stderr, "Output file #%d does not contain any stream\n", i);
1984
+            av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i);
1985 1985
             return AVERROR(EINVAL);
1986 1986
         }
1987 1987
     }
... ...
@@ -2046,7 +2036,7 @@ static int transcode_init(OutputFile *output_files,
2046 2046
             switch(codec->codec_type) {
2047 2047
             case AVMEDIA_TYPE_AUDIO:
2048 2048
                 if(audio_volume != 256) {
2049
-                    fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n");
2049
+                    av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
2050 2050
                     exit_program(1);
2051 2051
                 }
2052 2052
                 codec->channel_layout = icodec->channel_layout;
... ...
@@ -2120,7 +2110,7 @@ static int transcode_init(OutputFile *output_files,
2120 2120
                 choose_pixel_fmt(ost->st, ost->enc);
2121 2121
 
2122 2122
                 if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
2123
-                    fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
2123
+                    av_log(NULL, AV_LOG_FATAL, "Video pixel format is unknown, stream cannot be encoded\n");
2124 2124
                     exit_program(1);
2125 2125
                 }
2126 2126
 
... ...
@@ -2157,7 +2147,7 @@ static int transcode_init(OutputFile *output_files,
2157 2157
 
2158 2158
 #if CONFIG_AVFILTER
2159 2159
                 if (configure_video_filters(ist, ost)) {
2160
-                    fprintf(stderr, "Error opening filters!\n");
2160
+                    av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n");
2161 2161
                     exit(1);
2162 2162
                 }
2163 2163
 #endif
... ...
@@ -2182,7 +2172,8 @@ static int transcode_init(OutputFile *output_files,
2182 2182
                 if (codec->flags & CODEC_FLAG_PASS1) {
2183 2183
                     f = fopen(logfilename, "wb");
2184 2184
                     if (!f) {
2185
-                        fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
2185
+                        av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n",
2186
+                               logfilename, strerror(errno));
2186 2187
                         exit_program(1);
2187 2188
                     }
2188 2189
                     ost->logfile = f;
... ...
@@ -2190,7 +2181,8 @@ static int transcode_init(OutputFile *output_files,
2190 2190
                     char  *logbuffer;
2191 2191
                     size_t logbuffer_size;
2192 2192
                     if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
2193
-                        fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename);
2193
+                        av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
2194
+                               logfilename);
2194 2195
                         exit_program(1);
2195 2196
                     }
2196 2197
                     codec->stats_in = logbuffer;
... ...
@@ -2207,8 +2199,8 @@ static int transcode_init(OutputFile *output_files,
2207 2207
     if (!bit_buffer)
2208 2208
         bit_buffer = av_malloc(bit_buffer_size);
2209 2209
     if (!bit_buffer) {
2210
-        fprintf(stderr, "Cannot allocate %d bytes output buffer\n",
2211
-                bit_buffer_size);
2210
+        av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n",
2211
+               bit_buffer_size);
2212 2212
         return AVERROR(ENOMEM);
2213 2213
     }
2214 2214
 
... ...
@@ -2294,31 +2286,29 @@ static int transcode_init(OutputFile *output_files,
2294 2294
     }
2295 2295
 
2296 2296
     /* dump the stream mapping */
2297
-    if (verbose >= 0) {
2298
-        fprintf(stderr, "Stream mapping:\n");
2299
-        for (i = 0; i < nb_output_streams;i ++) {
2300
-            ost = &output_streams[i];
2301
-            fprintf(stderr, "  Stream #%d.%d -> #%d.%d",
2302
-                    input_streams[ost->source_index].file_index,
2303
-                    input_streams[ost->source_index].st->index,
2304
-                    ost->file_index,
2305
-                    ost->index);
2306
-            if (ost->sync_ist != &input_streams[ost->source_index])
2307
-                fprintf(stderr, " [sync #%d.%d]",
2308
-                        ost->sync_ist->file_index,
2309
-                        ost->sync_ist->st->index);
2310
-            if (ost->st->stream_copy)
2311
-                fprintf(stderr, " (copy)");
2312
-            else
2313
-                fprintf(stderr, " (%s -> %s)", input_streams[ost->source_index].dec ?
2314
-                        input_streams[ost->source_index].dec->name : "?",
2315
-                        ost->enc ? ost->enc->name : "?");
2316
-            fprintf(stderr, "\n");
2317
-        }
2297
+    av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
2298
+    for (i = 0; i < nb_output_streams; i++) {
2299
+        ost = &output_streams[i];
2300
+        av_log(NULL, AV_LOG_INFO, "  Stream #%d.%d -> #%d.%d",
2301
+               input_streams[ost->source_index].file_index,
2302
+               input_streams[ost->source_index].st->index,
2303
+               ost->file_index,
2304
+               ost->index);
2305
+        if (ost->sync_ist != &input_streams[ost->source_index])
2306
+            av_log(NULL, AV_LOG_INFO, " [sync #%d.%d]",
2307
+                   ost->sync_ist->file_index,
2308
+                   ost->sync_ist->st->index);
2309
+        if (ost->st->stream_copy)
2310
+            av_log(NULL, AV_LOG_INFO, " (copy)");
2311
+        else
2312
+            av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ?
2313
+                   input_streams[ost->source_index].dec->name : "?",
2314
+                   ost->enc ? ost->enc->name : "?");
2315
+        av_log(NULL, AV_LOG_INFO, "\n");
2318 2316
     }
2319 2317
 
2320 2318
     if (ret) {
2321
-        fprintf(stderr, "%s\n", error);
2319
+        av_log(NULL, AV_LOG_ERROR, "%s\n", error);
2322 2320
         return ret;
2323 2321
     }
2324 2322
 
... ...
@@ -2354,8 +2344,7 @@ static int transcode(OutputFile *output_files,
2354 2354
         goto fail;
2355 2355
 
2356 2356
     if (!using_stdin) {
2357
-        if(verbose >= 0)
2358
-            fprintf(stderr, "Press [q] to stop, [?] for help\n");
2357
+        av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
2359 2358
         avio_set_interrupt_cb(decode_interrupt_cb);
2360 2359
     }
2361 2360
     term_init();
... ...
@@ -2378,8 +2367,8 @@ static int transcode(OutputFile *output_files,
2378 2378
             key = read_key();
2379 2379
             if (key == 'q')
2380 2380
                 break;
2381
-            if (key == '+') verbose++;
2382
-            if (key == '-') verbose--;
2381
+            if (key == '+') av_log_set_level(av_log_get_level()+10);
2382
+            if (key == '-') av_log_set_level(av_log_get_level()-10);
2383 2383
             if (key == 's') qp_hist     ^= 1;
2384 2384
             if (key == 'h'){
2385 2385
                 if (do_hex_dump){
... ...
@@ -2515,9 +2504,8 @@ static int transcode(OutputFile *output_files,
2515 2515
             int64_t delta= pkt_dts - ist->next_pts;
2516 2516
             if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){
2517 2517
                 input_files[ist->file_index].ts_offset -= delta;
2518
-                if (verbose > 2)
2519
-                    fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
2520
-                            delta, input_files[ist->file_index].ts_offset);
2518
+                av_log(NULL, AV_LOG_DEBUG, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
2519
+                       delta, input_files[ist->file_index].ts_offset);
2521 2520
                 pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
2522 2521
                 if(pkt.pts != AV_NOPTS_VALUE)
2523 2522
                     pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
... ...
@@ -2527,9 +2515,8 @@ static int transcode(OutputFile *output_files,
2527 2527
         //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size);
2528 2528
         if (output_packet(ist, ist_index, output_streams, nb_output_streams, &pkt) < 0) {
2529 2529
 
2530
-            if (verbose >= 0)
2531
-                fprintf(stderr, "Error while decoding stream #%d.%d\n",
2532
-                        ist->file_index, ist->st->index);
2530
+            av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d.%d\n",
2531
+                   ist->file_index, ist->st->index);
2533 2532
             if (exit_on_error)
2534 2533
                 exit_program(1);
2535 2534
             av_free_packet(&pkt);
... ...
@@ -2620,7 +2607,7 @@ static int transcode(OutputFile *output_files,
2620 2620
 
2621 2621
 static int opt_verbose(const char *opt, const char *arg)
2622 2622
 {
2623
-    verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10);
2623
+    av_log(NULL, AV_LOG_WARNING, "-%s is deprecated, use -loglevel\n", opt);
2624 2624
     return 0;
2625 2625
 }
2626 2626
 
... ...
@@ -2642,7 +2629,7 @@ static double parse_frame_aspect_ratio(const char *arg)
2642 2642
         ar = strtod(arg, NULL);
2643 2643
 
2644 2644
     if (!ar) {
2645
-        fprintf(stderr, "Incorrect aspect ratio specification.\n");
2645
+        av_log(NULL, AV_LOG_FATAL, "Incorrect aspect ratio specification.\n");
2646 2646
         exit_program(1);
2647 2647
     }
2648 2648
     return ar;
... ...
@@ -2687,7 +2674,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2687 2687
         *sync = 0;
2688 2688
         sync_file_idx = strtol(sync + 1, &sync, 0);
2689 2689
         if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
2690
-            av_log(NULL, AV_LOG_ERROR, "Invalid sync file index: %d.\n", sync_file_idx);
2690
+            av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
2691 2691
             exit_program(1);
2692 2692
         }
2693 2693
         if (*sync)
... ...
@@ -2699,7 +2686,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2699 2699
                 break;
2700 2700
             }
2701 2701
         if (i == input_files[sync_file_idx].nb_streams) {
2702
-            av_log(NULL, AV_LOG_ERROR, "Sync stream specification in map %s does not "
2702
+            av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
2703 2703
                                        "match any streams.\n", arg);
2704 2704
             exit_program(1);
2705 2705
         }
... ...
@@ -2708,7 +2695,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2708 2708
 
2709 2709
     file_idx = strtol(map, &p, 0);
2710 2710
     if (file_idx >= nb_input_files || file_idx < 0) {
2711
-        av_log(NULL, AV_LOG_ERROR, "Invalid input file index: %d.\n", file_idx);
2711
+        av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
2712 2712
         exit_program(1);
2713 2713
     }
2714 2714
     if (negative)
... ...
@@ -2742,7 +2729,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2742 2742
         }
2743 2743
 
2744 2744
     if (!m) {
2745
-        av_log(NULL, AV_LOG_ERROR, "Stream map '%s' matches no streams.\n", arg);
2745
+        av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n", arg);
2746 2746
         exit_program(1);
2747 2747
     }
2748 2748
 
... ...
@@ -2764,7 +2751,7 @@ static void parse_meta_type(char *arg, char *type, int *index)
2764 2764
                 *index = strtol(++arg, NULL, 0);
2765 2765
             break;
2766 2766
         default:
2767
-            fprintf(stderr, "Invalid metadata type %c.\n", *arg);
2767
+            av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
2768 2768
             exit_program(1);
2769 2769
         }
2770 2770
     } else
... ...
@@ -2810,11 +2797,11 @@ static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, i
2810 2810
         avcodec_find_encoder_by_name(name) :
2811 2811
         avcodec_find_decoder_by_name(name);
2812 2812
     if(!codec) {
2813
-        av_log(NULL, AV_LOG_ERROR, "Unknown %s '%s'\n", codec_string, name);
2813
+        av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
2814 2814
         exit_program(1);
2815 2815
     }
2816 2816
     if(codec->type != type) {
2817
-        av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name);
2817
+        av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
2818 2818
         exit_program(1);
2819 2819
     }
2820 2820
     return codec->id;
... ...
@@ -2888,11 +2875,9 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
2888 2888
 
2889 2889
             if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
2890 2890
 
2891
-                if (verbose >= 0)
2892
-                    fprintf(stderr,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
2893
-                            i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
2894
-
2895
-                    (float)rfps / rfps_base, rfps, rfps_base);
2891
+                av_log(NULL, AV_LOG_INFO,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
2892
+                       i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
2893
+                       (float)rfps / rfps_base, rfps, rfps_base);
2896 2894
             }
2897 2895
 
2898 2896
             if (o->video_disable)
... ...
@@ -2929,7 +2914,7 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
2929 2929
 
2930 2930
     if (o->format) {
2931 2931
         if (!(file_iformat = av_find_input_format(o->format))) {
2932
-            fprintf(stderr, "Unknown input format: '%s'\n", o->format);
2932
+            av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
2933 2933
             exit_program(1);
2934 2934
         }
2935 2935
     }
... ...
@@ -2984,8 +2969,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
2984 2984
     /* If not enough info to get the stream parameters, we decode the
2985 2985
        first frames to get it. (used in mpeg case for example) */
2986 2986
     ret = avformat_find_stream_info(ic, opts);
2987
-    if (ret < 0 && verbose >= 0) {
2988
-        fprintf(stderr, "%s: could not find codec parameters\n", filename);
2987
+    if (ret < 0) {
2988
+        av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
2989 2989
         av_close_input_file(ic);
2990 2990
         exit_program(1);
2991 2991
     }
... ...
@@ -2999,8 +2984,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
2999 2999
     if (o->start_time != 0) {
3000 3000
         ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
3001 3001
         if (ret < 0) {
3002
-            fprintf(stderr, "%s: could not seek to position %0.3f\n",
3003
-                    filename, (double)timestamp / AV_TIME_BASE);
3002
+            av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
3003
+                   filename, (double)timestamp / AV_TIME_BASE);
3004 3004
         }
3005 3005
     }
3006 3006
 
... ...
@@ -3008,8 +2993,7 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
3008 3008
     add_input_streams(o, ic);
3009 3009
 
3010 3010
     /* dump the file content */
3011
-    if (verbose >= 0)
3012
-        av_dump_format(ic, nb_input_files, filename, 0);
3011
+    av_dump_format(ic, nb_input_files, filename, 0);
3013 3012
 
3014 3013
     input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
3015 3014
     input_files[nb_input_files - 1].ctx        = ic;
... ...
@@ -3060,7 +3044,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
3060 3060
     double qscale = -1;
3061 3061
 
3062 3062
     if (!st) {
3063
-        av_log(NULL, AV_LOG_ERROR, "Could not alloc stream.\n");
3063
+        av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
3064 3064
         exit_program(1);
3065 3065
     }
3066 3066
 
... ...
@@ -3087,7 +3071,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
3087 3087
         if (next = strchr(bsf, ','))
3088 3088
             *next++ = 0;
3089 3089
         if (!(bsfc = av_bitstream_filter_init(bsf))) {
3090
-            av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter %s\n", bsf);
3090
+            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
3091 3091
             exit_program(1);
3092 3092
         }
3093 3093
         if (bsfc_prev)
... ...
@@ -3127,7 +3111,7 @@ static void parse_matrix_coeffs(uint16_t *dest, const char *str)
3127 3127
             break;
3128 3128
         p = strchr(p, ',');
3129 3129
         if(!p) {
3130
-            fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
3130
+            av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
3131 3131
             exit_program(1);
3132 3132
         }
3133 3133
         p++;
... ...
@@ -3157,13 +3141,13 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3157 3157
 
3158 3158
         MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
3159 3159
         if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
3160
-            av_log(NULL, AV_LOG_ERROR, "Invalid framerate value: %s\n", frame_rate);
3160
+            av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
3161 3161
             exit_program(1);
3162 3162
         }
3163 3163
 
3164 3164
         MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
3165 3165
         if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
3166
-            av_log(NULL, AV_LOG_ERROR, "Invalid frame size: %s.\n", frame_size);
3166
+            av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
3167 3167
             exit_program(1);
3168 3168
         }
3169 3169
 
... ...
@@ -3173,7 +3157,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3173 3173
 
3174 3174
         MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
3175 3175
         if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {
3176
-            av_log(NULL, AV_LOG_ERROR, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
3176
+            av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
3177 3177
             exit_program(1);
3178 3178
         }
3179 3179
         st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
... ...
@@ -3181,7 +3165,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3181 3181
         MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
3182 3182
         if (intra_matrix) {
3183 3183
             if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
3184
-                av_log(NULL, AV_LOG_ERROR, "Could not allocate memory for intra matrix.\n");
3184
+                av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
3185 3185
                 exit_program(1);
3186 3186
             }
3187 3187
             parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
... ...
@@ -3189,7 +3173,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3189 3189
         MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
3190 3190
         if (inter_matrix) {
3191 3191
             if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
3192
-                av_log(NULL, AV_LOG_ERROR, "Could not allocate memory for inter matrix.\n");
3192
+                av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
3193 3193
                 exit_program(1);
3194 3194
             }
3195 3195
             parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
... ...
@@ -3200,7 +3184,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3200 3200
             int start, end, q;
3201 3201
             int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
3202 3202
             if(e!=3){
3203
-                fprintf(stderr, "error parsing rc_override\n");
3203
+                av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
3204 3204
                 exit_program(1);
3205 3205
             }
3206 3206
             video_enc->rc_override=
... ...
@@ -3276,7 +3260,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
3276 3276
         MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
3277 3277
         if (sample_fmt &&
3278 3278
             (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
3279
-            av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", sample_fmt);
3279
+            av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
3280 3280
             exit_program(1);
3281 3281
         }
3282 3282
 
... ...
@@ -3296,7 +3280,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc)
3296 3296
     st  = ost->st;
3297 3297
     data_enc = st->codec;
3298 3298
     if (!st->stream_copy) {
3299
-        fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n");
3299
+        av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
3300 3300
         exit_program(1);
3301 3301
     }
3302 3302
 
... ...
@@ -3336,9 +3320,9 @@ static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)
3336 3336
     av_strlcpy(idx_str, arg, sizeof(idx_str));
3337 3337
     p = strchr(idx_str, ':');
3338 3338
     if (!p) {
3339
-        fprintf(stderr,
3340
-                "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
3341
-                arg, opt);
3339
+        av_log(NULL, AV_LOG_FATAL,
3340
+               "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
3341
+               arg, opt);
3342 3342
         exit_program(1);
3343 3343
     }
3344 3344
     *p++ = '\0';
... ...
@@ -3512,7 +3496,7 @@ static void opt_output_file(void *optctx, const char *filename)
3512 3512
             case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
3513 3513
             case AVMEDIA_TYPE_DATA:     ost = new_data_stream(o, oc);     break;
3514 3514
             default:
3515
-                av_log(NULL, AV_LOG_ERROR, "Cannot map stream #%d.%d - unsupported type.\n",
3515
+                av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\n",
3516 3516
                        map->file_index, map->stream_index);
3517 3517
                 exit_program(1);
3518 3518
             }
... ...
@@ -3583,7 +3567,7 @@ static void opt_output_file(void *optctx, const char *filename)
3583 3583
                     break;
3584 3584
                 }
3585 3585
         } else {
3586
-            av_log(NULL, AV_LOG_ERROR, "Invalid input file index %d in chapter mapping.\n",
3586
+            av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
3587 3587
                    o->chapters_input_file);
3588 3588
             exit_program(1);
3589 3589
         }
... ...
@@ -3600,7 +3584,7 @@ static void opt_output_file(void *optctx, const char *filename)
3600 3600
 
3601 3601
 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
3602 3602
         if ((index) < 0 || (index) >= (nb_elems)) {\
3603
-            av_log(NULL, AV_LOG_ERROR, "Invalid %s index %d while processing metadata maps\n",\
3603
+            av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\n",\
3604 3604
                      (desc), (index));\
3605 3605
             exit_program(1);\
3606 3606
         }
... ...
@@ -3656,7 +3640,7 @@ static void opt_output_file(void *optctx, const char *filename)
3656 3656
 
3657 3657
         val = strchr(o->metadata[i].u.str, '=');
3658 3658
         if (!val) {
3659
-            av_log(NULL, AV_LOG_ERROR, "No '=' character in metadata string %s.\n",
3659
+            av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
3660 3660
                    o->metadata[i].u.str);
3661 3661
             exit_program(1);
3662 3662
         }
... ...
@@ -3669,20 +3653,20 @@ static void opt_output_file(void *optctx, const char *filename)
3669 3669
             break;
3670 3670
         case 's':
3671 3671
             if (index < 0 || index >= oc->nb_streams) {
3672
-                av_log(NULL, AV_LOG_ERROR, "Invalid stream index %d in metadata specifier.\n", index);
3672
+                av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\n", index);
3673 3673
                 exit_program(1);
3674 3674
             }
3675 3675
             m = &oc->streams[index]->metadata;
3676 3676
             break;
3677 3677
         case 'c':
3678 3678
             if (index < 0 || index >= oc->nb_chapters) {
3679
-                av_log(NULL, AV_LOG_ERROR, "Invalid chapter index %d in metadata specifier.\n", index);
3679
+                av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
3680 3680
                 exit_program(1);
3681 3681
             }
3682 3682
             m = &oc->chapters[index]->metadata;
3683 3683
             break;
3684 3684
         default:
3685
-            av_log(NULL, AV_LOG_ERROR, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
3685
+            av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
3686 3686
             exit_program(1);
3687 3687
         }
3688 3688
 
... ...
@@ -3854,14 +3838,14 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
3854 3854
                     break;
3855 3855
             }
3856 3856
         }
3857
-        if(verbose > 0 && norm != UNKNOWN)
3858
-            fprintf(stderr, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
3857
+        if (norm != UNKNOWN)
3858
+            av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
3859 3859
     }
3860 3860
 
3861 3861
     if(norm == UNKNOWN) {
3862
-        fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
3863
-        fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
3864
-        fprintf(stderr, "or set a framerate with \"-r xxx\".\n");
3862
+        av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
3863
+        av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
3864
+        av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
3865 3865
         exit_program(1);
3866 3866
     }
3867 3867
 
... ...
@@ -3948,7 +3932,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
3948 3948
         parse_option(o, "ac", "2", options);
3949 3949
 
3950 3950
     } else {
3951
-        fprintf(stderr, "Unknown target: %s\n", arg);
3951
+        av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
3952 3952
         return AVERROR(EINVAL);
3953 3953
     }
3954 3954
     return 0;
... ...
@@ -4049,7 +4033,7 @@ static const OptionDef options[] = {
4049 4049
     { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
4050 4050
       "when dumping packets, also dump the payload" },
4051 4051
     { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(rate_emu)}, "read input at native frame rate", "" },
4052
-    { "v", HAS_ARG, {(void*)opt_verbose}, "set the verbosity level", "number" },
4052
+    { "v", HAS_ARG, {(void*)opt_verbose}, "deprecated, use -loglevel instead", "number" },
4053 4053
     { "target", HAS_ARG | OPT_FUNC2, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
4054 4054
     { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
4055 4055
     { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
... ...
@@ -4140,10 +4124,10 @@ int main(int argc, char **argv)
4140 4140
     reset_options(&o);
4141 4141
 
4142 4142
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
4143
+    parse_loglevel(argc, argv, options);
4143 4144
 
4144 4145
     if(argc>1 && !strcmp(argv[1], "-d")){
4145 4146
         run_as_daemon=1;
4146
-        verbose=-1;
4147 4147
         av_log_set_callback(log_callback_null);
4148 4148
         argc--;
4149 4149
         argv++;
... ...
@@ -4163,15 +4147,14 @@ int main(int argc, char **argv)
4163 4163
         avio_set_interrupt_cb(decode_interrupt_cb);
4164 4164
 #endif
4165 4165
 
4166
-    if(verbose>=0)
4167
-        show_banner();
4166
+    show_banner();
4168 4167
 
4169 4168
     /* parse options */
4170 4169
     parse_options(&o, argc, argv, options, opt_output_file);
4171 4170
 
4172 4171
     if(nb_output_files <= 0 && nb_input_files == 0) {
4173 4172
         show_usage();
4174
-        fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
4173
+        av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
4175 4174
         exit_program(1);
4176 4175
     }
4177 4176
 
... ...
@@ -4182,7 +4165,7 @@ int main(int argc, char **argv)
4182 4182
     }
4183 4183
 
4184 4184
     if (nb_input_files == 0) {
4185
-        fprintf(stderr, "At least one input file must be specified\n");
4185
+        av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
4186 4186
         exit_program(1);
4187 4187
     }
4188 4188
 
... ...
@@ -91,7 +91,7 @@ double parse_number_or_die(const char *context, const char *numstr, int type, do
91 91
         error= "Expected int for %s but found %s\n";
92 92
     else
93 93
         return d;
94
-    fprintf(stderr, error, context, numstr, min, max);
94
+    av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
95 95
     exit_program(1);
96 96
     return 0;
97 97
 }
... ...
@@ -100,8 +100,8 @@ int64_t parse_time_or_die(const char *context, const char *timestr, int is_durat
100 100
 {
101 101
     int64_t us;
102 102
     if (av_parse_time(&us, timestr, is_duration) < 0) {
103
-        fprintf(stderr, "Invalid %s specification for %s: %s\n",
104
-                is_duration ? "duration" : "date", context, timestr);
103
+        av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
104
+               is_duration ? "duration" : "date", context, timestr);
105 105
         exit_program(1);
106 106
     }
107 107
     return us;
... ...
@@ -305,6 +305,41 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
305 305
     }
306 306
 }
307 307
 
308
+/*
309
+ * Return index of option opt in argv or 0 if not found.
310
+ */
311
+static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
312
+{
313
+    const OptionDef *po;
314
+    int i;
315
+
316
+    for (i = 1; i < argc; i++) {
317
+        const char *cur_opt = argv[i];
318
+
319
+        if (*cur_opt++ != '-')
320
+            continue;
321
+
322
+        po = find_option(options, cur_opt);
323
+        if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
324
+            po = find_option(options, cur_opt + 2);
325
+
326
+        if ((!po->name && !strcmp(cur_opt, optname)) ||
327
+             (po->name && !strcmp(optname, po->name)))
328
+            return i;
329
+
330
+        if (!po || po->flags & HAS_ARG)
331
+            i++;
332
+    }
333
+    return 0;
334
+}
335
+
336
+void parse_loglevel(int argc, char **argv, const OptionDef *options)
337
+{
338
+    int idx = locate_option(argc, argv, options, "loglevel");
339
+    if (idx && argv[idx + 1])
340
+        opt_loglevel("loglevel", argv[idx + 1]);
341
+}
342
+
308 343
 #define FLAGS(o) ((o)->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
309 344
 int opt_default(const char *opt, const char *arg)
310 345
 {
... ...
@@ -337,7 +372,7 @@ int opt_default(const char *opt, const char *arg)
337 337
 
338 338
     if (oc || of || os)
339 339
         return 0;
340
-    fprintf(stderr, "Unrecognized option '%s'\n", opt);
340
+    av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
341 341
     return AVERROR_OPTION_NOT_FOUND;
342 342
 }
343 343
 
... ...
@@ -366,10 +401,10 @@ int opt_loglevel(const char *opt, const char *arg)
366 366
 
367 367
     level = strtol(arg, &tail, 10);
368 368
     if (*tail) {
369
-        fprintf(stderr, "Invalid loglevel \"%s\". "
370
-                        "Possible levels are numbers or:\n", arg);
369
+        av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
370
+               "Possible levels are numbers or:\n", arg);
371 371
         for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
372
-            fprintf(stderr, "\"%s\"\n", log_levels[i].name);
372
+            av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
373 373
         exit_program(1);
374 374
     }
375 375
     av_log_set_level(level);
... ...
@@ -384,7 +419,7 @@ int opt_timelimit(const char *opt, const char *arg)
384 384
     if (setrlimit(RLIMIT_CPU, &rl))
385 385
         perror("setrlimit");
386 386
 #else
387
-    fprintf(stderr, "Warning: -%s not implemented on this OS\n", opt);
387
+    av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
388 388
 #endif
389 389
     return 0;
390 390
 }
... ...
@@ -396,7 +431,7 @@ void print_error(const char *filename, int err)
396 396
 
397 397
     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
398 398
         errbuf_ptr = strerror(AVUNERROR(err));
399
-    fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);
399
+    av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
400 400
 }
401 401
 
402 402
 static int warned_cfg = 0;
... ...
@@ -405,58 +440,59 @@ static int warned_cfg = 0;
405 405
 #define SHOW_VERSION  2
406 406
 #define SHOW_CONFIG   4
407 407
 
408
-#define PRINT_LIB_INFO(outstream,libname,LIBNAME,flags)                 \
408
+#define PRINT_LIB_INFO(libname, LIBNAME, flags, level)                  \
409 409
     if (CONFIG_##LIBNAME) {                                             \
410 410
         const char *indent = flags & INDENT? "  " : "";                 \
411 411
         if (flags & SHOW_VERSION) {                                     \
412 412
             unsigned int version = libname##_version();                 \
413
-            fprintf(outstream, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n", \
414
-                    indent, #libname,                                   \
415
-                    LIB##LIBNAME##_VERSION_MAJOR,                       \
416
-                    LIB##LIBNAME##_VERSION_MINOR,                       \
417
-                    LIB##LIBNAME##_VERSION_MICRO,                       \
418
-                    version >> 16, version >> 8 & 0xff, version & 0xff); \
413
+            av_log(NULL, level, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n",\
414
+                   indent, #libname,                                    \
415
+                   LIB##LIBNAME##_VERSION_MAJOR,                        \
416
+                   LIB##LIBNAME##_VERSION_MINOR,                        \
417
+                   LIB##LIBNAME##_VERSION_MICRO,                        \
418
+                   version >> 16, version >> 8 & 0xff, version & 0xff); \
419 419
         }                                                               \
420 420
         if (flags & SHOW_CONFIG) {                                      \
421 421
             const char *cfg = libname##_configuration();                \
422 422
             if (strcmp(FFMPEG_CONFIGURATION, cfg)) {                    \
423 423
                 if (!warned_cfg) {                                      \
424
-                    fprintf(outstream,                                  \
424
+                    av_log(NULL, level,                                 \
425 425
                             "%sWARNING: library configuration mismatch\n", \
426 426
                             indent);                                    \
427 427
                     warned_cfg = 1;                                     \
428 428
                 }                                                       \
429
-                fprintf(stderr, "%s%-11s configuration: %s\n",          \
429
+                av_log(NULL, level, "%s%-11s configuration: %s\n",      \
430 430
                         indent, #libname, cfg);                         \
431 431
             }                                                           \
432 432
         }                                                               \
433 433
     }                                                                   \
434 434
 
435
-static void print_all_libs_info(FILE* outstream, int flags)
435
+static void print_all_libs_info(int flags, int level)
436 436
 {
437
-    PRINT_LIB_INFO(outstream, avutil,   AVUTIL,   flags);
438
-    PRINT_LIB_INFO(outstream, avcodec,  AVCODEC,  flags);
439
-    PRINT_LIB_INFO(outstream, avformat, AVFORMAT, flags);
440
-    PRINT_LIB_INFO(outstream, avdevice, AVDEVICE, flags);
441
-    PRINT_LIB_INFO(outstream, avfilter, AVFILTER, flags);
442
-    PRINT_LIB_INFO(outstream, swscale,  SWSCALE,  flags);
443
-    PRINT_LIB_INFO(outstream, postproc, POSTPROC, flags);
437
+    PRINT_LIB_INFO(avutil,   AVUTIL,   flags, level);
438
+    PRINT_LIB_INFO(avcodec,  AVCODEC,  flags, level);
439
+    PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
440
+    PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
441
+    PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
442
+    PRINT_LIB_INFO(swscale,  SWSCALE,  flags, level);
443
+    PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
444 444
 }
445 445
 
446 446
 void show_banner(void)
447 447
 {
448
-    fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
449
-            program_name, program_birth_year, this_year);
450
-    fprintf(stderr, "  built on %s %s with %s %s\n",
451
-            __DATE__, __TIME__, CC_TYPE, CC_VERSION);
452
-    fprintf(stderr, "  configuration: " FFMPEG_CONFIGURATION "\n");
453
-    print_all_libs_info(stderr, INDENT|SHOW_CONFIG);
454
-    print_all_libs_info(stderr, INDENT|SHOW_VERSION);
448
+    av_log(NULL, AV_LOG_INFO, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
449
+           program_name, program_birth_year, this_year);
450
+    av_log(NULL, AV_LOG_INFO, "  built on %s %s with %s %s\n",
451
+           __DATE__, __TIME__, CC_TYPE, CC_VERSION);
452
+    av_log(NULL, AV_LOG_VERBOSE, "  configuration: " FFMPEG_CONFIGURATION "\n");
453
+    print_all_libs_info(INDENT|SHOW_CONFIG,  AV_LOG_VERBOSE);
454
+    print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_VERBOSE);
455 455
 }
456 456
 
457 457
 int opt_version(const char *opt, const char *arg) {
458
+    av_log_set_callback(log_callback_help);
458 459
     printf("%s " FFMPEG_VERSION "\n", program_name);
459
-    print_all_libs_info(stdout, SHOW_VERSION);
460
+    print_all_libs_info(SHOW_VERSION, AV_LOG_INFO);
460 461
     return 0;
461 462
 }
462 463
 
... ...
@@ -758,7 +794,7 @@ int read_file(const char *filename, char **bufptr, size_t *size)
758 758
     FILE *f = fopen(filename, "rb");
759 759
 
760 760
     if (!f) {
761
-        fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno));
761
+        av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, strerror(errno));
762 762
         return AVERROR(errno);
763 763
     }
764 764
     fseek(f, 0, SEEK_END);
... ...
@@ -766,7 +802,7 @@ int read_file(const char *filename, char **bufptr, size_t *size)
766 766
     fseek(f, 0, SEEK_SET);
767 767
     *bufptr = av_malloc(*size + 1);
768 768
     if (!*bufptr) {
769
-        fprintf(stderr, "Could not allocate file buffer\n");
769
+        av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
770 770
         fclose(f);
771 771
         return AVERROR(ENOMEM);
772 772
     }
... ...
@@ -179,6 +179,11 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
179 179
 int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options);
180 180
 
181 181
 /**
182
+ * Find the '-loglevel' option in the commandline args and apply it.
183
+ */
184
+void parse_loglevel(int argc, char **argv, const OptionDef *options);
185
+
186
+/**
182 187
  * Check if the given stream matches a stream specifier.
183 188
  *
184 189
  * @param s  Corresponding format context.
... ...
@@ -1630,11 +1630,14 @@ test_deps(){
1630 1630
         dep=${v%=*}
1631 1631
         tests=${v#*=}
1632 1632
         for name in ${tests}; do
1633
-            eval ${name}_test_deps="'${dep}$suf1 ${dep}$suf2'"
1633
+            append ${name}_test_deps ${dep}$suf1 ${dep}$suf2
1634 1634
         done
1635 1635
     done
1636 1636
 }
1637 1637
 
1638
+mxf_d10_test_deps="avfilter"
1639
+seek_lavf_mxf_d10_test_deps="mxf_d10_test"
1640
+
1638 1641
 test_deps _encoder _decoder                                             \
1639 1642
     adpcm_g726=g726                                                     \
1640 1643
     adpcm_ima_qt                                                        \
... ...
@@ -154,7 +154,8 @@ avconv -i INPUT -metadata:s:1 language=eng OUTPUT
154 154
 @end example
155 155
 
156 156
 @item -v @var{number} (@emph{global})
157
-Set the logging verbosity level.
157
+This option is deprecated and has no effect, use -loglevel
158
+to set verbosity level.
158 159
 
159 160
 @item -target @var{type} (@emph{output})
160 161
 Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd",
... ...
@@ -145,7 +145,6 @@ static int audio_volume = 256;
145 145
 
146 146
 static int exit_on_error = 0;
147 147
 static int using_stdin = 0;
148
-static int verbose = 1;
149 148
 static int run_as_daemon  = 0;
150 149
 static int q_pressed = 0;
151 150
 static int64_t video_size = 0;
... ...
@@ -659,9 +658,8 @@ void exit_program(int ret)
659 659
     av_freep(&input_tmp);
660 660
 
661 661
     if (received_sigterm) {
662
-        fprintf(stderr,
663
-            "Received signal %d: terminating.\n",
664
-            (int) received_sigterm);
662
+        av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n",
663
+               (int) received_sigterm);
665 664
         exit (255);
666 665
     }
667 666
 
... ...
@@ -672,7 +670,7 @@ static void assert_avoptions(AVDictionary *m)
672 672
 {
673 673
     AVDictionaryEntry *t;
674 674
     if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
675
-        av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
675
+        av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
676 676
         exit_program(1);
677 677
     }
678 678
 }
... ...
@@ -683,12 +681,12 @@ static void assert_codec_experimental(AVCodecContext *c, int encoder)
683 683
     AVCodec *codec;
684 684
     if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
685 685
         c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
686
-        av_log(NULL, AV_LOG_ERROR, "%s '%s' is experimental and might produce bad "
686
+        av_log(NULL, AV_LOG_FATAL, "%s '%s' is experimental and might produce bad "
687 687
                 "results.\nAdd '-strict experimental' if you want to use it.\n",
688 688
                 codec_string, c->codec->name);
689 689
         codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id);
690 690
         if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))
691
-            av_log(NULL, AV_LOG_ERROR, "Or use the non experimental %s '%s'.\n",
691
+            av_log(NULL, AV_LOG_FATAL, "Or use the non experimental %s '%s'.\n",
692 692
                    codec_string, codec->name);
693 693
         exit_program(1);
694 694
     }
... ...
@@ -784,9 +782,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx
784 784
             av_free_packet(pkt);
785 785
             new_pkt.destruct= av_destruct_packet;
786 786
         } else if(a<0){
787
-            fprintf(stderr, "%s failed for stream %d, codec %s",
788
-                    bsfc->filter->name, pkt->stream_index,
789
-                    avctx->codec ? avctx->codec->name : "copy");
787
+            av_log(NULL, AV_LOG_ERROR, "%s failed for stream %d, codec %s",
788
+                   bsfc->filter->name, pkt->stream_index,
789
+                   avctx->codec ? avctx->codec->name : "copy");
790 790
             print_error("", a);
791 791
             if (exit_on_error)
792 792
                 exit_program(1);
... ...
@@ -832,14 +830,14 @@ need_realloc:
832 832
     audio_out_size += FF_MIN_BUFFER_SIZE;
833 833
 
834 834
     if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){
835
-        fprintf(stderr, "Buffer sizes too large\n");
835
+        av_log(NULL, AV_LOG_FATAL, "Buffer sizes too large\n");
836 836
         exit_program(1);
837 837
     }
838 838
 
839 839
     av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size);
840 840
     av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size);
841 841
     if (!audio_buf || !audio_out){
842
-        fprintf(stderr, "Out of memory in do_audio_out\n");
842
+        av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n");
843 843
         exit_program(1);
844 844
     }
845 845
 
... ...
@@ -878,12 +876,12 @@ need_realloc:
878 878
             av_set_int(ost->swr, "och", enc->channels);
879 879
             if(audio_sync_method>1) av_set_int(ost->swr, "flags", SWR_FLAG_RESAMPLE);
880 880
             if(ost->swr && swr_init(ost->swr) < 0){
881
-                fprintf(stderr, "swr_init() failed\n");
881
+                av_log(NULL, AV_LOG_FATAL, "swr_init() failed\n");
882 882
                 swr_free(&ost->swr);
883 883
             }
884 884
 
885 885
             if (!ost->swr) {
886
-                fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
886
+                av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
887 887
                         dec->channels, dec->sample_rate,
888 888
                         enc->channels, enc->sample_rate);
889 889
                 exit_program(1);
... ...
@@ -906,8 +904,7 @@ need_realloc:
906 906
                     byte_delta= FFMAX(byte_delta, -size);
907 907
                     size += byte_delta;
908 908
                     buf  -= byte_delta;
909
-                    if(verbose > 2)
910
-                        fprintf(stderr, "discarding %d audio samples\n", (int)-delta);
909
+                    av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n", (int)-delta);
911 910
                     if(!size)
912 911
                         return;
913 912
                     ist->is_start=0;
... ...
@@ -924,14 +921,13 @@ need_realloc:
924 924
                     memcpy(input_tmp + byte_delta, buf, size);
925 925
                     buf= input_tmp;
926 926
                     size += byte_delta;
927
-                    if(verbose > 2)
928
-                        fprintf(stderr, "adding %d audio samples of silence\n", (int)delta);
927
+                    av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", (int)delta);
929 928
                 }
930 929
             }else if(audio_sync_method>1){
931 930
                 int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
932 931
                 av_assert0(ost->audio_resample);
933
-                if(verbose > 2)
934
-                    fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
932
+                av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
933
+                       delta, comp, enc->sample_rate);
935 934
 //                fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
936 935
                 swr_compensate(ost->swr, comp, enc->sample_rate);
937 936
             }
... ...
@@ -956,7 +952,7 @@ need_realloc:
956 956
     if (enc->frame_size > 1) {
957 957
         /* output resampled raw samples */
958 958
         if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) {
959
-            fprintf(stderr, "av_fifo_realloc2() failed\n");
959
+            av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n");
960 960
             exit_program(1);
961 961
         }
962 962
         av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL);
... ...
@@ -974,7 +970,7 @@ need_realloc:
974 974
             ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
975 975
                                        (short *)audio_buf);
976 976
             if (ret < 0) {
977
-                fprintf(stderr, "Audio encoding failed\n");
977
+                av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
978 978
                 exit_program(1);
979 979
             }
980 980
             audio_size += ret;
... ...
@@ -1001,7 +997,7 @@ need_realloc:
1001 1001
             size_out = size_out*coded_bps/8;
1002 1002
 
1003 1003
         if(size_out > audio_out_size){
1004
-            fprintf(stderr, "Internal error, buffer size too small\n");
1004
+            av_log(NULL, AV_LOG_FATAL, "Internal error, buffer size too small\n");
1005 1005
             exit_program(1);
1006 1006
         }
1007 1007
 
... ...
@@ -1009,7 +1005,7 @@ need_realloc:
1009 1009
         ret = avcodec_encode_audio(enc, audio_out, size_out,
1010 1010
                                    (short *)buftmp);
1011 1011
         if (ret < 0) {
1012
-            fprintf(stderr, "Audio encoding failed\n");
1012
+            av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
1013 1013
             exit_program(1);
1014 1014
         }
1015 1015
         audio_size += ret;
... ...
@@ -1048,7 +1044,7 @@ static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void *
1048 1048
         if(avpicture_deinterlace(picture2, picture,
1049 1049
                                  dec->pix_fmt, dec->width, dec->height) < 0) {
1050 1050
             /* if error, do not deinterlace */
1051
-            fprintf(stderr, "Deinterlacing failed\n");
1051
+            av_log(NULL, AV_LOG_WARNING, "Deinterlacing failed\n");
1052 1052
             av_free(buf);
1053 1053
             buf = NULL;
1054 1054
             picture2 = picture;
... ...
@@ -1075,7 +1071,7 @@ static void do_subtitle_out(AVFormatContext *s,
1075 1075
     AVPacket pkt;
1076 1076
 
1077 1077
     if (pts == AV_NOPTS_VALUE) {
1078
-        fprintf(stderr, "Subtitle packets must have a pts\n");
1078
+        av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
1079 1079
         if (exit_on_error)
1080 1080
             exit_program(1);
1081 1081
         return;
... ...
@@ -1104,7 +1100,7 @@ static void do_subtitle_out(AVFormatContext *s,
1104 1104
         subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
1105 1105
                                                     subtitle_out_max_size, sub);
1106 1106
         if (subtitle_out_size < 0) {
1107
-            fprintf(stderr, "Subtitle encoding failed\n");
1107
+            av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
1108 1108
             exit_program(1);
1109 1109
         }
1110 1110
 
... ...
@@ -1166,7 +1162,7 @@ static void do_video_resample(OutputStream *ost,
1166 1166
                 avcodec_get_frame_defaults(&ost->resample_frame);
1167 1167
                 if (avpicture_alloc((AVPicture *)&ost->resample_frame, enc->pix_fmt,
1168 1168
                                     enc->width, enc->height)) {
1169
-                    fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
1169
+                    av_log(NULL, AV_LOG_FATAL, "Cannot allocate temp picture, check pix fmt\n");
1170 1170
                     exit_program(1);
1171 1171
                 }
1172 1172
             }
... ...
@@ -1176,7 +1172,7 @@ static void do_video_resample(OutputStream *ost,
1176 1176
                                                    enc->width, enc->height, enc->pix_fmt,
1177 1177
                                                    ost->sws_flags, NULL, NULL, NULL);
1178 1178
             if (ost->img_resample_ctx == NULL) {
1179
-                fprintf(stderr, "Cannot get resampling context\n");
1179
+                av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n");
1180 1180
                 exit_program(1);
1181 1181
             }
1182 1182
         }
... ...
@@ -1235,12 +1231,10 @@ static void do_video_out(AVFormatContext *s,
1235 1235
 //fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames);
1236 1236
         if (nb_frames == 0){
1237 1237
             ++nb_frames_drop;
1238
-            if (verbose>2)
1239
-                fprintf(stderr, "*** drop!\n");
1238
+            av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
1240 1239
         }else if (nb_frames > 1) {
1241 1240
             nb_frames_dup += nb_frames - 1;
1242
-            if (verbose>2)
1243
-                fprintf(stderr, "*** %d dup!\n", nb_frames-1);
1241
+            av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames-1);
1244 1242
         }
1245 1243
     }else
1246 1244
         ost->sync_opts= lrintf(sync_ipts);
... ...
@@ -1301,7 +1295,7 @@ static void do_video_out(AVFormatContext *s,
1301 1301
                                        bit_buffer, bit_buffer_size,
1302 1302
                                        &big_picture);
1303 1303
             if (ret < 0) {
1304
-                fprintf(stderr, "Video encoding failed\n");
1304
+                av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
1305 1305
                 exit_program(1);
1306 1306
             }
1307 1307
 
... ...
@@ -1388,6 +1382,7 @@ static void print_report(OutputFile *output_files,
1388 1388
     int64_t pts = INT64_MAX;
1389 1389
     static int64_t last_time = -1;
1390 1390
     static int qp_histogram[52];
1391
+    int hours, mins, secs, us;
1391 1392
 
1392 1393
     if (!is_last_report) {
1393 1394
         int64_t cur_time;
... ...
@@ -1464,43 +1459,39 @@ static void print_report(OutputFile *output_files,
1464 1464
                                       ost->st->time_base, AV_TIME_BASE_Q));
1465 1465
     }
1466 1466
 
1467
-    if (verbose > 0 || is_last_report) {
1468
-        int hours, mins, secs, us;
1469
-        secs = pts / AV_TIME_BASE;
1470
-        us = pts % AV_TIME_BASE;
1471
-        mins = secs / 60;
1472
-        secs %= 60;
1473
-        hours = mins / 60;
1474
-        mins %= 60;
1475
-
1476
-        bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
1477
-
1478
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1479
-                 "size=%8.0fkB time=", total_size / 1024.0);
1480
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1481
-                 "%02d:%02d:%02d.%02d ", hours, mins, secs,
1482
-                 (100 * us) / AV_TIME_BASE);
1483
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1484
-                 "bitrate=%6.1fkbits/s", bitrate);
1485
-
1486
-        if (nb_frames_dup || nb_frames_drop)
1487
-          snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
1488
-                  nb_frames_dup, nb_frames_drop);
1489
-
1490
-        if (verbose >= 0)
1491
-            fprintf(stderr, "%s    \r", buf);
1492
-
1493
-        fflush(stderr);
1494
-    }
1467
+    secs = pts / AV_TIME_BASE;
1468
+    us = pts % AV_TIME_BASE;
1469
+    mins = secs / 60;
1470
+    secs %= 60;
1471
+    hours = mins / 60;
1472
+    mins %= 60;
1473
+
1474
+    bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
1475
+
1476
+    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1477
+             "size=%8.0fkB time=", total_size / 1024.0);
1478
+    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1479
+             "%02d:%02d:%02d.%02d ", hours, mins, secs,
1480
+             (100 * us) / AV_TIME_BASE);
1481
+    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1482
+             "bitrate=%6.1fkbits/s", bitrate);
1483
+
1484
+    if (nb_frames_dup || nb_frames_drop)
1485
+        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
1486
+                nb_frames_dup, nb_frames_drop);
1495 1487
 
1496
-    if (is_last_report && verbose >= 0){
1488
+    av_log(NULL, is_last_report ? AV_LOG_WARNING : AV_LOG_INFO, "%s    \r", buf);
1489
+
1490
+    fflush(stderr);
1491
+
1492
+    if (is_last_report) {
1497 1493
         int64_t raw= audio_size + video_size + extra_size;
1498
-        fprintf(stderr, "\n");
1499
-        fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
1500
-                video_size/1024.0,
1501
-                audio_size/1024.0,
1502
-                extra_size/1024.0,
1503
-                100.0*(total_size - raw)/raw
1494
+        av_log(NULL, AV_LOG_INFO, "\n");
1495
+        av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
1496
+               video_size/1024.0,
1497
+               audio_size/1024.0,
1498
+               extra_size/1024.0,
1499
+               100.0*(total_size - raw)/raw
1504 1500
         );
1505 1501
     }
1506 1502
 }
... ...
@@ -1564,7 +1555,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
1564 1564
                     ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
1565 1565
                 }
1566 1566
                 if (ret < 0) {
1567
-                    fprintf(stderr, "Audio encoding failed\n");
1567
+                    av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
1568 1568
                     exit_program(1);
1569 1569
                 }
1570 1570
                 audio_size += ret;
... ...
@@ -1573,7 +1564,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
1573 1573
             case AVMEDIA_TYPE_VIDEO:
1574 1574
                 ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
1575 1575
                 if (ret < 0) {
1576
-                    fprintf(stderr, "Video encoding failed\n");
1576
+                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
1577 1577
                     exit_program(1);
1578 1578
                 }
1579 1579
                 video_size += ret;
... ...
@@ -1645,11 +1636,10 @@ static int output_packet(InputStream *ist, int ist_index,
1645 1645
     handle_eof:
1646 1646
         ist->pts= ist->next_pts;
1647 1647
 
1648
-        if(avpkt.size && avpkt.size != pkt->size &&
1649
-           ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){
1650
-            fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
1648
+        if(avpkt.size && avpkt.size != pkt->size)
1649
+            av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,
1650
+                   "Multiple frames in a packet from stream %d\n", pkt->stream_index);
1651 1651
             ist->showed_multi_packet_warning=1;
1652
-        }
1653 1652
 
1654 1653
         /* decode the packet if needed */
1655 1654
         decoded_data_buf = NULL; /* fail safe */
... ...
@@ -1995,7 +1985,7 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
1995 1995
         os = output_files[i].ctx;
1996 1996
         if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) {
1997 1997
             av_dump_format(os, i, os->filename, 1);
1998
-            fprintf(stderr, "Output file #%d does not contain any stream\n", i);
1998
+            av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i);
1999 1999
             return AVERROR(EINVAL);
2000 2000
         }
2001 2001
     }
... ...
@@ -2060,7 +2050,7 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2060 2060
             switch(codec->codec_type) {
2061 2061
             case AVMEDIA_TYPE_AUDIO:
2062 2062
                 if(audio_volume != 256) {
2063
-                    fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n");
2063
+                    av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
2064 2064
                     exit_program(1);
2065 2065
                 }
2066 2066
                 codec->channel_layout = icodec->channel_layout;
... ...
@@ -2135,7 +2125,7 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2135 2135
                 choose_pixel_fmt(ost->st, ost->enc);
2136 2136
 
2137 2137
                 if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
2138
-                    fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
2138
+                    av_log(NULL, AV_LOG_FATAL, "Video pixel format is unknown, stream cannot be encoded\n");
2139 2139
                     exit_program(1);
2140 2140
                 }
2141 2141
 
... ...
@@ -2172,7 +2162,7 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2172 2172
 
2173 2173
 #if CONFIG_AVFILTER
2174 2174
                 if (configure_video_filters(ist, ost)) {
2175
-                    fprintf(stderr, "Error opening filters!\n");
2175
+                    av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n");
2176 2176
                     exit(1);
2177 2177
                 }
2178 2178
 #endif
... ...
@@ -2197,7 +2187,8 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2197 2197
                 if (codec->flags & CODEC_FLAG_PASS1) {
2198 2198
                     f = fopen(logfilename, "wb");
2199 2199
                     if (!f) {
2200
-                        fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
2200
+                        av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n",
2201
+                               logfilename, strerror(errno));
2201 2202
                         exit_program(1);
2202 2203
                     }
2203 2204
                     ost->logfile = f;
... ...
@@ -2205,7 +2196,8 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2205 2205
                     char  *logbuffer;
2206 2206
                     size_t logbuffer_size;
2207 2207
                     if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
2208
-                        fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename);
2208
+                        av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
2209
+                               logfilename);
2209 2210
                         exit_program(1);
2210 2211
                     }
2211 2212
                     codec->stats_in = logbuffer;
... ...
@@ -2222,8 +2214,8 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2222 2222
     if (!bit_buffer)
2223 2223
         bit_buffer = av_malloc(bit_buffer_size);
2224 2224
     if (!bit_buffer) {
2225
-        fprintf(stderr, "Cannot allocate %d bytes output buffer\n",
2226
-                bit_buffer_size);
2225
+        av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n",
2226
+               bit_buffer_size);
2227 2227
         return AVERROR(ENOMEM);
2228 2228
     }
2229 2229
 
... ...
@@ -2309,31 +2301,29 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2309 2309
     }
2310 2310
 
2311 2311
     /* dump the stream mapping */
2312
-    if (verbose >= 0) {
2313
-        fprintf(stderr, "Stream mapping:\n");
2314
-        for (i = 0; i < nb_output_streams;i ++) {
2315
-            ost = &output_streams[i];
2316
-            fprintf(stderr, "  Stream #%d.%d -> #%d.%d",
2317
-                    input_streams[ost->source_index].file_index,
2318
-                    input_streams[ost->source_index].st->index,
2319
-                    ost->file_index,
2320
-                    ost->index);
2321
-            if (ost->sync_ist != &input_streams[ost->source_index])
2322
-                fprintf(stderr, " [sync #%d.%d]",
2323
-                        ost->sync_ist->file_index,
2324
-                        ost->sync_ist->st->index);
2325
-            if (ost->st->stream_copy)
2326
-                fprintf(stderr, " (copy)");
2327
-            else
2328
-                fprintf(stderr, " (%s -> %s)", input_streams[ost->source_index].dec ?
2329
-                        input_streams[ost->source_index].dec->name : "?",
2330
-                        ost->enc ? ost->enc->name : "?");
2331
-            fprintf(stderr, "\n");
2332
-        }
2312
+    av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
2313
+    for (i = 0; i < nb_output_streams; i++) {
2314
+        ost = &output_streams[i];
2315
+        av_log(NULL, AV_LOG_INFO, "  Stream #%d.%d -> #%d.%d",
2316
+               input_streams[ost->source_index].file_index,
2317
+               input_streams[ost->source_index].st->index,
2318
+               ost->file_index,
2319
+               ost->index);
2320
+        if (ost->sync_ist != &input_streams[ost->source_index])
2321
+            av_log(NULL, AV_LOG_INFO, " [sync #%d.%d]",
2322
+                   ost->sync_ist->file_index,
2323
+                   ost->sync_ist->st->index);
2324
+        if (ost->st->stream_copy)
2325
+            av_log(NULL, AV_LOG_INFO, " (copy)");
2326
+        else
2327
+            av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ?
2328
+                   input_streams[ost->source_index].dec->name : "?",
2329
+                   ost->enc ? ost->enc->name : "?");
2330
+        av_log(NULL, AV_LOG_INFO, "\n");
2333 2331
     }
2334 2332
 
2335 2333
     if (ret) {
2336
-        fprintf(stderr, "%s\n", error);
2334
+        av_log(NULL, AV_LOG_ERROR, "%s\n", error);
2337 2335
         return ret;
2338 2336
     }
2339 2337
 
... ...
@@ -2367,8 +2357,7 @@ static int transcode(OutputFile *output_files, int nb_output_files,
2367 2367
         goto fail;
2368 2368
 
2369 2369
     if (!using_stdin) {
2370
-        if(verbose >= 0)
2371
-            fprintf(stderr, "Press [q] to stop, [?] for help\n");
2370
+        av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
2372 2371
         avio_set_interrupt_cb(decode_interrupt_cb);
2373 2372
     }
2374 2373
     term_init();
... ...
@@ -2391,8 +2380,8 @@ static int transcode(OutputFile *output_files, int nb_output_files,
2391 2391
             key = read_key();
2392 2392
             if (key == 'q')
2393 2393
                 break;
2394
-            if (key == '+') verbose++;
2395
-            if (key == '-') verbose--;
2394
+            if (key == '+') av_log_set_level(av_log_get_level()+10);
2395
+            if (key == '-') av_log_set_level(av_log_get_level()-10);
2396 2396
             if (key == 's') qp_hist     ^= 1;
2397 2397
             if (key == 'h'){
2398 2398
                 if (do_hex_dump){
... ...
@@ -2566,9 +2555,8 @@ static int transcode(OutputFile *output_files, int nb_output_files,
2566 2566
                  ist->st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) ||
2567 2567
                 pkt_dts+1<ist->pts)&& !copy_ts){
2568 2568
                 input_files[ist->file_index].ts_offset -= delta;
2569
-                if (verbose > 2)
2570
-                    fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
2571
-                            delta, input_files[ist->file_index].ts_offset);
2569
+                av_log(NULL, AV_LOG_DEBUG, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
2570
+                       delta, input_files[ist->file_index].ts_offset);
2572 2571
                 pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
2573 2572
                 if(pkt.pts != AV_NOPTS_VALUE)
2574 2573
                     pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
... ...
@@ -2578,9 +2566,8 @@ static int transcode(OutputFile *output_files, int nb_output_files,
2578 2578
         //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size);
2579 2579
         if (output_packet(ist, ist_index, output_streams, nb_output_streams, &pkt) < 0) {
2580 2580
 
2581
-            if (verbose >= 0)
2582
-                fprintf(stderr, "Error while decoding stream #%d.%d\n",
2583
-                        ist->file_index, ist->st->index);
2581
+            av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d.%d\n",
2582
+                   ist->file_index, ist->st->index);
2584 2583
             if (exit_on_error)
2585 2584
                 exit_program(1);
2586 2585
             av_free_packet(&pkt);
... ...
@@ -2668,19 +2655,19 @@ static int transcode(OutputFile *output_files, int nb_output_files,
2668 2668
 
2669 2669
 static int opt_verbose(const char *opt, const char *arg)
2670 2670
 {
2671
-    verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10);
2671
+    av_log(NULL, AV_LOG_WARNING, "-%s is deprecated, use -loglevel\n", opt);
2672 2672
     return 0;
2673 2673
 }
2674 2674
 
2675 2675
 static int opt_frame_crop(const char *opt, const char *arg)
2676 2676
 {
2677
-    fprintf(stderr, "Option '%s' has been removed, use the crop filter instead\n", opt);
2677
+    av_log(NULL, AV_LOG_FATAL, "Option '%s' has been removed, use the crop filter instead\n", opt);
2678 2678
     return AVERROR(EINVAL);
2679 2679
 }
2680 2680
 
2681 2681
 static int opt_pad(const char *opt, const char *arg)
2682 2682
 {
2683
-    fprintf(stderr, "Option '%s' has been removed, use the pad filter instead\n", opt);
2683
+    av_log(NULL, AV_LOG_FATAL, "Option '%s' has been removed, use the pad filter instead\n", opt);
2684 2684
     return -1;
2685 2685
 }
2686 2686
 
... ...
@@ -2702,7 +2689,7 @@ static double parse_frame_aspect_ratio(const char *arg)
2702 2702
         ar = strtod(arg, NULL);
2703 2703
 
2704 2704
     if (!ar) {
2705
-        fprintf(stderr, "Incorrect aspect ratio specification.\n");
2705
+        av_log(NULL, AV_LOG_FATAL, "Incorrect aspect ratio specification.\n");
2706 2706
         exit_program(1);
2707 2707
     }
2708 2708
     return ar;
... ...
@@ -2762,7 +2749,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2762 2762
         *sync = 0;
2763 2763
         sync_file_idx = strtol(sync + 1, &sync, 0);
2764 2764
         if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
2765
-            av_log(NULL, AV_LOG_ERROR, "Invalid sync file index: %d.\n", sync_file_idx);
2765
+            av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
2766 2766
             exit_program(1);
2767 2767
         }
2768 2768
         if (*sync)
... ...
@@ -2774,7 +2761,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2774 2774
                 break;
2775 2775
             }
2776 2776
         if (i == input_files[sync_file_idx].nb_streams) {
2777
-            av_log(NULL, AV_LOG_ERROR, "Sync stream specification in map %s does not "
2777
+            av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
2778 2778
                                        "match any streams.\n", arg);
2779 2779
             exit_program(1);
2780 2780
         }
... ...
@@ -2783,7 +2770,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2783 2783
 
2784 2784
     file_idx = strtol(map, &p, 0);
2785 2785
     if (file_idx >= nb_input_files || file_idx < 0) {
2786
-        av_log(NULL, AV_LOG_ERROR, "Invalid input file index: %d.\n", file_idx);
2786
+        av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
2787 2787
         exit_program(1);
2788 2788
     }
2789 2789
     if (negative)
... ...
@@ -2817,7 +2804,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg)
2817 2817
         }
2818 2818
 
2819 2819
     if (!m) {
2820
-        av_log(NULL, AV_LOG_ERROR, "Stream map '%s' matches no streams.\n", arg);
2820
+        av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n", arg);
2821 2821
         exit_program(1);
2822 2822
     }
2823 2823
 
... ...
@@ -2839,7 +2826,7 @@ static void parse_meta_type(char *arg, char *type, int *index)
2839 2839
                 *index = strtol(++arg, NULL, 0);
2840 2840
             break;
2841 2841
         default:
2842
-            fprintf(stderr, "Invalid metadata type %c.\n", *arg);
2842
+            av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
2843 2843
             exit_program(1);
2844 2844
         }
2845 2845
     } else
... ...
@@ -2876,7 +2863,7 @@ static int opt_map_metadata(OptionsContext *o, const char *opt, const char *arg)
2876 2876
 
2877 2877
 static int opt_map_meta_data(OptionsContext *o, const char *opt, const char *arg)
2878 2878
 {
2879
-    fprintf(stderr, "-map_meta_data is deprecated and will be removed soon. "
2879
+    av_log(NULL, AV_LOG_WARNING, "-map_meta_data is deprecated and will be removed soon. "
2880 2880
                     "Use -map_metadata instead.\n");
2881 2881
     return opt_map_metadata(o, opt, arg);
2882 2882
 }
... ...
@@ -2905,11 +2892,11 @@ static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, i
2905 2905
         avcodec_find_encoder_by_name(name) :
2906 2906
         avcodec_find_decoder_by_name(name);
2907 2907
     if(!codec) {
2908
-        av_log(NULL, AV_LOG_ERROR, "Unknown %s '%s'\n", codec_string, name);
2908
+        av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
2909 2909
         exit_program(1);
2910 2910
     }
2911 2911
     if(codec->type != type) {
2912
-        av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name);
2912
+        av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
2913 2913
         exit_program(1);
2914 2914
     }
2915 2915
     return codec->id;
... ...
@@ -2983,11 +2970,9 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
2983 2983
 
2984 2984
             if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
2985 2985
 
2986
-                if (verbose >= 0)
2987
-                    fprintf(stderr,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
2988
-                            i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
2989
-
2990
-                    (float)rfps / rfps_base, rfps, rfps_base);
2986
+                av_log(NULL, AV_LOG_INFO,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
2987
+                       i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
2988
+                       (float)rfps / rfps_base, rfps, rfps_base);
2991 2989
             }
2992 2990
 
2993 2991
             if (o->video_disable)
... ...
@@ -3024,7 +3009,7 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
3024 3024
 
3025 3025
     if (o->format) {
3026 3026
         if (!(file_iformat = av_find_input_format(o->format))) {
3027
-            fprintf(stderr, "Unknown input format: '%s'\n", o->format);
3027
+            av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
3028 3028
             exit_program(1);
3029 3029
         }
3030 3030
     }
... ...
@@ -3084,8 +3069,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
3084 3084
     /* If not enough info to get the stream parameters, we decode the
3085 3085
        first frames to get it. (used in mpeg case for example) */
3086 3086
     ret = avformat_find_stream_info(ic, opts);
3087
-    if (ret < 0 && verbose >= 0) {
3088
-        fprintf(stderr, "%s: could not find codec parameters\n", filename);
3087
+    if (ret < 0) {
3088
+        av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
3089 3089
         av_close_input_file(ic);
3090 3090
         exit_program(1);
3091 3091
     }
... ...
@@ -3099,8 +3084,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
3099 3099
     if (o->start_time != 0) {
3100 3100
         ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
3101 3101
         if (ret < 0) {
3102
-            fprintf(stderr, "%s: could not seek to position %0.3f\n",
3103
-                    filename, (double)timestamp / AV_TIME_BASE);
3102
+            av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
3103
+                   filename, (double)timestamp / AV_TIME_BASE);
3104 3104
         }
3105 3105
     }
3106 3106
 
... ...
@@ -3108,8 +3093,7 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
3108 3108
     add_input_streams(o, ic);
3109 3109
 
3110 3110
     /* dump the file content */
3111
-    if (verbose >= 0)
3112
-        av_dump_format(ic, nb_input_files, filename, 0);
3111
+    av_dump_format(ic, nb_input_files, filename, 0);
3113 3112
 
3114 3113
     input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
3115 3114
     input_files[nb_input_files - 1].ctx        = ic;
... ...
@@ -3159,7 +3143,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
3159 3159
     double qscale = -1;
3160 3160
 
3161 3161
     if (!st) {
3162
-        av_log(NULL, AV_LOG_ERROR, "Could not alloc stream.\n");
3162
+        av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
3163 3163
         exit_program(1);
3164 3164
     }
3165 3165
 
... ...
@@ -3186,7 +3170,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
3186 3186
         if (next = strchr(bsf, ','))
3187 3187
             *next++ = 0;
3188 3188
         if (!(bsfc = av_bitstream_filter_init(bsf))) {
3189
-            av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter %s\n", bsf);
3189
+            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
3190 3190
             exit_program(1);
3191 3191
         }
3192 3192
         if (bsfc_prev)
... ...
@@ -3226,7 +3210,7 @@ static void parse_matrix_coeffs(uint16_t *dest, const char *str)
3226 3226
             break;
3227 3227
         p = strchr(p, ',');
3228 3228
         if(!p) {
3229
-            fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
3229
+            av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
3230 3230
             exit_program(1);
3231 3231
         }
3232 3232
         p++;
... ...
@@ -3256,13 +3240,13 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3256 3256
 
3257 3257
         MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
3258 3258
         if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
3259
-            av_log(NULL, AV_LOG_ERROR, "Invalid framerate value: %s\n", frame_rate);
3259
+            av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
3260 3260
             exit_program(1);
3261 3261
         }
3262 3262
 
3263 3263
         MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
3264 3264
         if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
3265
-            av_log(NULL, AV_LOG_ERROR, "Invalid frame size: %s.\n", frame_size);
3265
+            av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
3266 3266
             exit_program(1);
3267 3267
         }
3268 3268
 
... ...
@@ -3273,7 +3257,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3273 3273
         video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
3274 3274
         MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
3275 3275
         if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {
3276
-            av_log(NULL, AV_LOG_ERROR, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
3276
+            av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
3277 3277
             exit_program(1);
3278 3278
         }
3279 3279
         st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
... ...
@@ -3283,7 +3267,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3283 3283
         MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
3284 3284
         if (intra_matrix) {
3285 3285
             if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
3286
-                av_log(NULL, AV_LOG_ERROR, "Could not allocate memory for intra matrix.\n");
3286
+                av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
3287 3287
                 exit_program(1);
3288 3288
             }
3289 3289
             parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
... ...
@@ -3291,7 +3275,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3291 3291
         MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
3292 3292
         if (inter_matrix) {
3293 3293
             if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
3294
-                av_log(NULL, AV_LOG_ERROR, "Could not allocate memory for inter matrix.\n");
3294
+                av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
3295 3295
                 exit_program(1);
3296 3296
             }
3297 3297
             parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
... ...
@@ -3302,7 +3286,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
3302 3302
             int start, end, q;
3303 3303
             int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
3304 3304
             if(e!=3){
3305
-                fprintf(stderr, "error parsing rc_override\n");
3305
+                av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
3306 3306
                 exit_program(1);
3307 3307
             }
3308 3308
             video_enc->rc_override=
... ...
@@ -3378,7 +3362,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
3378 3378
         MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
3379 3379
         if (sample_fmt &&
3380 3380
             (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
3381
-            av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", sample_fmt);
3381
+            av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
3382 3382
             exit_program(1);
3383 3383
         }
3384 3384
 
... ...
@@ -3398,7 +3382,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc)
3398 3398
     st  = ost->st;
3399 3399
     data_enc = st->codec;
3400 3400
     if (!st->stream_copy) {
3401
-        fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n");
3401
+        av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
3402 3402
         exit_program(1);
3403 3403
     }
3404 3404
 
... ...
@@ -3438,9 +3422,9 @@ static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)
3438 3438
     av_strlcpy(idx_str, arg, sizeof(idx_str));
3439 3439
     p = strchr(idx_str, ':');
3440 3440
     if (!p) {
3441
-        fprintf(stderr,
3442
-                "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
3443
-                arg, opt);
3441
+        av_log(NULL, AV_LOG_FATAL,
3442
+               "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
3443
+               arg, opt);
3444 3444
         exit_program(1);
3445 3445
     }
3446 3446
     *p++ = '\0';
... ...
@@ -3613,7 +3597,7 @@ static void opt_output_file(void *optctx, const char *filename)
3613 3613
             case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
3614 3614
             case AVMEDIA_TYPE_DATA:     ost = new_data_stream(o, oc);     break;
3615 3615
             default:
3616
-                av_log(NULL, AV_LOG_ERROR, "Cannot map stream #%d.%d - unsupported type.\n",
3616
+                av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\n",
3617 3617
                        map->file_index, map->stream_index);
3618 3618
                 exit_program(1);
3619 3619
             }
... ...
@@ -3652,12 +3636,12 @@ static void opt_output_file(void *optctx, const char *filename)
3652 3652
                     fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
3653 3653
                     fflush(stderr);
3654 3654
                     if (!read_yesno()) {
3655
-                        fprintf(stderr, "Not overwriting - exiting\n");
3655
+                        av_log(0, AV_LOG_FATAL, "Not overwriting - exiting\n");
3656 3656
                         exit_program(1);
3657 3657
                     }
3658 3658
                 }
3659 3659
                 else {
3660
-                    fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
3660
+                    av_log(0, AV_LOG_FATAL,"File '%s' already exists. Exiting.\n", filename);
3661 3661
                     exit_program(1);
3662 3662
                 }
3663 3663
             }
... ...
@@ -3689,7 +3673,7 @@ static void opt_output_file(void *optctx, const char *filename)
3689 3689
                     break;
3690 3690
                 }
3691 3691
         } else {
3692
-            av_log(NULL, AV_LOG_ERROR, "Invalid input file index %d in chapter mapping.\n",
3692
+            av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
3693 3693
                    o->chapters_input_file);
3694 3694
             exit_program(1);
3695 3695
         }
... ...
@@ -3706,7 +3690,7 @@ static void opt_output_file(void *optctx, const char *filename)
3706 3706
 
3707 3707
 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
3708 3708
         if ((index) < 0 || (index) >= (nb_elems)) {\
3709
-            av_log(NULL, AV_LOG_ERROR, "Invalid %s index %d while processing metadata maps\n",\
3709
+            av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\n",\
3710 3710
                      (desc), (index));\
3711 3711
             exit_program(1);\
3712 3712
         }
... ...
@@ -3765,7 +3749,7 @@ static void opt_output_file(void *optctx, const char *filename)
3765 3765
 
3766 3766
         val = strchr(o->metadata[i].u.str, '=');
3767 3767
         if (!val) {
3768
-            av_log(NULL, AV_LOG_ERROR, "No '=' character in metadata string %s.\n",
3768
+            av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
3769 3769
                    o->metadata[i].u.str);
3770 3770
             exit_program(1);
3771 3771
         }
... ...
@@ -3778,20 +3762,20 @@ static void opt_output_file(void *optctx, const char *filename)
3778 3778
             break;
3779 3779
         case 's':
3780 3780
             if (index < 0 || index >= oc->nb_streams) {
3781
-                av_log(NULL, AV_LOG_ERROR, "Invalid stream index %d in metadata specifier.\n", index);
3781
+                av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\n", index);
3782 3782
                 exit_program(1);
3783 3783
             }
3784 3784
             m = &oc->streams[index]->metadata;
3785 3785
             break;
3786 3786
         case 'c':
3787 3787
             if (index < 0 || index >= oc->nb_chapters) {
3788
-                av_log(NULL, AV_LOG_ERROR, "Invalid chapter index %d in metadata specifier.\n", index);
3788
+                av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
3789 3789
                 exit_program(1);
3790 3790
             }
3791 3791
             m = &oc->chapters[index]->metadata;
3792 3792
             break;
3793 3793
         default:
3794
-            av_log(NULL, AV_LOG_ERROR, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
3794
+            av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
3795 3795
             exit_program(1);
3796 3796
         }
3797 3797
 
... ...
@@ -3963,14 +3947,14 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
3963 3963
                     break;
3964 3964
             }
3965 3965
         }
3966
-        if(verbose > 0 && norm != UNKNOWN)
3967
-            fprintf(stderr, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
3966
+        if (norm != UNKNOWN)
3967
+            av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
3968 3968
     }
3969 3969
 
3970 3970
     if(norm == UNKNOWN) {
3971
-        fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
3972
-        fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
3973
-        fprintf(stderr, "or set a framerate with \"-r xxx\".\n");
3971
+        av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
3972
+        av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
3973
+        av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
3974 3974
         exit_program(1);
3975 3975
     }
3976 3976
 
... ...
@@ -4059,7 +4043,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
4059 4059
         parse_option(o, "ac", "2", options);
4060 4060
 
4061 4061
     } else {
4062
-        fprintf(stderr, "Unknown target: %s\n", arg);
4062
+        av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
4063 4063
         return AVERROR(EINVAL);
4064 4064
     }
4065 4065
     return 0;
... ...
@@ -4108,9 +4092,9 @@ static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
4108 4108
 
4109 4109
     if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
4110 4110
         if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
4111
-            fprintf(stderr, "Please use -preset <speed> -qp 0\n");
4111
+            av_log(0, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
4112 4112
         }else
4113
-            fprintf(stderr, "File for preset '%s' not found\n", arg);
4113
+            av_log(0, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
4114 4114
         exit_program(1);
4115 4115
     }
4116 4116
 
... ...
@@ -4120,7 +4104,7 @@ static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
4120 4120
             continue;
4121 4121
         e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
4122 4122
         if(e){
4123
-            fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line);
4123
+            av_log(0, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
4124 4124
             exit_program(1);
4125 4125
         }
4126 4126
         if(!strcmp(tmp, "acodec")){
... ...
@@ -4132,7 +4116,7 @@ static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
4132 4132
         }else if(!strcmp(tmp, "dcodec")){
4133 4133
             opt_data_codec(o, tmp, tmp2);
4134 4134
         }else if(opt_default(tmp, tmp2) < 0){
4135
-            fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
4135
+            av_log(0, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
4136 4136
             exit_program(1);
4137 4137
         }
4138 4138
     }
... ...
@@ -4210,7 +4194,7 @@ static const OptionDef options[] = {
4210 4210
     { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(rate_emu)}, "read input at native frame rate", "" },
4211 4211
     { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "deprecated, use -loop" },
4212 4212
     { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "deprecated, use -loop", "" },
4213
-    { "v", HAS_ARG, {(void*)opt_verbose}, "set the verbosity level", "number" },
4213
+    { "v", HAS_ARG, {(void*)opt_verbose}, "deprecated, use -loglevel instead", "number" },
4214 4214
     { "target", HAS_ARG | OPT_FUNC2, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
4215 4215
     { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
4216 4216
     { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
... ...
@@ -4321,10 +4305,10 @@ int main(int argc, char **argv)
4321 4321
     reset_options(&o, 0);
4322 4322
 
4323 4323
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
4324
+    parse_loglevel(argc, argv, options);
4324 4325
 
4325 4326
     if(argc>1 && !strcmp(argv[1], "-d")){
4326 4327
         run_as_daemon=1;
4327
-        verbose=-1;
4328 4328
         av_log_set_callback(log_callback_null);
4329 4329
         argc--;
4330 4330
         argv++;
... ...
@@ -4344,26 +4328,25 @@ int main(int argc, char **argv)
4344 4344
         avio_set_interrupt_cb(decode_interrupt_cb);
4345 4345
 #endif
4346 4346
 
4347
-    if(verbose>=0)
4348
-        show_banner();
4347
+    show_banner();
4349 4348
 
4350 4349
     /* parse options */
4351 4350
     parse_options(&o, argc, argv, options, opt_output_file);
4352 4351
 
4353 4352
     if(nb_output_files <= 0 && nb_input_files == 0) {
4354 4353
         show_usage();
4355
-        fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
4354
+        av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
4356 4355
         exit_program(1);
4357 4356
     }
4358 4357
 
4359 4358
     /* file converter / grab */
4360 4359
     if (nb_output_files <= 0) {
4361
-        fprintf(stderr, "At least one output file must be specified\n");
4360
+        av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
4362 4361
         exit_program(1);
4363 4362
     }
4364 4363
 
4365 4364
     if (nb_input_files == 0) {
4366
-        fprintf(stderr, "At least one input file must be specified\n");
4365
+        av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
4367 4366
         exit_program(1);
4368 4367
     }
4369 4368
 
... ...
@@ -3043,6 +3043,7 @@ int main(int argc, char **argv)
3043 3043
     VideoState *is;
3044 3044
 
3045 3045
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
3046
+    parse_loglevel(argc, argv, options);
3046 3047
 
3047 3048
     /* register all codecs, demux and protocols */
3048 3049
     avcodec_register_all();
... ...
@@ -669,6 +669,7 @@ int main(int argc, char **argv)
669 669
 {
670 670
     int ret;
671 671
 
672
+    parse_loglevel(argc, argv, options);
672 673
     av_register_all();
673 674
     init_opts();
674 675
 #if CONFIG_AVDEVICE
... ...
@@ -4669,6 +4669,7 @@ int main(int argc, char **argv)
4669 4669
 {
4670 4670
     struct sigaction sigact;
4671 4671
 
4672
+    parse_loglevel(argc, argv, options);
4672 4673
     av_register_all();
4673 4674
 
4674 4675
     show_banner();
... ...
@@ -226,9 +226,11 @@ static int get_metadata_size(const uint8_t *buf, int buf_size)
226 226
 
227 227
     buf += 4;
228 228
     do {
229
+        if (buf_end - buf < 4)
230
+            return 0;
229 231
         ff_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size);
230 232
         buf += 4;
231
-        if (buf + metadata_size > buf_end) {
233
+        if (buf_end - buf < metadata_size) {
232 234
             /* need more data in order to read the complete header */
233 235
             return 0;
234 236
         }
... ...
@@ -35,36 +35,26 @@
35 35
 #define GSM_MS_BLOCK_SIZE 65
36 36
 #define GSM_FRAME_SIZE 160
37 37
 
38
-static av_cold int libgsm_init(AVCodecContext *avctx) {
38
+static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
39 39
     if (avctx->channels > 1) {
40 40
         av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
41 41
                avctx->channels);
42 42
         return -1;
43 43
     }
44 44
 
45
-    if(avctx->codec->decode){
46
-        if(!avctx->channels)
47
-            avctx->channels= 1;
48
-
49
-        if(!avctx->sample_rate)
50
-            avctx->sample_rate= 8000;
51
-
52
-        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
53
-    }else{
54
-        if (avctx->sample_rate != 8000) {
55
-            av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n",
56
-                avctx->sample_rate);
57
-            if(avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
58
-                return -1;
59
-        }
60
-        if (avctx->bit_rate != 13000 /* Official */ &&
61
-            avctx->bit_rate != 13200 /* Very common */ &&
62
-            avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) {
63
-            av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n",
64
-                avctx->bit_rate);
65
-            if(avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
66
-                return -1;
67
-        }
45
+    if (avctx->sample_rate != 8000) {
46
+        av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n",
47
+               avctx->sample_rate);
48
+        if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
49
+            return -1;
50
+    }
51
+    if (avctx->bit_rate != 13000 /* Official */ &&
52
+        avctx->bit_rate != 13200 /* Very common */ &&
53
+        avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) {
54
+        av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n",
55
+               avctx->bit_rate);
56
+        if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
57
+            return -1;
68 58
     }
69 59
 
70 60
     avctx->priv_data = gsm_create();
... ...
@@ -88,7 +78,7 @@ static av_cold int libgsm_init(AVCodecContext *avctx) {
88 88
     return 0;
89 89
 }
90 90
 
91
-static av_cold int libgsm_close(AVCodecContext *avctx) {
91
+static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
92 92
     av_freep(&avctx->coded_frame);
93 93
     gsm_destroy(avctx->priv_data);
94 94
     avctx->priv_data = NULL;
... ...
@@ -116,9 +106,9 @@ AVCodec ff_libgsm_encoder = {
116 116
     .name           = "libgsm",
117 117
     .type           = AVMEDIA_TYPE_AUDIO,
118 118
     .id             = CODEC_ID_GSM,
119
-    .init           = libgsm_init,
119
+    .init           = libgsm_encode_init,
120 120
     .encode         = libgsm_encode_frame,
121
-    .close          = libgsm_close,
121
+    .close          = libgsm_encode_close,
122 122
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
123 123
     .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
124 124
 };
... ...
@@ -127,13 +117,52 @@ AVCodec ff_libgsm_ms_encoder = {
127 127
     .name           = "libgsm_ms",
128 128
     .type           = AVMEDIA_TYPE_AUDIO,
129 129
     .id             = CODEC_ID_GSM_MS,
130
-    .init           = libgsm_init,
130
+    .init           = libgsm_encode_init,
131 131
     .encode         = libgsm_encode_frame,
132
-    .close          = libgsm_close,
132
+    .close          = libgsm_encode_close,
133 133
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
134 134
     .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
135 135
 };
136 136
 
137
+static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
138
+    if (avctx->channels > 1) {
139
+        av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
140
+               avctx->channels);
141
+        return -1;
142
+    }
143
+
144
+    if (!avctx->channels)
145
+        avctx->channels = 1;
146
+
147
+    if (!avctx->sample_rate)
148
+        avctx->sample_rate = 8000;
149
+
150
+    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
151
+
152
+    avctx->priv_data = gsm_create();
153
+
154
+    switch(avctx->codec_id) {
155
+    case CODEC_ID_GSM:
156
+        avctx->frame_size  = GSM_FRAME_SIZE;
157
+        avctx->block_align = GSM_BLOCK_SIZE;
158
+        break;
159
+    case CODEC_ID_GSM_MS: {
160
+        int one = 1;
161
+        gsm_option(avctx->priv_data, GSM_OPT_WAV49, &one);
162
+        avctx->frame_size  = 2 * GSM_FRAME_SIZE;
163
+        avctx->block_align = GSM_MS_BLOCK_SIZE;
164
+        }
165
+    }
166
+
167
+    return 0;
168
+}
169
+
170
+static av_cold int libgsm_decode_close(AVCodecContext *avctx) {
171
+    gsm_destroy(avctx->priv_data);
172
+    avctx->priv_data = NULL;
173
+    return 0;
174
+}
175
+
137 176
 static int libgsm_decode_frame(AVCodecContext *avctx,
138 177
                                void *data, int *data_size,
139 178
                                AVPacket *avpkt) {
... ...
@@ -158,8 +187,8 @@ AVCodec ff_libgsm_decoder = {
158 158
     .name           = "libgsm",
159 159
     .type           = AVMEDIA_TYPE_AUDIO,
160 160
     .id             = CODEC_ID_GSM,
161
-    .init           = libgsm_init,
162
-    .close          = libgsm_close,
161
+    .init           = libgsm_decode_init,
162
+    .close          = libgsm_decode_close,
163 163
     .decode         = libgsm_decode_frame,
164 164
     .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
165 165
 };
... ...
@@ -168,8 +197,8 @@ AVCodec ff_libgsm_ms_decoder = {
168 168
     .name           = "libgsm_ms",
169 169
     .type           = AVMEDIA_TYPE_AUDIO,
170 170
     .id             = CODEC_ID_GSM_MS,
171
-    .init           = libgsm_init,
172
-    .close          = libgsm_close,
171
+    .init           = libgsm_decode_init,
172
+    .close          = libgsm_decode_close,
173 173
     .decode         = libgsm_decode_frame,
174 174
     .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
175 175
 };
... ...
@@ -21,7 +21,7 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 53
24
-#define LIBAVCODEC_VERSION_MINOR 17
24
+#define LIBAVCODEC_VERSION_MINOR 18
25 25
 #define LIBAVCODEC_VERSION_MICRO  0
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -25,47 +25,50 @@
25 25
 
26 26
 /**
27 27
  * @file
28
- * Westwood SNDx codecs.
28
+ * Westwood SNDx codecs
29 29
  *
30 30
  * Reference documents about VQA format and its audio codecs
31 31
  * can be found here:
32 32
  * http://www.multimedia.cx
33 33
  */
34 34
 
35
-static const int8_t ws_adpcm_2bit[] = { -2, -1, 0, 1};
36 35
 static const int8_t ws_adpcm_4bit[] = {
37 36
     -9, -8, -6, -5, -4, -3, -2, -1,
38
-     0,  1,  2,  3,  4,  5,  6,  8 };
39
-
40
-#define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128;
37
+     0,  1,  2,  3,  4,  5,  6,  8
38
+};
41 39
 
42
-static av_cold int ws_snd_decode_init(AVCodecContext * avctx)
40
+static av_cold int ws_snd_decode_init(AVCodecContext *avctx)
43 41
 {
44
-//    WSSNDContext *c = avctx->priv_data;
42
+    if (avctx->channels != 1) {
43
+        av_log_ask_for_sample(avctx, "unsupported number of channels\n");
44
+        return AVERROR(EINVAL);
45
+    }
45 46
 
46
-    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
47
+    avctx->sample_fmt = AV_SAMPLE_FMT_U8;
47 48
     return 0;
48 49
 }
49 50
 
50
-static int ws_snd_decode_frame(AVCodecContext *avctx,
51
-                void *data, int *data_size,
52
-                AVPacket *avpkt)
51
+static int ws_snd_decode_frame(AVCodecContext *avctx, void *data,
52
+                               int *data_size, AVPacket *avpkt)
53 53
 {
54 54
     const uint8_t *buf = avpkt->data;
55
-    int buf_size = avpkt->size;
56
-//    WSSNDContext *c = avctx->priv_data;
55
+    int buf_size       = avpkt->size;
57 56
 
58 57
     int in_size, out_size;
59
-    int sample = 0;
60
-    int i;
61
-    short *samples = data;
58
+    int sample = 128;
59
+    uint8_t *samples = data;
60
+    uint8_t *samples_end;
62 61
 
63 62
     if (!buf_size)
64 63
         return 0;
65 64
 
65
+    if (buf_size < 4) {
66
+        av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
67
+        return AVERROR(EINVAL);
68
+    }
69
+
66 70
     out_size = AV_RL16(&buf[0]);
67
-    *data_size = out_size * 2;
68
-    in_size = AV_RL16(&buf[2]);
71
+    in_size  = AV_RL16(&buf[2]);
69 72
     buf += 4;
70 73
 
71 74
     if (out_size > *data_size) {
... ...
@@ -76,47 +79,63 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
76 76
         av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");
77 77
         return -1;
78 78
     }
79
+    samples_end = samples + out_size;
80
+
79 81
     if (in_size == out_size) {
80
-        for (i = 0; i < out_size; i++)
81
-            *samples++ = (*buf++ - 0x80) << 8;
82
+        memcpy(samples, buf, out_size);
83
+        *data_size = out_size;
82 84
         return buf_size;
83 85
     }
84 86
 
85
-    while (out_size > 0) {
86
-        int code;
87
+    while (samples < samples_end && buf - avpkt->data < buf_size) {
88
+        int code, smp, size;
87 89
         uint8_t count;
88
-        code = (*buf) >> 6;
89
-        count = (*buf) & 0x3F;
90
+        code  = *buf >> 6;
91
+        count = *buf & 0x3F;
90 92
         buf++;
91
-        switch(code) {
93
+
94
+        /* make sure we don't write past the output buffer */
95
+        switch (code) {
96
+        case 0:  smp = 4;                              break;
97
+        case 1:  smp = 2;                              break;
98
+        case 2:  smp = (count & 0x20) ? 1 : count + 1; break;
99
+        default: smp = count + 1;                      break;
100
+        }
101
+        if (samples_end - samples < smp)
102
+            break;
103
+
104
+        /* make sure we don't read past the input buffer */
105
+        size = ((code == 2 && (count & 0x20)) || code == 3) ? 0 : count + 1;
106
+        if ((buf - avpkt->data) + size > buf_size)
107
+            break;
108
+
109
+        switch (code) {
92 110
         case 0: /* ADPCM 2-bit */
93 111
             for (count++; count > 0; count--) {
94 112
                 code = *buf++;
95
-                sample += ws_adpcm_2bit[code & 0x3];
96
-                CLIP8(sample);
97
-                *samples++ = sample << 8;
98
-                sample += ws_adpcm_2bit[(code >> 2) & 0x3];
99
-                CLIP8(sample);
100
-                *samples++ = sample << 8;
101
-                sample += ws_adpcm_2bit[(code >> 4) & 0x3];
102
-                CLIP8(sample);
103
-                *samples++ = sample << 8;
104
-                sample += ws_adpcm_2bit[(code >> 6) & 0x3];
105
-                CLIP8(sample);
106
-                *samples++ = sample << 8;
107
-                out_size -= 4;
113
+                sample += ( code       & 0x3) - 2;
114
+                sample = av_clip_uint8(sample);
115
+                *samples++ = sample;
116
+                sample += ((code >> 2) & 0x3) - 2;
117
+                sample = av_clip_uint8(sample);
118
+                *samples++ = sample;
119
+                sample += ((code >> 4) & 0x3) - 2;
120
+                sample = av_clip_uint8(sample);
121
+                *samples++ = sample;
122
+                sample +=  (code >> 6)        - 2;
123
+                sample = av_clip_uint8(sample);
124
+                *samples++ = sample;
108 125
             }
109 126
             break;
110 127
         case 1: /* ADPCM 4-bit */
111 128
             for (count++; count > 0; count--) {
112 129
                 code = *buf++;
113 130
                 sample += ws_adpcm_4bit[code & 0xF];
114
-                CLIP8(sample);
115
-                *samples++ = sample << 8;
131
+                sample = av_clip_uint8(sample);
132
+                *samples++ = sample;
116 133
                 sample += ws_adpcm_4bit[code >> 4];
117
-                CLIP8(sample);
118
-                *samples++ = sample << 8;
119
-                out_size -= 2;
134
+                sample = av_clip_uint8(sample);
135
+                *samples++ = sample;
120 136
             }
121 137
             break;
122 138
         case 2: /* no compression */
... ...
@@ -125,24 +144,23 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
125 125
                 t = count;
126 126
                 t <<= 3;
127 127
                 sample += t >> 3;
128
-                *samples++ = sample << 8;
129
-                out_size--;
128
+                sample = av_clip_uint8(sample);
129
+                *samples++ = sample;
130 130
             } else { /* copy */
131
-                for (count++; count > 0; count--) {
132
-                    *samples++ = (*buf++ - 0x80) << 8;
133
-                    out_size--;
134
-                }
135
-                sample = buf[-1] - 0x80;
131
+                memcpy(samples, buf, smp);
132
+                samples += smp;
133
+                buf     += smp;
134
+                sample = buf[-1];
136 135
             }
137 136
             break;
138 137
         default: /* run */
139
-            for(count++; count > 0; count--) {
140
-                *samples++ = sample << 8;
141
-                out_size--;
142
-            }
138
+            memset(samples, sample, smp);
139
+            samples += smp;
143 140
         }
144 141
     }
145 142
 
143
+    *data_size = samples - (uint8_t *)data;
144
+
146 145
     return buf_size;
147 146
 }
148 147
 
... ...
@@ -20,9 +20,10 @@
20 20
  */
21 21
 
22 22
 #include <string.h>
23
+
24
+#include "libavutil/intreadwrite.h"
23 25
 #include "avformat.h"
24 26
 #include "oggdec.h"
25
-#include "libavutil/intreadwrite.h"
26 27
 
27 28
 struct oggcelt_private {
28 29
     int extra_headers_left;
... ...
@@ -38,11 +39,10 @@ static int celt_header(AVFormatContext *s, int idx)
38 38
 
39 39
     if (os->psize == 60 &&
40 40
         !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) {
41
-
42 41
         /* Main header */
43 42
 
44
-        uint32_t version, header_size av_unused, sample_rate, nb_channels, frame_size;
45
-        uint32_t overlap, bytes_per_packet av_unused, extra_headers;
43
+        uint32_t version, sample_rate, nb_channels, frame_size;
44
+        uint32_t overlap, extra_headers;
46 45
         uint8_t *extradata;
47 46
 
48 47
         extradata = av_malloc(2 * sizeof(uint32_t) +
... ...
@@ -54,12 +54,12 @@ static int celt_header(AVFormatContext *s, int idx)
54 54
             return AVERROR(ENOMEM);
55 55
         }
56 56
         version          = AV_RL32(p + 28);
57
-        header_size      = AV_RL32(p + 32); /* unused */
57
+        /* unused header size field skipped */
58 58
         sample_rate      = AV_RL32(p + 36);
59 59
         nb_channels      = AV_RL32(p + 40);
60 60
         frame_size       = AV_RL32(p + 44);
61 61
         overlap          = AV_RL32(p + 48);
62
-        bytes_per_packet = AV_RL32(p + 52); /* unused */
62
+        /* unused bytes per packet field skipped */
63 63
         extra_headers    = AV_RL32(p + 56);
64 64
         st->codec->codec_type     = AVMEDIA_TYPE_AUDIO;
65 65
         st->codec->codec_id       = CODEC_ID_CELT;
... ...
@@ -67,25 +67,23 @@ static int celt_header(AVFormatContext *s, int idx)
67 67
         st->codec->channels       = nb_channels;
68 68
         st->codec->frame_size     = frame_size;
69 69
         st->codec->sample_fmt     = AV_SAMPLE_FMT_S16;
70
-        av_set_pts_info(st, 64, 1, sample_rate);
70
+        av_free(st->codec->extradata);
71
+        st->codec->extradata      = extradata;
72
+        st->codec->extradata_size = 2 * sizeof(uint32_t);
73
+        if (sample_rate)
74
+            av_set_pts_info(st, 64, 1, sample_rate);
71 75
         priv->extra_headers_left  = 1 + extra_headers;
72 76
         av_free(os->private);
73 77
         os->private = priv;
74 78
         AV_WL32(extradata + 0, overlap);
75 79
         AV_WL32(extradata + 4, version);
76
-        av_free(st->codec->extradata);
77
-        st->codec->extradata = extradata;
78
-        st->codec->extradata_size = 2 * sizeof(uint32_t);
79 80
         return 1;
80
-
81
-    } else if(priv && priv->extra_headers_left) {
82
-
81
+    } else if (priv && priv->extra_headers_left) {
83 82
         /* Extra headers (vorbiscomment) */
84 83
 
85 84
         ff_vorbis_comment(s, &st->metadata, p, os->psize);
86 85
         priv->extra_headers_left--;
87 86
         return 1;
88
-
89 87
     } else {
90 88
         return 0;
91 89
     }
... ...
@@ -19,6 +19,7 @@
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 20
  */
21 21
 
22
+#include <libavutil/opt.h>
22 23
 #include "avformat.h"
23 24
 
24 25
 #include "rtp.h"
... ...
@@ -89,26 +90,31 @@ int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type)
89 89
     return -1;
90 90
 }
91 91
 
92
-int ff_rtp_get_payload_type(AVCodecContext *codec)
92
+int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec)
93 93
 {
94
-    int i, payload_type;
94
+    int i;
95
+    AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL;
96
+
97
+    /* Was the payload type already specified for the RTP muxer? */
98
+    if (ofmt && ofmt->priv_class) {
99
+        int payload_type = av_get_int(fmt->priv_data, "payload_type", NULL);
100
+        if (payload_type >= 0)
101
+            return payload_type;
102
+    }
95 103
 
96
-    /* compute the payload type */
97
-    for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
104
+    /* static payload type */
105
+    for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
98 106
         if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
99 107
             if (codec->codec_id == CODEC_ID_H263)
100 108
                 continue;
101 109
             if (codec->codec_id == CODEC_ID_PCM_S16BE)
102 110
                 if (codec->channels != AVRtpPayloadTypes[i].audio_channels)
103 111
                     continue;
104
-            payload_type = AVRtpPayloadTypes[i].pt;
112
+            return AVRtpPayloadTypes[i].pt;
105 113
         }
106 114
 
107 115
     /* dynamic payload type */
108
-    if (payload_type < 0)
109
-        payload_type = RTP_PT_PRIVATE + (codec->codec_type == AVMEDIA_TYPE_AUDIO);
110
-
111
-    return payload_type;
116
+    return RTP_PT_PRIVATE + (codec->codec_type == AVMEDIA_TYPE_AUDIO);
112 117
 }
113 118
 
114 119
 const char *ff_rtp_enc_name(int payload_type)
... ...
@@ -21,17 +21,17 @@
21 21
 #ifndef AVFORMAT_RTP_H
22 22
 #define AVFORMAT_RTP_H
23 23
 
24
+#include "libavformat/avformat.h"
24 25
 #include "libavcodec/avcodec.h"
25 26
 
26 27
 /**
27
- * Return the payload type for a given codec.
28
+ * Return the payload type for a given codec used in the given format context.
28 29
  *
30
+ * @param fmt   The context of the format
29 31
  * @param codec The context of the codec
30
- * @return In case of unknown payload type or dynamic payload type, a
31
- * negative value is returned; otherwise, the payload type (the 'PT' field
32
- * in the RTP header) is returned.
32
+ * @return The payload type (the 'PT' field in the RTP header).
33 33
  */
34
-int ff_rtp_get_payload_type(AVCodecContext *codec);
34
+int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec);
35 35
 
36 36
 /**
37 37
  * Initialize a codec context based on the payload type.
... ...
@@ -32,6 +32,7 @@
32 32
 
33 33
 static const AVOption options[] = {
34 34
     FF_RTP_FLAG_OPTS(RTPMuxContext, flags),
35
+    { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
35 36
     { NULL },
36 37
 };
37 38
 
... ...
@@ -92,7 +93,8 @@ static int rtp_write_header(AVFormatContext *s1)
92 92
         return -1;
93 93
     }
94 94
 
95
-    s->payload_type = ff_rtp_get_payload_type(st->codec);
95
+    if (s->payload_type < 0)
96
+        s->payload_type = ff_rtp_get_payload_type(s1, st->codec);
96 97
     s->base_timestamp = av_get_random_seed();
97 98
     s->timestamp = s->base_timestamp;
98 99
     s->cur_timestamp = 0;
... ...
@@ -532,7 +532,7 @@ void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *des
532 532
     const char *type;
533 533
     int payload_type;
534 534
 
535
-    payload_type = ff_rtp_get_payload_type(c);
535
+    payload_type = ff_rtp_get_payload_type(fmt, c);
536 536
 
537 537
     switch (c->codec_type) {
538 538
         case AVMEDIA_TYPE_VIDEO   : type = "video"      ; break;
... ...
@@ -132,6 +132,8 @@ static int sol_read_packet(AVFormatContext *s,
132 132
     if (url_feof(s->pb))
133 133
         return AVERROR(EIO);
134 134
     ret= av_get_packet(s->pb, pkt, MAX_SIZE);
135
+    if (ret < 0)
136
+        return ret;
135 137
     pkt->stream_index = 0;
136 138
 
137 139
     /* note: we need to modify the packet size here to handle the last
... ...
@@ -2122,14 +2122,14 @@ static int has_codec_parameters(AVCodecContext *avctx)
2122 2122
     switch (avctx->codec_type) {
2123 2123
     case AVMEDIA_TYPE_AUDIO:
2124 2124
         val = avctx->sample_rate && avctx->channels && avctx->sample_fmt != AV_SAMPLE_FMT_NONE;
2125
-        if(!avctx->frame_size &&
2126
-           (avctx->codec_id == CODEC_ID_VORBIS ||
2127
-            avctx->codec_id == CODEC_ID_AAC ||
2128
-            avctx->codec_id == CODEC_ID_MP1 ||
2129
-            avctx->codec_id == CODEC_ID_MP2 ||
2130
-            avctx->codec_id == CODEC_ID_MP3 ||
2131
-            avctx->codec_id == CODEC_ID_SPEEX ||
2132
-            avctx->codec_id == CODEC_ID_CELT))
2125
+        if (!avctx->frame_size &&
2126
+            (avctx->codec_id == CODEC_ID_VORBIS ||
2127
+             avctx->codec_id == CODEC_ID_AAC ||
2128
+             avctx->codec_id == CODEC_ID_MP1 ||
2129
+             avctx->codec_id == CODEC_ID_MP2 ||
2130
+             avctx->codec_id == CODEC_ID_MP3 ||
2131
+             avctx->codec_id == CODEC_ID_SPEEX ||
2132
+             avctx->codec_id == CODEC_ID_CELT))
2133 2133
             return 0;
2134 2134
         break;
2135 2135
     case AVMEDIA_TYPE_VIDEO:
... ...
@@ -40,7 +40,7 @@
40 40
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
41 41
 
42 42
 #define LIBAVUTIL_VERSION_MAJOR 51
43
-#define LIBAVUTIL_VERSION_MINOR 17
43
+#define LIBAVUTIL_VERSION_MINOR 18
44 44
 #define LIBAVUTIL_VERSION_MICRO  0
45 45
 
46 46
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
... ...
@@ -65,6 +65,8 @@ static const struct {
65 65
     { AV_CPU_FLAG_SSE4,      "sse4.1"     },
66 66
     { AV_CPU_FLAG_SSE42,     "sse4.2"     },
67 67
     { AV_CPU_FLAG_AVX,       "avx"        },
68
+    { AV_CPU_FLAG_XOP,       "xop"        },
69
+    { AV_CPU_FLAG_FMA4,      "fma4"       },
68 70
     { AV_CPU_FLAG_3DNOW,     "3dnow"      },
69 71
     { AV_CPU_FLAG_3DNOWEXT,  "3dnowext"   },
70 72
 #endif
... ...
@@ -38,6 +38,8 @@
38 38
 #define AV_CPU_FLAG_SSE4         0x0100 ///< Penryn SSE4.1 functions
39 39
 #define AV_CPU_FLAG_SSE42        0x0200 ///< Nehalem SSE4.2 functions
40 40
 #define AV_CPU_FLAG_AVX          0x4000 ///< AVX functions: requires OS support even if YMM registers aren't used
41
+#define AV_CPU_FLAG_XOP          0x0400 ///< Bulldozer XOP functions
42
+#define AV_CPU_FLAG_FMA4         0x0800 ///< Bulldozer FMA4 functions
41 43
 #define AV_CPU_FLAG_IWMMXT       0x0100 ///< XScale IWMMXT
42 44
 #define AV_CPU_FLAG_ALTIVEC      0x0001 ///< standard
43 45
 
... ...
@@ -133,6 +133,15 @@ int ff_get_cpu_flags_x86(void)
133 133
             rval & AV_CPU_FLAG_SSE2 && !(ecx & 0x00000040)) {
134 134
             rval |= AV_CPU_FLAG_SSE2SLOW;
135 135
         }
136
+
137
+        /* XOP and FMA4 use the AVX instruction coding scheme, so they can't be
138
+         * used unless the OS has AVX support. */
139
+        if (rval & AV_CPU_FLAG_AVX) {
140
+            if (ecx & 0x00000800)
141
+                rval |= AV_CPU_FLAG_XOP;
142
+            if (ecx & 0x00010000)
143
+                rval |= AV_CPU_FLAG_FMA4;
144
+        }
136 145
     }
137 146
 
138 147
     if (!strncmp(vendor.c, "GenuineIntel", 12)) {
... ...
@@ -54,9 +54,12 @@ FATE_SEEK    = $(SEEK_TESTS:seek_%=fate-seek-%)
54 54
 FATE = $(FATE_ACODEC)                                                   \
55 55
        $(FATE_VCODEC)                                                   \
56 56
        $(FATE_LAVF)                                                     \
57
-       $(FATE_LAVFI)                                                    \
58 57
        $(FATE_SEEK)                                                     \
59 58
 
59
+FATE-$(CONFIG_AVFILTER) += $(FATE_LAVFI)
60
+
61
+FATE += $(FATE-yes)
62
+
60 63
 $(filter-out %-aref,$(FATE_ACODEC)): $(AREF)
61 64
 $(filter-out %-vref,$(FATE_VSYNTH1)): fate-vsynth1-vref
62 65
 $(filter-out %-vref,$(FATE_VSYNTH2)): fate-vsynth2-vref
... ...
@@ -79,7 +82,7 @@ fate-lavfi:  $(FATE_LAVFI)
79 79
 fate-seek:   $(FATE_SEEK)
80 80
 
81 81
 ifdef SAMPLES
82
-FATE += $(FATE_TESTS)
82
+FATE += $(FATE_TESTS) $(FATE_TESTS-yes)
83 83
 fate-rsync:
84 84
 	rsync -vaLW rsync://fate.ffmpeg.org/fate-suite/ $(SAMPLES)
85 85
 else
... ...
@@ -128,7 +128,7 @@ FATE_TESTS += fate-id-cin-video
128 128
 fate-id-cin-video: CMD = framecrc  -i $(SAMPLES)/idcin/idlog-2MB.cin -pix_fmt rgb24
129 129
 FATE_TESTS += fate-idroq-video-dpcm
130 130
 fate-idroq-video-dpcm: CMD = framecrc  -i $(SAMPLES)/idroq/idlogo.roq
131
-FATE_TESTS += fate-idroq-video-encode
131
+FATE_TESTS-$(CONFIG_AVFILTER) += fate-idroq-video-encode
132 132
 fate-idroq-video-encode: CMD = md5  -f image2 -vcodec pgmyuv -i $(SAMPLES)/ffmpeg-synthetic/vsynth1/%02d.pgm -sws_flags +bitexact -vf pad=512:512:80:112 -f RoQ -t 0.2
133 133
 FATE_TESTS += fate-iff-byterun1
134 134
 fate-iff-byterun1: CMD = framecrc  -i $(SAMPLES)/iff/ASH.LBM -pix_fmt rgb24