Hi all.

I'm writing a java tool using a ffmpeg wrapper (ffmpeg-java) while using
version snv15986 of libs for testing.
The purpose of this tool is to get video information a bit like what
MediaInfo does but as i'm using both java and ffmpeg i hope to be more
cross platform.
For the most part everthing works fine and i can get most of the
information i want but i'm having some dificulties with some bits and i
hope someone can help me.

Okay, by default we can get Pixel width and height from a video stream
AVCodecContext structure but at least for matroska we can have
display_width and display_height and currently i don't see any way to get
those values from the available structures, how should i get this
information which helps in finding out the aspect ratio of anamorphic
videos.
The other issue i'm having is with AVPacket duration, the documentation
says it's the duration of a packet in time_base units or 0 if unknown, but
i'm getting wrong values.

this is my code:

AVStreamData is a structure which holds long values for both size and
duration, bitrate and timebase are doubles.

final AVPacket packet = new AVPacket();
while (AVFORMAT.av_read_frame(formatCtx, packet) >= 0) {
        if (this.streams[packet.stream_index] == null)
this.streams[packet.stream_index] = new AVStreamData();
        this.streams[packet.stream_index].size += packet.size;
        this.streams[packet.stream_index].duration += packet.duration;
        
        // Free the packet that was allocated by av_read_frame
           // AVFORMAT.av_free_packet(packet.getPointer()) - cannot be  
called
because it is an inlined function.
           // so we'll just do the JNA equivalent of the inline:
        if (packet.destruct != null)
                packet.destruct.callback(packet);
}
                
// fill in computed bitrate for audio and video streams
for (int i = 0; i < formatCtx.nb_streams; i++) {
        if (this.streams[i] == null) continue;
        if (this.streams[i].type != AVCodecLibrary.CODEC_TYPE_VIDEO &&
this.streams[i].type != AVCodecLibrary.CODEC_TYPE_AUDIO) continue;
        if (this.streams[i].duration <= 0) continue; // can't have this
        int den = (int)(this.streams[i].duration * this.streams[i].timebase);
        this.streams[i].duration = den;
        long num = this.streams[i].size * 8;
        this.streams[i].bitrate = num / den;
}

Here is the example of the output of the program for a matroska file

file: [gg]_Toradora_-_01_[E2AF98B5].mkv
        format: matroska
        size: 251254774 bytes
        duration: 00:23:39 (1419.36)
        stream [video]:
                codec: h264
                size: 216919898 bytes
                duration: 00:23:43 (1423.0)
                bitrate: 1219 kbps
                resolution: 848x480
                fps: 23,976
                picture format: yuv420p
        stream [audio]:
                codec: aac
                size: 33340848 bytes
                duration: 00:23:11 (1391.0)
                bitrate: 191 kbps
                language: jpn
                channels: stereo
                sample rate: 48000 Hz
                sample format: s16

As you can see the duration of both the audio and video streams are
different from the one got from AVFormatContext, while it's possible for a
stream to run for less time i don't think it's possible for a stream to be
longer than the total duration.
For comparisson here is the output of MediaInfo for the same file.

Duration: 00:23:39 (1419.36) - WARNING: Differs from video duration! (5.32
sec)

Track #1: default video (Toradora! - 01)
        lang: jpn (2)
        codc: V_MPEG4/ISO/AVC -> H264/AVC (22)
        reso: 848x480 -> Unknown (aka not common)
        fram: 23.976025 fps
        rate: 1227 kbps (1227.236450)
        dura: 00:23:34 (1414.037964)
        size: 206.87 MB (216919898)
Track #2: default audio (AAC 2.0)
        lang: jpn -> Japanese (2)
        codc: A_AAC -> AAC (9)
        chan: 2 -> Stereo
        samp: 48000 Hz
        rate: 189 kbps (189.07)
        dura: 00:23:34 (1413.93)
        size: 31.87 MB (33416543)
(MediaInfoLib - v0.7.5.2 CVS)

Am i overlooking something while getting the durations and size, is there
some other method i should be using that works better?

thanks in advance for any help.

Miguel Gomes
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to