Browse code

ffmpeg: accept + prefix to -pix_fmt option to disable automatic conversions.

Nicolas George authored on 2012/04/27 17:55:12
Showing 3 changed files
... ...
@@ -29,6 +29,7 @@ version next:
29 29
 - add libavresample audio conversion library for compatibility
30 30
 - MicroDVD decoder
31 31
 - Avid Meridien (AVUI) decoder
32
+- accept + prefix to -pix_fmt option to disable automatic conversions.
32 33
 
33 34
 
34 35
 version 0.10:
... ...
@@ -418,6 +418,14 @@ also sources and sinks).  This is an alias for @code{-filter:v}.
418 418
 @item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream})
419 419
 Set pixel format. Use @code{-pix_fmts} to show all the supported
420 420
 pixel formats.
421
+If the selected pixel format can not be selected, ffmpeg will print a
422
+warning and select the best pixel format supported by the encoder.
423
+If @var{pix_fmt} is prefixed by a @code{+}, ffmpeg will exit with an error
424
+if the requested pixel format can not be selected, and automatic conversions
425
+inside filter graphs are disabled.
426
+If @var{pix_fmt} is a single @code{+}, ffmpeg selects the same pixel format
427
+as the input (or graph output) and automatic conversions are disabled.
428
+
421 429
 @item -sws_flags @var{flags} (@emph{input/output})
422 430
 Set SwScaler flags.
423 431
 @item -vdt @var{n}
... ...
@@ -319,6 +319,7 @@ typedef struct OutputStream {
319 319
     int copy_initial_nonkeyframes;
320 320
 
321 321
     enum PixelFormat pix_fmts[2];
322
+    int keep_pix_fmt;
322 323
 } OutputStream;
323 324
 
324 325
 
... ...
@@ -706,6 +707,15 @@ static enum PixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum Pixe
706 706
 
707 707
 static char *choose_pixel_fmts(OutputStream *ost)
708 708
 {
709
+    if (ost->keep_pix_fmt) {
710
+        if (ost->filter)
711
+            avfilter_graph_set_auto_convert(ost->filter->graph->graph,
712
+                                            AVFILTER_AUTO_CONVERT_NONE);
713
+        if (ost->st->codec->pix_fmt == PIX_FMT_NONE)
714
+            return NULL;
715
+        ost->pix_fmts[0] = ost->st->codec->pix_fmt;
716
+        return ost->pix_fmts;
717
+    }
709 718
     if (ost->st->codec->pix_fmt != PIX_FMT_NONE) {
710 719
         return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt)));
711 720
     } else if (ost->enc->pix_fmts) {
... ...
@@ -835,6 +845,10 @@ static int configure_video_filters(FilterGraph *fg)
835 835
             return ret;
836 836
     }
837 837
 
838
+    if (ost->keep_pix_fmt)
839
+        avfilter_graph_set_auto_convert(fg->graph,
840
+                                        AVFILTER_AUTO_CONVERT_NONE);
841
+
838 842
     if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
839 843
         return ret;
840 844
 
... ...
@@ -4661,6 +4675,11 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
4661 4661
 
4662 4662
         video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
4663 4663
         MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
4664
+        if (frame_pix_fmt && *frame_pix_fmt == '+') {
4665
+            ost->keep_pix_fmt = 1;
4666
+            if (!*++frame_pix_fmt)
4667
+                frame_pix_fmt = NULL;
4668
+        }
4664 4669
         if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {
4665 4670
             av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
4666 4671
             exit_program(1);