0

My system is Windows and I use Cygwin to run bash and shell file. Check a script, see the link below, which according to its author creates the metadata of an image to be attached to the ogg file, it happens that the script is generating incomplete data.

I did some tests with the first script posted by @Gaff here:Embed album art in OGG through command line in linux that do not generate the metadata correctly, see the tests below:

Metadata block picture results according to defined option in the $EASYTAG variable of the script.

Note:

When we run the script without the -e parameter at the end, the $EASYTAG variable will have the value of N and when we run the script with the -e parameter at the end, the $EASYTAG variable will have the Y value.

Script execution command without -e at the end :

sh oggart.sh "audio.ogg" "cover.jpg"

Output ffprobe in audio file with option $EASYTAG variable = N, generated by the script:

[ogg @ 0000023748f0f300] Invalid picture type: -2555936.
[ogg @ 0000023748f0f300] Could not read mimetype from an attached picture.
Input #0, ogg, from 'audio.ogg':
  Duration: 00:03:26.60, start: 0.000000, bitrate: 402 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.12.100 libvorbis
      album           : CMG Clássicos Pop Rock Nacionais
      artist          : Lobão
      date            : 1988
      genre           : Clássico Pop Rock Nacional
      TKEY            : E m
      title           : Cuidado!

Script execution command with -e at the end :

sh oggart.sh "audio.ogg" "cover.jpg" -e

Output ffprobe in audio file with option $EASYTAG variable = Y, generated by the script:

Input #0, ogg, from 'audio.ogg':
  Duration: 00:03:26.60, start: 0.000000, bitrate: 402 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.12.100 libvorbis
      album           : CMG Clássicos Pop Rock Nacionais
      artist          : Lobão
      date            : 1988
      genre           : Clássico Pop Rock Nacional
      TKEY            : E m
      title           : Cuidado!
      COVERART        : /9j/4AAQSkZJRgABAQEASABIAAD/4ROiRXhpZgAASUkqAAgAAAACADIBAgAUAAAAJ
                        gAAAGmHBAABAAAAOgAAAEAAAAAyMDE5OjEwOjE4IDEzOjU4OjU5AAAAAAAAAAMAAw
                        EEAAEAAAAGAAAAAQIEAAEAAABqAAAAAgIEAAEAAAAwEwAAAAAAAP/Y/+AAEEpGSUY
                        AAQEAAAEAAQAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBg

In $EASYTAG = N show:

[ogg @ 0000023748f0f300] Invalid picture type: -2555936.
[ogg @ 0000023748f0f300] Could not read mimetype from an attached picture.

In $EASYTAG = Y, does not show an error message, but includes the COVERART in a Metadata field with incomplete data:

COVERART        : /9j/4AAQSkZJRgABAQEASABIAAD/4ROiRXhpZgAASUkqAAgAAAACADIBAgAUAAAAJ
                  gAAAGmHBAABAAAAOgAAAEAAAAAyMDE5OjEwOjE4IDEzOjU4OjU5AAAAAAAAAAMAAw
                  EEAAEAAAAGAAAAAQIEAAEAAABqAAAAAgIEAAEAAAAwEwAAAAAAAP/Y/+AAEEpGSUY
                  AAQEAAAEAAQAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBg

Note: The COVERAT field shows only the first 255 characters of the generated metadata block picture... this may be happening precisely because of the lack information in the data block related to the identification of the file, that is in its header, where the program identifies the record and inserts it correctly as a cover art in the file.

The ogg metadata block picture structure appears to be the same as flac's.

Script is generating incomplete metadata block picture, seems to be missing metadata header. Note below, mainly, the information in --add padding. The script doesn't seem to be considering the 4 bytes when generating the metadata block picture.

--import-picture-from={FILENAME|SPECIFICATION}  
Import a picture and store it in a PICTURE metadata block. 
See the flac option --picture for an explanation of the SPECIFICATION syntax.

--add-padding=# Add a padding block of the given length (in bytes). The overall length of the new block will be 4 + length; the extra 4 bytes is for the metadata block header.

Note: Maybe that's the problem with your file not being generated with the header.

--dont-use-padding
By default metaflac tries to use padding where possible to avoid rewriting the entire file if the metadata size changes. Use this option to tell metaflac to not take advantage of padding this way.

Note: Another possibility of metadata generation error, look here: https://github.com/taglib/taglib

Is there no ffmpeg function or program that does the conversion correctly so that it can be used in a batch file?

@Tom Yan, first i wanted to thank you for your post, because it was exactly what I was looking for many days, thank you!

I followed your step by step to run vorbis_ca, but I had some problems:

Step 1:

I created a folder called Vorbis in the following path:
C:\Users\CMG\Vorbis

I copied the vorbis_ca.c into the Vorbis folder and compiled the file:
gcc vorbis_ca.c -o vorbis_ca.exe

I changed the path to my desktop, which is where the image is on my PC:
cd "C:/Users/CMG/Desktop"

I ran the file command on the image:
file cover.jpeg

Output file command:

Exif Standard: [TIFF image data, little-endian, direntries=2, datetime=2019:10:18 13:58:59], baseline, 
precision 8, 1018x1023, components 3

Step 2:

I ran the ./vorbis_ca command:
$ ./vorbis_ca 1018 1023 cover.jpeg | hexdump -C

Output ./vorbis_ca command:
-bash: ./vorbis_ca: No such file or directory

so i tried:

"C:/Users/CMG/Vorbis/"./vorbis_ca 1018 1023 cover.jpeg | hexdump -C

Output ./vorbis_ca command inserting full path:

00000000  00 00 00 03 00 00 00 09  69 6d 61 67 65 2f 6a 70  |........image/jp|
00000010  67 00 00 00 00 00 00 03  fa 00 00 03 ff 00 00 00  |g...............|
00000020  18 00 00 00 00 00 04 39  24                       |.......9$|
00000029

./vorbis_ca only runs when I put the full path.

Note:

When I compiled the vorbis_ca.c which is in the folder in the path: C:\Users\CMG\Vorbis I can't run the generated ./vorbis_ca in any location, how to make ./vorbis_ca run without me having to put the full path? eg. in the file cover.jpeg command, I didn't need to put the full path of it for it to work.

Step 3:

Run vorbiscomment command: note that I had to put the full path of ./vorbis_ca in this command.

$ vorbiscomment -w -t "METADATA_BLOCK_PICTURE=$(("C:/Users/CMG/Vorbis/"./vorbis_ca 1018 1023 cover.jpeg; cat cover.jpeg) | base64 -w 0)" "audio_cover.ogg"

Output vorbiscomment command:

-bash: /cygdrive/c/vorbis-tools-master/bin/x64/vorbiscomment: Argument list too long

Why did the above message appear when I ran vorbiscomment?

Another question: in Step 2, I ran the command ./vorbis_ca 1018 1023 cover.jpeg | hexdump -C and your last command again has the ./vorbis_ca 1018 1023 cover.jpeg. This command needs to be run twice, or did you just show it in detail as an example?

That is, the official command is the last command, correct?

Clamarc
  • 663

1 Answers1

1

As I mentioned in my comment, METADATA_BLOCK_PICTURE is not expected to consists of just the image file. You need to "prefix" the image file with some more metadata bytes as per the specification:

Here's an example C program that outputs such a prefix:

$ ./vorbis_ca 
Usage: ./vorbis_ca width height image_file

The image width and height can be obtained with e.g. file (note that they are near the end of the output; not to be confused with density):

$ file test_ca.jpg 
test_ca.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, comment: "Created with GIMP", progressive, precision 8, 600x600, components 3

Using hexdump -C to see what (bytes) it actually outputs:

$ ./vorbis_ca 600 600 test_ca.jpg | hexdump -C
00000000  00 00 00 03 00 00 00 09  69 6d 61 67 65 2f 6a 70  |........image/jp|
00000010  67 00 00 00 00 00 00 02  58 00 00 02 58 00 00 00  |g.......X...X...|
00000020  18 00 00 00 00 00 00 37  e6                       |.......7.|
00000029

(FFmpeg doesn't really care about the width and height in the prefix though, so you may as well just use 0 for both of them if you don't care about standard conformance / portability of the file)

Reproducing the problem you bumped into:

$ vorbiscomment -w -t "METADATA_BLOCK_PICTURE=$(cat test_ca.jpg | base64 -w 0)" test.ogg 
$ ffprobe /tmp/test.ogg 
ffprobe version n5.0 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 11.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
[ogg @ 0x55910a096700] Invalid picture type: -2555936.
[ogg @ 0x55910a096700] Could not read mimetype from an attached picture.
Input #0, ogg, from '/tmp/test.ogg':
  Duration: 00:00:10.00, start: 0.000000, bitrate: 19 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 112 kb/s

With the prefix added, problem solved:

$ vorbiscomment -w -t "METADATA_BLOCK_PICTURE=$((./vorbis_ca 600 600 test_ca.jpg; cat test_ca.jpg) | base64 -w 0)" test.ogg 
$ ffprobe /tmp/test.ogg 
ffprobe version n5.0 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 11.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, ogg, from '/tmp/test.ogg':
  Duration: 00:00:10.00, start: 0.000000, bitrate: 19 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 112 kb/s
  Stream #0:1: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 600x600 [SAR 300:300 DAR 1:1], 90k tbr, 90k tbn (attached pic)
    Metadata:
      comment         : Cover (front)
$ 

(Note that the prefix is base64-encoded as well)

Tom Yan
  • 10,996