These changes add support for copying overlay streams.

So to extract IGS menu from m2ts file:
$ avconv -i source.m2ts -vn -an -sn output.mnu

To mux IGS menu with h264 video in ts:
$ avconv -i video.264 -i test.mnu -f mpegts out.ts

Still todo: update mpegts muxer to set correct PID so
output may be compatible to BDAV format.

Signed-off-by: David Girault <david at dhgirault.fr>
---
 avconv.c   |   26 ++++++++++++++++++++++++++
 cmdutils.h |    1 +
 2 files changed, 27 insertions(+)

diff --git a/avconv.c b/avconv.c
index 23ee164..481813f 100644
--- a/avconv.c
+++ b/avconv.c
@@ -341,6 +341,7 @@ typedef struct OptionsContext {
     int video_disable;
     int audio_disable;
     int subtitle_disable;
+    int overlay_disable;
     int data_disable;
 
     /* indexed by output file stream index */
@@ -2440,6 +2441,7 @@ static int transcode_init(void)
                 codec->width  = icodec->width;
                 codec->height = icodec->height;
                 break;
+            case AVMEDIA_TYPE_OVERLAY:
             case AVMEDIA_TYPE_DATA:
             case AVMEDIA_TYPE_ATTACHMENT:
                 break;
@@ -3305,6 +3307,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
         case AVMEDIA_TYPE_DATA:
         case AVMEDIA_TYPE_SUBTITLE:
         case AVMEDIA_TYPE_ATTACHMENT:
+        case AVMEDIA_TYPE_OVERLAY:
         case AVMEDIA_TYPE_UNKNOWN:
             break;
         default:
@@ -3896,6 +3899,15 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc)
     return ost;
 }
 
+static OutputStream *new_overlay_stream(OptionsContext *o, AVFormatContext *oc)
+{
+    OutputStream *ost;
+
+    ost = new_output_stream(o, oc, AVMEDIA_TYPE_OVERLAY);
+    ost->stream_copy = 1;
+    return ost;
+}
+
 /* arg format is "output-stream-index:streamid-value". */
 static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)
 {
@@ -4046,6 +4058,7 @@ static void opt_output_file(void *optctx, const char *filename)
             case AVMEDIA_TYPE_VIDEO:    o->video_disable    = 1; break;
             case AVMEDIA_TYPE_AUDIO:    o->audio_disable    = 1; break;
             case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
+            case AVMEDIA_TYPE_OVERLAY:  o->overlay_disable = 1; break;
             }
             init_output_filter(ofilter, o, oc);
         }
@@ -4098,6 +4111,15 @@ static void opt_output_file(void *optctx, const char *filename)
                     break;
                 }
         }
+
+        /* overlay: pick first */
+        if (!o->overlay_disable && oc->oformat->overlay_codec != CODEC_ID_NONE) {
+            for (i = 0; i < nb_input_streams; i++)
+                if (input_streams[i]->st->codec->codec_type == AVMEDIA_TYPE_OVERLAY) {
+                    NEW_STREAM(overlay, i);
+                    break;
+                }
+        }
         /* do something with data? */
     } else {
         for (i = 0; i < o->nb_stream_maps; i++) {
@@ -4135,6 +4157,7 @@ loop_end:
                 case AVMEDIA_TYPE_AUDIO:    ost = new_audio_stream(o, oc);    break;
                 case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
                 case AVMEDIA_TYPE_DATA:     ost = new_data_stream(o, oc);     break;
+                case AVMEDIA_TYPE_OVERLAY:  ost = new_overlay_stream(o, oc);     break;
                 case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;
                 default:
                     av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d:%d - unsupported type.\n",
@@ -4786,6 +4809,9 @@ static const OptionDef options[] = {
     { "scodec", HAS_ARG | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
     { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
 
+    /* overlay options */
+    { "on", OPT_BOOL | OPT_OVERLAY | OPT_OFFSET, {.off = OFFSET(overlay_disable)}, "disable overlay" },
+
     /* grab options */
     { "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
 
diff --git a/cmdutils.h b/cmdutils.h
index 5dac130..bcc33c7 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -144,6 +144,7 @@ typedef struct {
                                    an int containing element count in the array. */
 #define OPT_TIME  0x10000
 #define OPT_DOUBLE 0x20000
+#define OPT_OVERLAY 0x40000
      union {
         void *dst_ptr;
         int (*func_arg)(const char *, const char *);
-- 
1.7.9.5

