Question: I am trying to decode a H264 frame using the [libav](https://libav.org/) library. After initialising the library by allocating frame and context, I am using the following code to decode:

```
AVPacket pkt;
int got_picture, len;
av_init_packet(&pkt);
pkt.size = size;
pkt.data = buffer;
while(pkt.size > 0) {
    if((len = avcodec_decode_video2(context, frame, &got_picture, &pkt)) < 0) {
        break;
    }

    if(got_picture) {
        // Do something with the picture...
    }

    avPkt.size -= len;
    avPkt.data += len;
}

```

However, whenever I call `avcodec_decode_video2` it prints the following error in the console:

```
[...]    
[h264 @ 000000000126db40] AVC: The buffer size 210 is too short to read the nal length size 0 at the offset 210.
[h264 @ 000000000126db40] AVC: The buffer size 283997 is too short to read the nal length size 0 at the offset 283997.
[h264 @ 000000000126db40] AVC: The buffer size 17137 is too short to read the nal length size 0 at the offset 17137.
[...]

```

What am I missing? I tried searching for threads concerning a similar issue but nothing came up. Or is there a way I can debug the error to get more information about it?

Answer: 
With [wand](/questions/tagged/wand "show questions tagged 'wand'") you would use `wand.drawing.Drawing.get_font_metrics` which will return an instance of `FontMetrics` class.

Example

```py
from wand.image import Image
from wand.drawing import Drawing

with Image(filename='wizard:') as img:
    with Drawing() as context:
        context.font_family = 'monospace'
        context.font_size = 25
        metrics = context.get_font_metrics(img,
                                           "How BIG am I?",
                                           multiline=False)
        print(metrics)

#=> FontMetrics(character_width=25.0,
#               character_height=25.0,
#               ascender=23.0,
#               descender=-5.0,
#               text_width=170.0,
#               text_height=29.0,
#               maximum_horizontal_advance=50.0,
#               x1=0.0,
#               y1=0.0,
#               x2=19.21875,
#               y2=18.0,
#               x=170.0,
#               y=0.0)

```
Can you use `label:` and let ImageMagick calculate the width needed for you?

```
convert -font "Arial" -pointsize 64 label:"this is the text" out.png
identify out.png
out.png PNG 396x73 396x73+0+0 8-bit sRGB 256c 2.57KB 0.000u 0:00.000

```

or, more simply:

```
convert -font "Arial" -pointsize 64 label:"this is the text" -format %w info:
396

```

or, as Eric suggested:

```
convert -font "Arial" -pointsize 64 label:"this is the text" -format %w +identify result.png
396

```

Or, if you want to use `annotate`, you can make a larger canvas and trim it, like this:

```
convert -gravity west xc:white[1000x1000] -font "arial" -pointsize 32 -annotate 0 "this is the text" -trim -format %w info:
197

```