[PATCH] Fix linesize computation for NV formats
Hi, for NV12 and NV21 data[1] contains both the U and V components, so it needs to be multiplied by 2. Alternatively we could have: linesize[1] = width which is equivalent. I couldn't find any NV12 samples and libswscale cannot issue that in output, so I didn't tested it. Regards. -- FFmpeg = Faithless and Faithful Mystic Puristic Exploitable Game
On date Sunday 2009-11-15 17:13:22 +0100, Stefano Sabatini encoded:
Hi,
for NV12 and NV21 data[1] contains both the U and V components, so its size needs to be multiplied by 2. Alternatively we could have: linesize[1] = width
which is equivalent.
I couldn't find any NV12 samples and libswscale cannot issue that in output, so I didn't tested it.
That change also requires a corresponding change in ff_fill_pointer(), so patch updated. I wonder if there is some reason if it has been done like that, it is done that way since the initial inclusion of NV formats support in r6115. Regards. -- FFmpeg = Faithless and Fierce Majestic Pitiless Extroverse Guru
On Sun, Nov 15, 2009 at 11:23:27PM +0100, Stefano Sabatini wrote:
On date Sunday 2009-11-15 17:13:22 +0100, Stefano Sabatini encoded:
Hi,
for NV12 and NV21 data[1] contains both the U and V components, so its size needs to be multiplied by 2. Alternatively we could have: linesize[1] = width
which is equivalent.
I couldn't find any NV12 samples and libswscale cannot issue that in output, so I didn't tested it.
That change also requires a corresponding change in ff_fill_pointer(), so patch updated.
I wonder if there is some reason if it has been done like that, it is done that way since the initial inclusion of NV formats support in r6115.
ill defer review of this until you claim that you confirmed a bug in a test and that this patch fixes it. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In fact, the RIAA has been known to suggest that students drop out of college or go to community college in order to be able to afford settlements. -- The RIAA
On date Monday 2009-11-16 00:57:25 +0100, Michael Niedermayer encoded:
On Sun, Nov 15, 2009 at 11:23:27PM +0100, Stefano Sabatini wrote:
On date Sunday 2009-11-15 17:13:22 +0100, Stefano Sabatini encoded:
Hi,
for NV12 and NV21 data[1] contains both the U and V components, so its size needs to be multiplied by 2. Alternatively we could have: linesize[1] = width
which is equivalent.
I couldn't find any NV12 samples and libswscale cannot issue that in output, so I didn't tested it.
That change also requires a corresponding change in ff_fill_pointer(), so patch updated.
I wonder if there is some reason if it has been done like that, it is done that way since the initial inclusion of NV formats support in r6115.
ill defer review of this until you claim that you confirmed a bug in a test and that this patch fixes it.
I don't think this is strictly a bug, but this makes more harder to deal with NV12 formats, as linesize[1] has a special value (half the size of the data[1] plane linesize) which has to be considered when dealing with the format, for example when filling the pointers in ff_fill_pointer(). But I agree that we should at least test the change, has anyone an NV12 sample or can suggest how/where to get it? Regards. -- FFmpeg = Fantastic & Foolish Meaningless Prodigious Epic Governor
On date Monday 2009-11-16 01:09:15 +0100, Stefano Sabatini encoded:
On date Monday 2009-11-16 00:57:25 +0100, Michael Niedermayer encoded:
On Sun, Nov 15, 2009 at 11:23:27PM +0100, Stefano Sabatini wrote:
On date Sunday 2009-11-15 17:13:22 +0100, Stefano Sabatini encoded:
Hi,
for NV12 and NV21 data[1] contains both the U and V components, so its size needs to be multiplied by 2. Alternatively we could have: linesize[1] = width
which is equivalent.
I couldn't find any NV12 samples and libswscale cannot issue that in output, so I didn't tested it.
That change also requires a corresponding change in ff_fill_pointer(), so patch updated.
I wonder if there is some reason if it has been done like that, it is done that way since the initial inclusion of NV formats support in r6115.
ill defer review of this until you claim that you confirmed a bug in a test and that this patch fixes it.
I don't think this is strictly a bug, but this makes more harder to deal with NV12 formats, as linesize[1] has a special value (half the size of the data[1] plane linesize) which has to be considered when dealing with the format, for example when filling the pointers in ff_fill_pointer().
But I agree that we should at least test the change, has anyone an NV12 sample or can suggest how/where to get it?
I can issue NV12 as output using ffmpeg, but then there is no way to read it since nv12 is not supported as input. So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX). Bonus patch attached. Regards. -- FFmpeg = Free Fiendish Magical Picky Elegant Gargoyle
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
Bonus patch attached.
Regards. -- FFmpeg = Free Fiendish Magical Picky Elegant Gargoyle
imgconvert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) c043cedb31125df864edc7399720870c9061e3bf fix-nv-name.patch Index: ffmpeg/libavcodec/imgconvert.c =================================================================== --- ffmpeg.orig/libavcodec/imgconvert.c 2009-11-19 01:31:28.000000000 +0100 +++ ffmpeg/libavcodec/imgconvert.c 2009-11-19 01:32:26.000000000 +0100 @@ -486,7 +486,7 @@ .x_chroma_shift = 1, .y_chroma_shift = 1, }, [PIX_FMT_NV21] = { - .name = "nv12", + .name = "nv21",
someone needs half a liter cola, patch ok [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB it is not once nor twice but times without number that the same ideas make their appearance in the world. -- Aristotle
On date Thursday 2009-11-19 17:44:59 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
Bonus patch attached.
Regards. -- FFmpeg = Free Fiendish Magical Picky Elegant Gargoyle
imgconvert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) c043cedb31125df864edc7399720870c9061e3bf fix-nv-name.patch Index: ffmpeg/libavcodec/imgconvert.c =================================================================== --- ffmpeg.orig/libavcodec/imgconvert.c 2009-11-19 01:31:28.000000000 +0100 +++ ffmpeg/libavcodec/imgconvert.c 2009-11-19 01:32:26.000000000 +0100 @@ -486,7 +486,7 @@ .x_chroma_shift = 1, .y_chroma_shift = 1, }, [PIX_FMT_NV21] = { - .name = "nv12", + .name = "nv21",
someone needs half a liter cola, patch ok
Applied. -- FFmpeg = Fiendish & Foolish MultiPurpose Enhancing Gorilla
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote:
On date Monday 2009-11-16 01:09:15 +0100, Stefano Sabatini encoded:
On date Monday 2009-11-16 00:57:25 +0100, Michael Niedermayer encoded:
On Sun, Nov 15, 2009 at 11:23:27PM +0100, Stefano Sabatini wrote:
On date Sunday 2009-11-15 17:13:22 +0100, Stefano Sabatini encoded:
Hi,
for NV12 and NV21 data[1] contains both the U and V components, so its size needs to be multiplied by 2. Alternatively we could have: linesize[1] = width
which is equivalent.
I couldn't find any NV12 samples and libswscale cannot issue that in output, so I didn't tested it.
That change also requires a corresponding change in ff_fill_pointer(), so patch updated.
I wonder if there is some reason if it has been done like that, it is done that way since the initial inclusion of NV formats support in r6115.
ill defer review of this until you claim that you confirmed a bug in a test and that this patch fixes it.
I don't think this is strictly a bug, but this makes more harder to deal with NV12 formats, as linesize[1] has a special value (half the size of the data[1] plane linesize) which has to be considered when dealing with the format, for example when filling the pointers in ff_fill_pointer().
But I agree that we should at least test the change, has anyone an NV12 sample or can suggest how/where to get it?
I can issue NV12 as output using ffmpeg, but then there is no way to read it since nv12 is not supported as input.
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it. either way your patch is wrong, unless by sheer luck the current code is buggy and your patch fixes that bug. Theres no way both values for linesize could be accepted by code using it. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc. Also I wonder how hard would be to add it as an input format in lsws.
either way your patch is wrong, unless by sheer luck the current code is buggy and your patch fixes that bug.
Theres no way both values for linesize could be accepted by code using it.
Please could you clarify the last sentence? I explained why I consider the patch correct, that's also the reason for which all the filters which claims to work with NVXX are indeed broken by that, I cannot test but then we have no means to test the original code either (at least not with ffmpeg tools). Regards. -- FFmpeg = Furious and Faboulous Miracolous Powered Elitist Gospel
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame. I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =) Ramiro Polla
On Fri, Nov 20, 2009 at 9:56 AM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
And here is a patch to take nv12 and nv21 as input for swscale (depends on the previous patch). Ramiro Polla
On date Friday 2009-11-20 14:16:44 -0200, Ramiro Polla encoded:
On Fri, Nov 20, 2009 at 9:56 AM, Ramiro Polla <ramiro.polla at gmail.com> wrote: [...]
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
And here is a patch to take nv12 and nv21 as input for swscale (depends on the previous patch).
Great! :) -- FFmpeg = Forgiving Free Murdering Patchable Egregious God
On Fri, Nov 20, 2009 at 02:16:44PM -0200, Ramiro Polla wrote:
On Fri, Nov 20, 2009 at 9:56 AM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
And here is a patch to take nv12 and nv21 as input for swscale (depends on the previous patch).
Ramiro Polla
swscale.c | 2 ++ swscale_template.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) 7e95c118694ad7ee4d89e948fea7e3252238d5d9 nv12in.diff Index: libswscale/swscale.c =================================================================== --- libswscale/swscale.c (revis?o 29937) +++ libswscale/swscale.c (c?pia de trabalho) @@ -134,6 +134,8 @@ || (x)==PIX_FMT_GRAY8 \ || (x)==PIX_FMT_YUV410P \ || (x)==PIX_FMT_YUV440P \ + || (x)==PIX_FMT_NV12 \ + || (x)==PIX_FMT_NV21 \ || (x)==PIX_FMT_GRAY16BE \ || (x)==PIX_FMT_GRAY16LE \ || (x)==PIX_FMT_YUV444P \ Index: libswscale/swscale_template.c =================================================================== --- libswscale/swscale_template.c (revis?o 29937) +++ libswscale/swscale_template.c (c?pia de trabalho) @@ -1784,6 +1784,27 @@ #endif }
+#define NVxxToUV(U, V) \ + int i; \ + for (i = 0; i < width; i++) { \ + dstU[i]= src1[2*i+U]; \ + dstV[i]= src1[2*i+V]; \ + } \ + +static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, + long width, uint32_t *unused) +{ + NVxxToUV(0, 1); +} + +static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, + long width, uint32_t *unused) +{ + NVxxToUV(1, 0); +}
you need just 1 function, just exchange the 2 dst pointers [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I hate to see young programmers poisoned by the kind of thinking Ulrich Drepper puts forward since it is simply too narrow -- Roman Shaposhnik
On Tue, Nov 24, 2009 at 12:27 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Fri, Nov 20, 2009 at 02:16:44PM -0200, Ramiro Polla wrote:
On Fri, Nov 20, 2009 at 9:56 AM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...] > So basically all the code affected by the change is indeed code which > is never used, my patch simply makes the linesize params semantics for > NV formats consistent with that of all the other formats (thus > simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
And here is a patch to take nv12 and nv21 as input for swscale (depends on the previous patch).
Ramiro Polla
?swscale.c ? ? ? ? ?| ? ?2 ++ ?swscale_template.c | ? 23 +++++++++++++++++++++++ ?2 files changed, 25 insertions(+) 7e95c118694ad7ee4d89e948fea7e3252238d5d9 ?nv12in.diff Index: libswscale/swscale.c =================================================================== --- libswscale/swscale.c ? ? ?(revis?o 29937) +++ libswscale/swscale.c ? ? ?(c?pia de trabalho) @@ -134,6 +134,8 @@ ? ? ? ? ?|| (x)==PIX_FMT_GRAY8 ? ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV410P ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV440P ? ? \ + ? ? ? ?|| (x)==PIX_FMT_NV12 ? ? ? ?\ + ? ? ? ?|| (x)==PIX_FMT_NV21 ? ? ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16BE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16LE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_YUV444P ? ? \ Index: libswscale/swscale_template.c =================================================================== --- libswscale/swscale_template.c ? ? (revis?o 29937) +++ libswscale/swscale_template.c ? ? (c?pia de trabalho) @@ -1784,6 +1784,27 @@ ?#endif ?}
+#define NVxxToUV(U, V) ? ? ? ? ? ? ?\ + ? ?int i; ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ?for (i = 0; i < width; i++) { ? \ + ? ? ? ?dstU[i]= src1[2*i+U]; ? ? ? \ + ? ? ? ?dstV[i]= src1[2*i+V]; ? ? ? \ + ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \ + +static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?NVxxToUV(0, 1); +} + +static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?NVxxToUV(1, 0); +}
you need just 1 function, just exchange the 2 dst pointers
Like in attached?
On Wed, Nov 25, 2009 at 03:24:03PM -0200, Ramiro Polla wrote:
On Tue, Nov 24, 2009 at 12:27 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Fri, Nov 20, 2009 at 02:16:44PM -0200, Ramiro Polla wrote:
On Fri, Nov 20, 2009 at 9:56 AM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded: > On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...] > > So basically all the code affected by the change is indeed code which > > is never used, my patch simply makes the linesize params semantics for > > NV formats consistent with that of all the other formats (thus > > simplifying the code if we choose to use pixdesc for ff_fill_XXX). > > if no code uses NV12 it should be removed (i dont belive this though) > if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
And here is a patch to take nv12 and nv21 as input for swscale (depends on the previous patch).
Ramiro Polla
?swscale.c ? ? ? ? ?| ? ?2 ++ ?swscale_template.c | ? 23 +++++++++++++++++++++++ ?2 files changed, 25 insertions(+) 7e95c118694ad7ee4d89e948fea7e3252238d5d9 ?nv12in.diff Index: libswscale/swscale.c =================================================================== --- libswscale/swscale.c ? ? ?(revis?o 29937) +++ libswscale/swscale.c ? ? ?(c?pia de trabalho) @@ -134,6 +134,8 @@ ? ? ? ? ?|| (x)==PIX_FMT_GRAY8 ? ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV410P ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV440P ? ? \ + ? ? ? ?|| (x)==PIX_FMT_NV12 ? ? ? ?\ + ? ? ? ?|| (x)==PIX_FMT_NV21 ? ? ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16BE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16LE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_YUV444P ? ? \ Index: libswscale/swscale_template.c =================================================================== --- libswscale/swscale_template.c ? ? (revis?o 29937) +++ libswscale/swscale_template.c ? ? (c?pia de trabalho) @@ -1784,6 +1784,27 @@ ?#endif ?}
+#define NVxxToUV(U, V) ? ? ? ? ? ? ?\ + ? ?int i; ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ?for (i = 0; i < width; i++) { ? \ + ? ? ? ?dstU[i]= src1[2*i+U]; ? ? ? \ + ? ? ? ?dstV[i]= src1[2*i+V]; ? ? ? \ + ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \ + +static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?NVxxToUV(0, 1); +} + +static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?NVxxToUV(1, 0); +}
you need just 1 function, just exchange the 2 dst pointers
Like in attached?
swscale.c | 2 ++ swscale_template.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) 219c60ab14c8879cf0b3578079ced1b82df9e01f nv12in2.diff Index: libswscale/swscale.c =================================================================== --- libswscale/swscale.c (revision 29964) +++ libswscale/swscale.c (working copy) @@ -134,6 +134,8 @@ || (x)==PIX_FMT_GRAY8 \ || (x)==PIX_FMT_YUV410P \ || (x)==PIX_FMT_YUV440P \ + || (x)==PIX_FMT_NV12 \ + || (x)==PIX_FMT_NV21 \ || (x)==PIX_FMT_GRAY16BE \ || (x)==PIX_FMT_GRAY16LE \ || (x)==PIX_FMT_YUV444P \ Index: libswscale/swscale_template.c =================================================================== --- libswscale/swscale_template.c (revision 29964) +++ libswscale/swscale_template.c (working copy) @@ -1784,6 +1784,30 @@ #endif }
+static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2, + const uint8_t *src, long width) +{ + int i; + for (i = 0; i < width; i++) { + dst1[i]= src[2*i+0]; + dst2[i]= src[2*i+1]; + } +} + +static inline void nv12ToUV(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, + long width, uint32_t *unused) +{ + RENAME(nvXXtoUV)(dstU, dstV, src1, width); +} + +static inline void nv21ToUV(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, + long width, uint32_t *unused) +{ + RENAME(nvXXtoUV)(dstV, dstU, src1, width); +}
is the use of existing functions like yuy2ToY() slower? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Thouse who are best at talking, realize last or never when they are wrong.
On Wed, Nov 25, 2009 at 4:16 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Wed, Nov 25, 2009 at 03:24:03PM -0200, Ramiro Polla wrote:
On Tue, Nov 24, 2009 at 12:27 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Fri, Nov 20, 2009 at 02:16:44PM -0200, Ramiro Polla wrote:
On Fri, Nov 20, 2009 at 9:56 AM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote: > On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded: >> On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: > [...] >> > So basically all the code affected by the change is indeed code which >> > is never used, my patch simply makes the linesize params semantics for >> > NV formats consistent with that of all the other formats (thus >> > simplifying the code if we choose to use pixdesc for ff_fill_XXX). >> >> if no code uses NV12 it should be removed (i dont belive this though) >> if any code uses NV12 your patch will break it. > > ffmpeg doesn't support NV12 as input, but can convert to NV12 / > NV21. So we can create a stream with pix_fmt nv12 but there is no mean > to visually test it (e.g. with ffplay) or convert it back to a stream > which is playable by ffmpeg, but maybe someone can suggest some way to > display such a format e.g. with mplayer or vlc. > > Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
And here is a patch to take nv12 and nv21 as input for swscale (depends on the previous patch).
Ramiro Polla
?swscale.c ? ? ? ? ?| ? ?2 ++ ?swscale_template.c | ? 23 +++++++++++++++++++++++ ?2 files changed, 25 insertions(+) 7e95c118694ad7ee4d89e948fea7e3252238d5d9 ?nv12in.diff Index: libswscale/swscale.c =================================================================== --- libswscale/swscale.c ? ? ?(revis?o 29937) +++ libswscale/swscale.c ? ? ?(c?pia de trabalho) @@ -134,6 +134,8 @@ ? ? ? ? ?|| (x)==PIX_FMT_GRAY8 ? ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV410P ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV440P ? ? \ + ? ? ? ?|| (x)==PIX_FMT_NV12 ? ? ? ?\ + ? ? ? ?|| (x)==PIX_FMT_NV21 ? ? ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16BE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16LE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_YUV444P ? ? \ Index: libswscale/swscale_template.c =================================================================== --- libswscale/swscale_template.c ? ? (revis?o 29937) +++ libswscale/swscale_template.c ? ? (c?pia de trabalho) @@ -1784,6 +1784,27 @@ ?#endif ?}
+#define NVxxToUV(U, V) ? ? ? ? ? ? ?\ + ? ?int i; ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ?for (i = 0; i < width; i++) { ? \ + ? ? ? ?dstU[i]= src1[2*i+U]; ? ? ? \ + ? ? ? ?dstV[i]= src1[2*i+V]; ? ? ? \ + ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \ + +static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?NVxxToUV(0, 1); +} + +static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?NVxxToUV(1, 0); +}
you need just 1 function, just exchange the 2 dst pointers
Like in attached?
?swscale.c ? ? ? ? ?| ? ?2 ++ ?swscale_template.c | ? 26 ++++++++++++++++++++++++++ ?2 files changed, 28 insertions(+) 219c60ab14c8879cf0b3578079ced1b82df9e01f ?nv12in2.diff Index: libswscale/swscale.c =================================================================== --- libswscale/swscale.c ? ? ?(revision 29964) +++ libswscale/swscale.c ? ? ?(working copy) @@ -134,6 +134,8 @@ ? ? ? ? ?|| (x)==PIX_FMT_GRAY8 ? ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV410P ? ? \ ? ? ? ? ?|| (x)==PIX_FMT_YUV440P ? ? \ + ? ? ? ?|| (x)==PIX_FMT_NV12 ? ? ? ?\ + ? ? ? ?|| (x)==PIX_FMT_NV21 ? ? ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16BE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_GRAY16LE ? ?\ ? ? ? ? ?|| (x)==PIX_FMT_YUV444P ? ? \ Index: libswscale/swscale_template.c =================================================================== --- libswscale/swscale_template.c ? ? (revision 29964) +++ libswscale/swscale_template.c ? ? (working copy) @@ -1784,6 +1784,30 @@ ?#endif ?}
+static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src, long width) +{ + ? ?int i; + ? ?for (i = 0; i < width; i++) { + ? ? ? ?dst1[i]= src[2*i+0]; + ? ? ? ?dst2[i]= src[2*i+1]; + ? ?} +} + +static inline void nv12ToUV(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?RENAME(nvXXtoUV)(dstU, dstV, src1, width); +} + +static inline void nv21ToUV(uint8_t *dstU, uint8_t *dstV, + ? ? ? ? ? ? ? ? ? ? ? ? ? ?const uint8_t *src1, const uint8_t *src2, + ? ? ? ? ? ? ? ? ? ? ? ? ? ?long width, uint32_t *unused) +{ + ? ?RENAME(nvXXtoUV)(dstV, dstU, src1, width); +}
is the use of existing functions like yuy2ToY() slower?
Getting the smallest dezicycle count from a whole bunch of runs: nvXXtoUV: C 21802 MMX 7744 yuy2ToY and uyvyToY to not cause unaligned loads in MMX: C 27653 MMX 8464 BEToUV (half the loads are always unaligned in MMX): C 21952 MMX 10060 New patch attached with MMX nvXXtoUV as well. Ramiro Polla
On Thu, Dec 03, 2009 at 01:13:57AM -0200, Ramiro Polla wrote: [...]
Getting the smallest dezicycle count from a whole bunch of runs:
nvXXtoUV: C 21802 MMX 7744
yuy2ToY and uyvyToY to not cause unaligned loads in MMX: C 27653 MMX 8464
BEToUV (half the loads are always unaligned in MMX): C 21952 MMX 10060
New patch attached with MMX nvXXtoUV as well.
Ramiro Polla
swscale.c | 2 ++ swscale_template.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) 34e6cfe079a809fa8624da73c3961d3814635328 nv12inMMX.diff
ok [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Democracy is the form of government in which you can choose your dictator
On Thu, Dec 3, 2009 at 3:45 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Thu, Dec 03, 2009 at 01:13:57AM -0200, Ramiro Polla wrote: [...]
Getting the smallest dezicycle count from a whole bunch of runs:
nvXXtoUV: C ? 21802 MMX ?7744
yuy2ToY and uyvyToY to not cause unaligned loads in MMX: C ? 27653 MMX 8464
BEToUV (half the loads are always unaligned in MMX): C ? 21952 MMX 10060
New patch attached with MMX nvXXtoUV as well.
Ramiro Polla
?swscale.c ? ? ? ? ?| ? ?2 ++ ?swscale_template.c | ? 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ ?2 files changed, 52 insertions(+) 34e6cfe079a809fa8624da73c3961d3814635328 ?nv12inMMX.diff
ok
Applied.
On Fri, Nov 20, 2009 at 09:56:32AM -0200, Ramiro Polla wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
Ramiro Polla
imgconvert.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 23a08f3e04d937fa4f0cd84645b99ad418a237e2 nv12.diff
ok [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Observe your enemies, for they first find out your faults. -- Antisthenes
On Tue, Nov 24, 2009 at 12:25 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Fri, Nov 20, 2009 at 09:56:32AM -0200, Ramiro Polla wrote:
On Thu, Nov 19, 2009 at 10:54 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
On Thu, Nov 19, 2009 at 10:38 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Thursday 2009-11-19 17:51:30 +0100, Michael Niedermayer encoded:
On Thu, Nov 19, 2009 at 01:37:03AM +0100, Stefano Sabatini wrote: [...]
So basically all the code affected by the change is indeed code which is never used, my patch simply makes the linesize params semantics for NV formats consistent with that of all the other formats (thus simplifying the code if we choose to use pixdesc for ff_fill_XXX).
if no code uses NV12 it should be removed (i dont belive this though) if any code uses NV12 your patch will break it.
ffmpeg doesn't support NV12 as input, but can convert to NV12 / NV21. So we can create a stream with pix_fmt nv12 but there is no mean to visually test it (e.g. with ffplay) or convert it back to a stream which is playable by ffmpeg, but maybe someone can suggest some way to display such a format e.g. with mplayer or vlc.
Also I wonder how hard would be to add it as an input format in lsws.
I have a device with a hardware decoder to nv12 that also displays in nv12 at work. I might take a look tomorrow if I manage to find some time...
One more change was needed to get raw nv12 output properly. With attached patch I can ./ffmpeg_g -i input.avi -s 1280x720 -pix_fmt nv12 -f rawvideo -y output.nv12 and then feed output.nv12 to the display frame by frame.
I haven't worked on nv12 support as input to swscale yet. I'll do it either this afternoon or in two weeks =)
Ramiro Polla
?imgconvert.c | ? ?8 +++++--- ?1 file changed, 5 insertions(+), 3 deletions(-) 23a08f3e04d937fa4f0cd84645b99ad418a237e2 ?nv12.diff
ok
Applied.
participants (3)
-
michaelni@gmx.at -
ramiro.polla@gmail.com -
stefano.sabatini-lala@poste.it