On 4/5/2018 12:09 AM, Michael Niedermayer wrote:


This does not work
breaks fate-unknown_layout-ac3

also the tests mayb too strict, there are similar codec_ids like mpeg1/2
or jpeg variants which are all basically the same from a muxers point of view

Revised patch passes FATE. Set looser conditions for mpeg-1/2/4 and jpeg muxer.

Regards,
Gyan
From a4ae3eb20af9a4c6e5feb201347b5b044541c59b Mon Sep 17 00:00:00 2001
From: Gyan Doshi <gyando...@gmail.com>
Date: Fri, 6 Apr 2018 20:21:57 +0530
Subject: [PATCH v2] avformat/rawenc: check stream type

Validate codec of stream to be muxed except for data muxer.
---
 libavformat/rawenc.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 809ca23b1a..19028329f7 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -34,12 +34,48 @@ int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
 
 static int force_one_stream(AVFormatContext *s)
 {
+enum AVCodecID id;
+const char *idname;
+
     if (s->nb_streams != 1) {
         av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
                s->oformat->name);
         return AVERROR(EINVAL);
     }
+
+    if (!strcmp("data", s->oformat->name))
+        return 0;
+
+id = s->streams[0]->codecpar->codec_id;
+idname = avcodec_get_name(id);
+
+    switch(s->streams[0]->codecpar->codec_type) {
+        case AVMEDIA_TYPE_AUDIO:
+            if (s->oformat->audio_codec != id)
+                goto fail;
+            break;
+        case AVMEDIA_TYPE_VIDEO:
+            if (strstr(s->oformat->name, "mpeg") != NULL) {
+                if (strstr(idname, "mpeg") == NULL)
+                    goto fail;
+            } else if (strstr(s->oformat->name, "m4v") != NULL) {
+                       if (strstr(idname, "mpeg4") == NULL)
+                           goto fail;
+            } else if (strstr(s->oformat->name, "jpeg") != NULL) {
+                       if (strstr(idname, "jpeg") == NULL)
+                           goto fail;
+            } else if (s->oformat->video_codec != id)
+                       goto fail;
+            break;
+        default:
+            goto fail;
+    }
+
     return 0;
+
+fail:
+    av_log(s, AV_LOG_ERROR, "Stream not of type %s\n", s->oformat->name);
+    return AVERROR(EINVAL);
 }
 
 /* Note: Do not forget to add new entries to the Makefile as well. */
-- 
2.12.2.windows.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to