Intel-FFmpeg-Plugin / Intel_FFmpeg_plugins

mirror of git://source.ffmpeg.org/ffmpeg.git
http://ffmpeg.org
Other
35 stars 19 forks source link

Fix YUV alignment when width is not multiple of 64 pixels #16

Closed ghost closed 6 years ago

lizhong1008 commented 6 years ago

@ViGill , thanks for your patch. The branch intel_ffmpeg-3.4.1 is not stable and currently it is created for development (many patches are in the list to be merged).
BTW, could you specify how to reproduce the issue this patch to fix? It is recommended to create a github issue with detail reproduce steps.

ghost commented 6 years ago

Hi, you can try to encode a file that has 720 as width. For instance: https://ufile.io/znn0z You need to encode in HW but decode in SW, and use VPP scaling.

ghost commented 6 years ago

Hi,

any feedback on this PR ?

lizhong1008 commented 6 years ago

@ViGill , sorry I can download the clip from https://ufile.io/znn0z.
Could you please upload it to google drive? And providing your testing command should be better.

ghost commented 6 years ago

Hi,

the file was removed, please use https://ufile.io/b06ur instead (let me know if it fails again, I'll use google drive if it does). The commande line is for instance: ffmpeg -i spam.avi -an -vcodec h264_qsv -vf [main]vpp_qsv=w=512:h=288[out] out.mp4

lizhong1008 commented 6 years ago

@ViGill , still can't open the link https://ufile.io/b06ur.
But I tried another video: ./ffmpeg -i /samba/anonymous/Videos/big_buck_bunny_480p_surround-fix.avi -an -vcodec h264_qsv -vf [main]vpp_qsv=w=512:h=288[out] out.mp4. It failed just like issue #19 [Parsed_vpp_qsv_0 @ 0x398b540] No hw context provided. [Parsed_vpp_qsv_0 @ 0x398b540] Failed to configure output pad on Parsed_vpp_qsv_0 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0

Adding "-init_hw_device qsv=foo -filter_hw_device foo", it can work well. The width of this clip is not 720 but 854 (also not 64 (or 32) bytes aligned). mediainfo /samba/anonymous/Videos/big_buck_bunny_480p_surround-fix.avi General Complete name : /samba/anonymous/Videos/big_buck_bunny_480p_surround-fix.avi Format : AVI Format/Info : Audio Video Interleave File size : 210 MiB Duration : 9 min 56 s Overall bit rate : 2 958 kb/s

Video ID : 0 Format : MPEG-4 Visual Format profile : Simple@L1 Format settings, BVOP : No Format settings, QPel : No Format settings, GMC : No warppoints Format settings, Matrix : Default (H.263) Codec ID : FMP4 Duration : 9 min 56 s Bit rate : 2 500 kb/s Width : 854 pixels Height : 480 pixels Display aspect ratio : 16:9 Frame rate : 24.000 FPS Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Compression mode : Lossy Bits/(Pixel*Frame) : 0.254 Stream size : 178 MiB (85%) Writing library : Lavc51.44.0

ghost commented 6 years ago

Hi,

yes, it's because of the missing parameters. Try:

ffmpeg -init_hw_device qsv=foo -filter_hw_device foo -i spam.avi -an -vcodec h264_qsv -vf [main]vpp_qsv=w=512:h=288[out] out.mp4

with the attached file spam.avi.zip

ghost commented 6 years ago

Hi,

this fix was fine on my version but it looks like it doesn't fix the problem here. Please let me know...

Thanks

ghost commented 6 years ago

Hi,

Ok I found the issue, actually in the code I use, we align on 128 and 64 bits:

> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 0ba9c0e..296b5a4 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -168,7 +168,9 @@ static QSVFrame *submit_frame(FFQSVVPPContext *s, AVFilterLink *inlink, AVFrame
>          qsv_frame->surface = (mfxFrameSurface1*)qsv_frame->frame->data[3];
>      } else {
>          /* make a copy if the input is not padded as libmfx requires */
> -        if (picref->height & 31 || picref->linesize[0] & 31) {
> +        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(picref->format);
> +        if (picref->height & 31 || picref->linesize[0] & 31
> +            || (!strcmp(desc->name, "yuv420p") && picref->linesize[0] & 63)) {
>              qsv_frame->frame = ff_get_video_buffer(inlink,
>                                              FFALIGN(inlink->w, 128),
>                                              FFALIGN(inlink->h, 64));

I will update the PR

lizhong1008 commented 6 years ago

Modified and pushed. Please let me know if any issue.

ghost commented 6 years ago

Thanks I will!