[Libav-user] Reading exif data from jpeg programmatically

Massimo Battistel battistel at gmail.com
Wed Oct 22 18:52:51 CEST 2014


>
> Last I checked which was quite awhile ago, the EXIF was only available in
> a successfully decoded frame and the frames metadata.
>
> I mentioned this also long ago and while it does possibly make sense for
> multi-frame files, it does not make much sense for a single frame jpeg file.
>
> I don't know if this is still the case because I don't use ffmpeg for
> single frame jpegs still. It may have improved but don't know.
>
>
I tried with your advice, but no success. frame->metadata is null
(also fmt_ctx->metadata
is null).
This is the code I used for the test (there is no error checking for
simplicity):

int ret = 0;
AVFormatContext *fmt_ctx = NULL;

av_register_all();

ret = avformat_open_input(&fmt_ctx, "C:\\tmp\\still\\p.jpg", NULL, NULL);

ret = avformat_find_stream_info(fmt_ctx, NULL);

AVCodec* codec = avcodec_find_decoder(fmt_ctx->streams[0]->codec->codec_id);
ret = avcodec_open2(fmt_ctx->streams[0]->codec, codec, NULL);

AVPacket pkt;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;

ret = av_read_frame(fmt_ctx, &pkt);

AVFrame* frame = avcodec_alloc_frame();
int got_pict = 0;

do
{
   ret = avcodec_decode_video2(fmt_ctx->streams[0]->codec, frame,
&got_pict, &pkt);
  av_packet_unref(&pkt);

  pkt.data = NULL; // request flush
  pkt.size = 0;
}
while (!got_pict && ret >= 0);

// TAGS reading
AVDictionaryEntry *tag = NULL;
while (tag = av_dict_get(frame->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))
{
   printf("%s=%s\n", tag->key, tag->value);
}

avformat_close_input(&fmt_ctx);


Could someone please help me finding what's wrong?

thanks,
MB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20141022/9118d588/attachment.html>


More information about the Libav-user mailing list