[FFmpeg-devel] determining the reference frame for motion_val
Michael Niedermayer
michaelni
Thu Aug 23 23:19:26 CEST 2007
Hi
On Thu, Aug 23, 2007 at 11:07:14AM -0500, Martin Luessi wrote:
> On 8/22/07, Michael Niedermayer <michaelni at gmx.at> wrote:
> > Hi
> >
> > On Wed, Aug 22, 2007 at 09:21:25AM -0500, Martin Luessi wrote:
> > > Hi,
> > >
> > > For my work I need to extract motion vectors from h264 video. By
> > > looking at the function ff_print_debug_info in mpegvideo.c and
> > > previous posts on this list, I figured out how to do that. Right now
> > > my motion vector extraction function accesses the motion_val table of
> > > the returned AVFrame and creates a table with one motion vector for
> > > each 8x8 block. However, I still have the following questions:
> > >
> > > 1)
> > > How can I determine which reference frame is used for a given motion
> > > vector? I use the USES_LIST macro to find out if there is a forward or
> > > backward motion vector assigned to a a given block. Let's say we have
> > > a forward motion vector, how can I find out which previous frame is
> > > used as reference? If the current frame is a P-frame and the previous
> > > one was an I-frame, obviously the previous frame is used. But what
> > > about if the current frame is a B-frame and the previous frame is B as
> > > well. As you know h264 has an option to support using B frames as
> > > reference, so the reference frame could be the previous B-frame or a
> > > I/P frame further back in the past. I hope you see what I'm getting
> > > at.
> >
> > AVFrame.ref_index
>
> Ok, thanks. I looked at the h264 code and wrote a function to copy the
> ref_index from the current frame. However, I cannot make much sense of
> the values in ref_index. My function looks something like this:
>
> void extract_ref_index(MpegEncContext * mpeg_ctx, int list, AVFrame *
> pict, uint8_t arr)
> {
> for (int mb8_y = 0; mb8_y < mpeg_ctx->mb_height * 2; mb8_y++){
> for (int mb8_x = 0; mb8_x < mpeg_ctx->mb_width * 2; mb8_x++){
> int b8_xy = mb8_x + mb8_y * mpeg_ctx->b8_stride;
> arr[mb8_x + mb8_y * 2 * mpeg_ctx->mb_width] =
> pict->ref_index[list][b8_xy];
> }
> }
> }
>
> >From the way the h264 code uses ref_index I figured that the ref_index
> has an entry for every 8x8 block and the array size is
> "mpeg_ctx->b8_stride * 2 * mpeg_ctx->mb_height * sizeof(uint8_t)",
> which means for a QVGA frame 41x30 bytes, is that correct? However, as
> I said before the values I get are kind of weird, they are mostly 0
> and sometimes 255, can anyone explain to me what this means?
there should be no 255 in a used reference, maybe its a intra block
or the ref is plain nt used (backward ref in forward predicted block)
>
> Also, does anybody know if the contents of ref_index are still valid
> when the frame is returned by avcodec_decode_vide(..)? I'm working on
they should be as valid as motion_val IIRC (if you want to be certain
read the fine source ...)
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070823/7a6b2e88/attachment.pgp>
More information about the ffmpeg-devel
mailing list