[FFmpeg-user] JSON writer Introduces malformed string when serializing usIng GSON

Moritz Barsnick barsnick at gmx.net
Thu Feb 13 13:00:36 EET 2020


(Replying to myself.)

On Thu, Feb 13, 2020 at 11:52:11 +0100, Moritz Barsnick wrote:
> On Thu, Feb 13, 2020 at 13:22:18 +0300, Otieno Rowland wrote:
> > For some reason when I try to read some metadata which has some text with
> > double quotes, FFprobe tries to escape them from "text here"  into \"text
> > here\", which causes lots of problems on my side, as I unable to serialize
> > the JSON properly when trying to convert to Java code.
>
> Can you give a complete example of the metadata, as shown by "ffmpeg
> -i" or "ffprobe" (without "-hide_banner", and without the other ffprobe
> options), the JSON output, and what you are expecting, please?

Sorry, I did it on my own. Assuming you mean something like this:

$ ffmpeg -f lavfi -i testsrc=d=0.1 -metadata blafoo='This is some "quoted" text' -f matroska - | ffprobe -print_format json -show_format -

the JSON output is
    "format": {
        "filename": "pipe:",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "matroska,webm",
        "format_long_name": "Matroska / WebM",
        "probe_score": 100,
        "tags": {
            "BLAFOO": "This is some \"quoted\" text",
            "ENCODER": "Lavf58.35.102"
        }
    }

This is fully correct JSON. What you need is a proper JSON parser - it
will understand this quoting and escaping. I'm sure there are many JSON
parsers available for Java. *Every* one of them must handle this. (I
only have experience with various Perl, C and C++ parsers.) Writing
your own can trip over this, but shouldn't be too tricky, JSON doesn't
allow for many exceptions in my experience (unlike the curiosities of
JavaScript/ECMAScript).

Cheers,
Moritz


More information about the ffmpeg-user mailing list