[FFmpeg-cvslog] mp3enc: write ISO8859-1 instead of UTF-16 when possible

Anton Khirnov git
Sun Feb 6 21:08:55 CET 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Feb  5 22:20:13 2011 +0100| [4a3556542d249718d3a7f59586ea1acc0a2d5e77] | committer: Michael Niedermayer

mp3enc: write ISO8859-1 instead of UTF-16 when possible

Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>
(cherry picked from commit 5a6de4e7e8d81169be9b6909b71e42a9ece59a82)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4a3556542d249718d3a7f59586ea1acc0a2d5e77
---

 libavformat/mp3enc.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index b2c0a7e..5921ded 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -77,6 +77,12 @@ static void id3v2_put_size(AVFormatContext *s, int size)
     put_byte(s->pb, size       & 0x7f);
 }
 
+static int string_is_ascii(const uint8_t *str)
+{
+    while (*str && *str < 128) str++;
+    return !*str;
+}
+
 /**
  * Write a text frame with one (normal frames) or two (TXXX frames) strings
  * according to encoding (only UTF-8 or UTF-16+BOM supported).
@@ -92,6 +98,12 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2
     if (url_open_dyn_buf(&dyn_buf) < 0)
         return AVERROR(ENOMEM);
 
+    /* check if the strings are ASCII-only and use UTF16 only if
+     * they're not */
+    if (enc == ID3v2_ENCODING_UTF16BOM && string_is_ascii(str1) &&
+        (!str2 || string_is_ascii(str2)))
+        enc = ID3v2_ENCODING_ISO8859;
+
     put_byte(dyn_buf, enc);
     if (enc == ID3v2_ENCODING_UTF16BOM) {
         put_le16(dyn_buf, 0xFEFF);      /* BOM */




More information about the ffmpeg-cvslog mailing list