diff mbox

[FFmpeg-devel] ffmpeg: Fail if the user requested impossible subtitle encoding

Message ID CAB0OVGrB-=vQkBvHPx2P_F8WbSFoRVS6UcgmZWcx8+LAajmMDg@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos June 6, 2018, 8:34 p.m. UTC
Hi!

Attached patch is meant to fix ticket #7239.

Please comment, Carl Eugen

Comments

Michael Niedermayer June 7, 2018, 9:08 p.m. UTC | #1
On Wed, Jun 06, 2018 at 10:34:42PM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch is meant to fix ticket #7239.
> 
> Please comment, Carl Eugen

>  ffmpeg.c |   17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 95832712dd42b9c4e99f2345e93a9853f1758871  0001-ffmpeg-Fail-if-the-user-requested-impossible-subtitl.patch
> From 309b7855f663053a5d11c5403a811bd723e472b9 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
> Date: Wed, 6 Jun 2018 21:09:38 +0200
> Subject: [PATCH] ffmpeg: Fail if the user requested impossible subtitle
>  encoding.

probably ok

[...]
Carl Eugen Hoyos June 9, 2018, 7:37 p.m. UTC | #2
2018-06-07 23:08 GMT+02:00, Michael Niedermayer <michael@niedermayer.cc>:
> On Wed, Jun 06, 2018 at 10:34:42PM +0200, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> Attached patch is meant to fix ticket #7239.
>>
>> Please comment, Carl Eugen
>
>>  ffmpeg.c |   17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>> 95832712dd42b9c4e99f2345e93a9853f1758871
>> 0001-ffmpeg-Fail-if-the-user-requested-impossible-subtitl.patch
>> From 309b7855f663053a5d11c5403a811bd723e472b9 Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
>> Date: Wed, 6 Jun 2018 21:09:38 +0200
>> Subject: [PATCH] ffmpeg: Fail if the user requested impossible subtitle
>>  encoding.
>
> probably ok

Patch applied.

Thank you, Carl Eugen
diff mbox

Patch

From 309b7855f663053a5d11c5403a811bd723e472b9 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Wed, 6 Jun 2018 21:09:38 +0200
Subject: [PATCH] ffmpeg: Fail if the user requested impossible subtitle
 encoding.

---
 fftools/ffmpeg.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 10f3012..d4ac690 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3485,6 +3485,23 @@  static int init_output_stream(OutputStream *ost, char *error, int error_len)
                 return ret;
             }
         }
+        if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && ost->enc->type == AVMEDIA_TYPE_SUBTITLE) {
+            int input_props = 0, output_props = 0;
+            AVCodecDescriptor const *input_descriptor =
+                avcodec_descriptor_get(dec->codec_id);
+            AVCodecDescriptor const *output_descriptor =
+                avcodec_descriptor_get(ost->enc_ctx->codec_id);
+            if (input_descriptor)
+                input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+            if (output_descriptor)
+                output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+            if (input_props && output_props && input_props != output_props) {
+                snprintf(error, error_len,
+                         "Subtitle encoding currently only possible from text to text "
+                         "or bitmap to bitmap");
+                return AVERROR_INVALIDDATA;
+            }
+        }
 
         if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
             if (ret == AVERROR_EXPERIMENTAL)
-- 
1.7.10.4