diff mbox

[FFmpeg-devel] avformat/rawenc: check stream type

Message ID cca3d192-00b8-1b28-1b2b-b00e04e27d70@gmail.com
State Superseded
Headers show

Commit Message

Gyan April 4, 2018, 10:23 a.m. UTC
From f86916b9e1128a4e41501f4d5b189749a344862f Mon Sep 17 00:00:00 2001
From: Gyan Doshi <gyandoshi@gmail.com>
Date: Wed, 4 Apr 2018 15:45:18 +0530
Subject: [PATCH] avformat/rawenc: check stream type

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

Comments

Michael Niedermayer April 4, 2018, 6:39 p.m. UTC | #1
On Wed, Apr 04, 2018 at 03:53:25PM +0530, Gyan Doshi wrote:
>  rawenc.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> c144b841348e9af26d80e0014daf63c5b2477467  0001-avformat-rawenc-check-stream-type.patch
> From f86916b9e1128a4e41501f4d5b189749a344862f Mon Sep 17 00:00:00 2001
> From: Gyan Doshi <gyandoshi@gmail.com>
> Date: Wed, 4 Apr 2018 15:45:18 +0530
> Subject: [PATCH] avformat/rawenc: check stream type
> 
> Validate codec of stream to be muxed except for data muxer.
> ---
>  libavformat/rawenc.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
> index 809ca23b1a..77cbc5f6fc 100644
> --- a/libavformat/rawenc.c
> +++ b/libavformat/rawenc.c
> @@ -39,6 +39,16 @@ static int force_one_stream(AVFormatContext *s)
>                 s->oformat->name);
>          return AVERROR(EINVAL);
>      }
> +
> +    if (strcmp("data", s->oformat->name)) {
> +        if (s->oformat->audio_codec != AV_CODEC_ID_NONE &&
> +            s->oformat->audio_codec != s->streams[0]->codecpar->codec_id ||
> +            s->oformat->video_codec != s->streams[0]->codecpar->codec_id) {
> +            av_log(s, AV_LOG_ERROR, "Stream not of type %s\n",
> +                   s->oformat->name);

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

[...]
Gyan April 4, 2018, 8:04 p.m. UTC | #2
On 4/5/2018 12:09 AM, Michael Niedermayer wrote:

> 
> This does not work
> breaks fate-unknown_layout-ac3

Silly mistake. Fixed locally.

> 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

Will change to a switch block to take care of these promiscuous cases.


Regards,
Gyan
Carl Eugen Hoyos April 7, 2018, 11:05 a.m. UTC | #3
2018-04-04 12:23 GMT+02:00, Gyan Doshi <gyandoshi@gmail.com>:
> Validate codec of stream to be muxed except for data muxer.

What issue does your patch fix?

Carl Eugen
Gyan April 7, 2018, 11:32 a.m. UTC | #4
On 4/7/2018 4:35 PM, Carl Eugen Hoyos wrote:
> 2018-04-04 12:23 GMT+02:00, Gyan Doshi <gyandoshi@gmail.com>:
>> Validate codec of stream to be muxed except for data muxer.
> 
> What issue does your patch fix?

Had an user on SE sometime back extract a video stream to a .h264 (in 
order to retime PTS). The retiming didn't work since the stream was 
actually mpeg4 but the muxer hasn't complained. Might have been fine but 
ffmpeg's format probe settled on h264 so user couldn't proceed until we 
examined the source. So just added some basic checks. Initially strict 
but loosened due to Michael's feedback.

Users can still use data or rawvideo muxer to extract any random stream.

(I do see that rawvideo does not enforce a single stream. Why?)

Regards,
Gyan
Carl Eugen Hoyos April 7, 2018, 7:49 p.m. UTC | #5
2018-04-07 13:32 GMT+02:00, Gyan Doshi <gyandoshi@gmail.com>:
> On 4/7/2018 4:35 PM, Carl Eugen Hoyos wrote:
>> 2018-04-04 12:23 GMT+02:00, Gyan Doshi <gyandoshi@gmail.com>:
>>> Validate codec of stream to be muxed except for data muxer.
>>
>> What issue does your patch fix?
>
> Had an user on SE sometime back extract a video stream to a .h264 (in
> order to retime PTS).

Does this work at all?

> The retiming didn't work since the stream was
> actually mpeg4 but the muxer hasn't complained. Might have been fine but
> ffmpeg's format probe settled on h264 so user couldn't proceed until we
> examined the source.

A warning would be sufficient.

Carl Eugen
Gyan April 8, 2018, 5:09 a.m. UTC | #6
On 4/8/2018 1:19 AM, Carl Eugen Hoyos wrote:
> 2018-04-07 13:32 GMT+02:00, Gyan Doshi <gyandoshi@gmail.com>:

>> Had an user on SE sometime back extract a video stream to a .h264 (in
>> order to retime PTS).
> 
> Does this work at all?

With input -r, yes. For streams with b-pyramid, mp4box does.

> A warning would be sufficient.

That won't be useful in batch mode, or good when a raw muxer does 
something besides just a packet dump. Besides, why allow ffmpeg to 
produce files with mismatched extensions, when input probing can't 
obviate the issue?

Gyan
diff mbox

Patch

diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 809ca23b1a..77cbc5f6fc 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -39,6 +39,16 @@  static int force_one_stream(AVFormatContext *s)
                s->oformat->name);
         return AVERROR(EINVAL);
     }
+
+    if (strcmp("data", s->oformat->name)) {
+        if (s->oformat->audio_codec != AV_CODEC_ID_NONE &&
+            s->oformat->audio_codec != s->streams[0]->codecpar->codec_id ||
+            s->oformat->video_codec != s->streams[0]->codecpar->codec_id) {
+            av_log(s, AV_LOG_ERROR, "Stream not of type %s\n",
+                   s->oformat->name);
+            return AVERROR(EINVAL);
+        }
+    }
     return 0;
 }