Flip in sws_scale

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Flip in sws_scale

Rômulo Fernandes
Hello,

I'm using libswscale to scale and convert pixel format from frames that I
capture from the screen. In my windows build the frames that I capture are
in DIB format. I'm using FFMPEG SVN rev 16437.

Calling sws_scale normally I get the image correctly, except that it's
vertically flipped.

If I change the srcSliceY from 0 to srcHeight and srcSliceH from srcHeight
to 0, I get a grey image (with correct dimensions).
If I keep the srcSliceY in 0 and change srcSliceH from srcHeight to
-srcHeight, I also get that grey image.

Is there a way to make sws_scale flip the image for me ?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Stefano Sabatini
On date Thursday 2009-01-08 17:08:26 -0200, Rômulo Fernandes encoded:
> Hello,
>
> I'm using libswscale to scale and convert pixel format from frames that I
> capture from the screen. In my windows build the frames that I capture are
> in DIB format. I'm using FFMPEG SVN rev 16437.

DIB format? Can you explain what is it?
 
> Calling sws_scale normally I get the image correctly, except that it's
> vertically flipped.
>
> If I change the srcSliceY from 0 to srcHeight and srcSliceH from srcHeight
> to 0, I get a grey image (with correct dimensions).
> If I keep the srcSliceY in 0 and change srcSliceH from srcHeight to
> -srcHeight, I also get that grey image.
>
> Is there a way to make sws_scale flip the image for me ?

No, you need to use a filter for that. Check out the code of
libavfilter in the SOC repo.

Regards.
--
ffmpeg-user random tip #3
Some few multimedia formats (mpeg-1, mpeg-2:PS, DV) support physical merge
consistency, which means you can merge two files with cat. E.g.:
cat input1.mpeg input2.mpeg > output.mpeg
See: http://ffmpeg.mplayerhq.hu/faq.html#SEC25
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Jason Garrett-Glaser
On Thu, Jan 8, 2009 at 3:51 PM, Stefano Sabatini
<[hidden email]> wrote:
> On date Thursday 2009-01-08 17:08:26 -0200, Rômulo Fernandes encoded:
>> Hello,
>>
>> I'm using libswscale to scale and convert pixel format from frames that I
>> capture from the screen. In my windows build the frames that I capture are
>> in DIB format. I'm using FFMPEG SVN rev 16437.
>
> DIB format? Can you explain what is it?

http://en.wikipedia.org/wiki/Device-independent_bitmap

Dark Shikari
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Rômulo Fernandes
The DIB that I have is basically an BGR array (1 byte per component) with
32-bit alignment per line. And the lines are in reverse order (last line
first).

It's something like this:

| Line N                      | Line N-1                    |...
|B|G|R|B|G|R|...|B|G|R|Padding|B|G|R|B|G|R|...|B|G|R|Padding|...

The problem is not with the DIB structure, because it works without
flipping. The only problem is that I'm being able make sws_scale flip it for
me, if it's really possible.

On Thu, Jan 8, 2009 at 8:27 PM, Jason Garrett-Glaser
<[hidden email]>wrote:

> On Thu, Jan 8, 2009 at 3:51 PM, Stefano Sabatini
> <[hidden email]> wrote:
> > On date Thursday 2009-01-08 17:08:26 -0200, Rômulo Fernandes encoded:
> >> Hello,
> >>
> >> I'm using libswscale to scale and convert pixel format from frames that
> I
> >> capture from the screen. In my windows build the frames that I capture
> are
> >> in DIB format. I'm using FFMPEG SVN rev 16437.
> >
> > DIB format? Can you explain what is it?
>
> http://en.wikipedia.org/wiki/Device-independent_bitmap
>
> Dark Shikari
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Stefano Sabatini
Top-posting is frowned upon here.

On date Thursday 2009-01-08 20:39:08 -0200, Rômulo Fernandes encoded:

> The DIB that I have is basically an BGR array (1 byte per component) with
> 32-bit alignment per line. And the lines are in reverse order (last line
> first).
>
> It's something like this:
>
> | Line N                      | Line N-1                    |...
> |B|G|R|B|G|R|...|B|G|R|Padding|B|G|R|B|G|R|...|B|G|R|Padding|...
>
> The problem is not with the DIB structure, because it works without
> flipping. The only problem is that I'm being able make sws_scale flip it for
> me, if it's really possible.

I don't think sws_scale() support vertical flipping, furthermore I don't
think libav* supports that kind of video frame, check
libavutil/avutil.h for the definition of all the formats supported.

And I still don't know how do you set the sws context, that is which
source pixel format do you set.

But you should be able to easily convert those frames to your
favourite pixel format (supported by ffmpeg) with some routine, then
use sws_scale() to convert/scale.

Or even better you could add support to that format into FFmpeg
itself.

[...]

Regards.
--
ffmpeg-user random tip #7
If you're asking about problems with an ffmpeg tool, *always* post the
command you're using and the complete output.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Ví­ctor Paesa
In reply to this post by Rômulo Fernandes
Hi,

Romulo Fernandes said:

> Hello,
>
> I'm using libswscale to scale and convert pixel format from frames that
> I capture from the screen. In my windows build the frames that I capture
> are in DIB format. I'm using FFMPEG SVN rev 16437.
>
> Calling sws_scale normally I get the image correctly, except that it's
> vertically flipped.
>
> If I change the srcSliceY from 0 to srcHeight and srcSliceH from
> srcHeight to 0, I get a grey image (with correct dimensions).
> If I keep the srcSliceY in 0 and change srcSliceH from srcHeight to
> -srcHeight, I also get that grey image.
>
> Is there a way to make sws_scale flip the image for me ?

I faintly recall that using a negative value for some vertical parameter
flips it.
Don't remember more, you'll need to search the mail archives or run some
experiments.

Regards,
Víctor


_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Ivo-5
On Friday 09 January 2009 10:30, Víctor Paesa wrote:

> Romulo Fernandes said:
> > I'm using libswscale to scale and convert pixel format from frames that
> > I capture from the screen. In my windows build the frames that I
> > capture are in DIB format. I'm using FFMPEG SVN rev 16437.
> >
> > Calling sws_scale normally I get the image correctly, except that it's
> > vertically flipped.
> >
> > If I change the srcSliceY from 0 to srcHeight and srcSliceH from
> > srcHeight to 0, I get a grey image (with correct dimensions).
> > If I keep the srcSliceY in 0 and change srcSliceH from srcHeight to
> > -srcHeight, I also get that grey image.
> >
> > Is there a way to make sws_scale flip the image for me ?
>
> I faintly recall that using a negative value for some vertical parameter
> flips it.
> Don't remember more, you'll need to search the mail archives or run some
> experiments.

I am not sure on the details either anymore (has been a while since I last
worked on swscale), but I think you can use a negative stride for either
the source or the destination image. In that case, you also need to point
to the last scanline, instead of the first.

--Ivo
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Rômulo Fernandes
There is a commentary in the source code of sws_scale, saying about
flipping. I read the code it a little, and I thought that swapping the
srcSliceY with srcSliceH should do the trick, but instead I got a gray
image.

On Fri, Jan 9, 2009 at 9:49 AM, Ivo <[hidden email]> wrote:

> On Friday 09 January 2009 10:30, Víctor Paesa wrote:
> > Romulo Fernandes said:
> > > I'm using libswscale to scale and convert pixel format from frames that
> > > I capture from the screen. In my windows build the frames that I
> > > capture are in DIB format. I'm using FFMPEG SVN rev 16437.
> > >
> > > Calling sws_scale normally I get the image correctly, except that it's
> > > vertically flipped.
> > >
> > > If I change the srcSliceY from 0 to srcHeight and srcSliceH from
> > > srcHeight to 0, I get a grey image (with correct dimensions).
> > > If I keep the srcSliceY in 0 and change srcSliceH from srcHeight to
> > > -srcHeight, I also get that grey image.
> > >
> > > Is there a way to make sws_scale flip the image for me ?
> >
> > I faintly recall that using a negative value for some vertical parameter
> > flips it.
> > Don't remember more, you'll need to search the mail archives or run some
> > experiments.
>
> I am not sure on the details either anymore (has been a while since I last
> worked on swscale), but I think you can use a negative stride for either
> the source or the destination image. In that case, you also need to point
> to the last scanline, instead of the first.
>
> --Ivo
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Ph0t0n
In reply to this post by Rômulo Fernandes
A filter would work, but if you're doing a conversion/scaling anyway with sw_scale(), theoretically it's faster to flip at the same time.

I saw this posted somewhere else...

int nDivisor, nMaxLineSize = 0;
        // find max linesize
        for (int i = 0; i < 4; i++) { if (pic->linesize[i] > nMaxLineSize) { nMaxLineSize = pic->linesize[i]; } }
        if (pic->linesize[0]) { nDivisor = (nMaxLineSize / pic->linesize[0]); if (!nDivisor) { nDivisor = 1; } pic->data[0] += (pic->linesize[0] * ((nHeight/nDivisor) - 1)); }
        if (pic->linesize[1]) { nDivisor = (nMaxLineSize / pic->linesize[1]); if (!nDivisor) { nDivisor = 1; } pic->data[1] += (pic->linesize[1] * ((nHeight/nDivisor) - 1)); }
        if (pic->linesize[2]) { nDivisor = (nMaxLineSize / pic->linesize[2]); if (!nDivisor) { nDivisor = 1; } pic->data[2] += (pic->linesize[2] * ((nHeight/nDivisor) - 1)); }
        if (pic->linesize[3]) { nDivisor = (nMaxLineSize / pic->linesize[3]); if (!nDivisor) { nDivisor = 1; } pic->data[3] += (pic->linesize[3] * ((nHeight/nDivisor) - 1)); }
        pic->linesize[0] *= -1;
        pic->linesize[1] *= -1;
        pic->linesize[2] *= -1;
        pic->linesize[3] *= -1;
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

xiel88
In reply to this post by Rômulo Fernandes
hi, i encounter this problem too. i use this can solve the problem. You need to reset src and linesize of source image, in my case is use sws_scale from rgb24, 640x480 -> YUV420 176x144 the code goes:

if (option & VIDEO_FLIP) {
   src[0] += linesize[0]*(height-1);
   linesize[0] = -linesize[0];
}

sws_scale(ctx, src, linesize, 0, height, dst, dst_linesize);

Maybe some help for you.
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

Ph0t0n
void FlipFrame(AVFrame* pFrame) {
        for (int i = 0; i < 4; i++) {
                pFrame->data[i] += pFrame->linesize[i] * (pFrame->height-1);
                pFrame->linesize[i] = -pFrame->linesize[i];
        }
}

void UnflipFrame(AVFrame* pFrame) {
        for (int i = 0; i < 4; i++) {
                pFrame->linesize[i] = -pFrame->linesize[i];
                pFrame->data[i] -= pFrame->linesize[i] * (pFrame->height-1);
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Flip in sws_scale

erikjn
If the planes in the image are unequal size (e.g. YUV420) you need to adapt the height.
There may be better ways to do it, but this works for me:

void FlipFrameJ420(AVFrame* pFrame) {
   for (int i = 0; i < 4; i++) {
      if (i) {
          pFrame->data[i] += pFrame->linesize[i] * ((pFrame->height >> 1)-1);
      }
      else {
          pFrame->data[i] += pFrame->linesize[i] * (pFrame->height-1);
      }
      pFrame->linesize[i] = -pFrame->linesize[i];
   }
}