diff mbox series

[FFmpeg-devel,RFC] ffmpeg_videotoolbox: skip memory copy if hwaccel_output_format match

Message ID tencent_67C90AEEABC5477305E85C33F13375D5C305@qq.com
State Accepted
Commit cf1746d77989c2742c8c364f57a626942cccd8d1
Headers show
Series [FFmpeg-devel,RFC] ffmpeg_videotoolbox: skip memory copy if hwaccel_output_format match
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Zhao Zhili April 27, 2021, 5:09 a.m. UTC
From: zhilizhao <zhilizhao@tencent.com>

Simple test results:

Command:
./ffmpeg -y -hwaccel videotoolbox -hwaccel_output_format videotoolbox_vld \
  -i test.mp4 -an -c:v h264_videotoolbox -benchmark out.mp4

Before:
frame= 1221 fps= 66 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.6kbits/s dup=4 drop=0 speed= 1.1x
bench: utime=2.714s stime=1.218s rtime=18.574s

After:
frame= 1221 fps=137 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.4kbits/s dup=4 drop=0 speed=2.28x
bench: utime=1.450s stime=1.440s rtime=8.924s

It has limited usecase since there is no video filter support, so
a log message is added to notify the user.
---
It has a good performance with limited usecases like transcoding without
autoscale/autorotate, and I don't know if it break some special usecase,
since the RFC.

 fftools/ffmpeg_videotoolbox.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Steven Liu April 27, 2021, 12:18 p.m. UTC | #1
> 2021年4月27日 下午1:09,Zhao Zhili <quinkblack@foxmail.com> 写道:
> 
> From: zhilizhao <zhilizhao@tencent.com>
> 
> Simple test results:
> 
> Command:
> ./ffmpeg -y -hwaccel videotoolbox -hwaccel_output_format videotoolbox_vld \
>  -i test.mp4 -an -c:v h264_videotoolbox -benchmark out.mp4
> 
> Before:
> frame= 1221 fps= 66 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.6kbits/s dup=4 drop=0 speed= 1.1x
> bench: utime=2.714s stime=1.218s rtime=18.574s
> 
> After:
> frame= 1221 fps=137 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.4kbits/s dup=4 drop=0 speed=2.28x
> bench: utime=1.450s stime=1.440s rtime=8.924s
> 
> It has limited usecase since there is no video filter support, so
> a log message is added to notify the user.
> ---
> It has a good performance with limited usecases like transcoding without
> autoscale/autorotate, and I don't know if it break some special usecase,
> since the RFC.
> 
> fftools/ffmpeg_videotoolbox.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
> 
> diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
> index a6b78d0f7d..4ba8618539 100644
> --- a/fftools/ffmpeg_videotoolbox.c
> +++ b/fftools/ffmpeg_videotoolbox.c
> @@ -29,6 +29,7 @@
> 
> typedef struct VTContext {
>     AVFrame *tmp_frame;
> +    int log_once;
> } VTContext;
> 
> char *videotoolbox_pixfmt;
> @@ -44,6 +45,13 @@ static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame)
>     int linesize[4] = { 0 };
>     int planes, ret, i;
> 
> +    if (frame->format == ist->hwaccel_output_format) {
> +        av_log_once(s, AV_LOG_INFO, AV_LOG_TRACE, &vt->log_once,
> +            "There is no video filter for videotoolbox pix_fmt now, remove the "
> +            "-hwaccel_output_format option if video filter doesn't work\n");
> +        return 0;
> +    }
> +
>     av_frame_unref(vt->tmp_frame);
> 
>     switch (pixel_format) {
> -- 
> 2.31.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 

lgtm & test ok

Thanks

Steven Liu
Zhao Zhili June 10, 2021, 4:15 a.m. UTC | #2
Ping.

> On Apr 27, 2021, at 1:09 PM, Zhao Zhili <quinkblack@foxmail.com> wrote:
> 
> From: zhilizhao <zhilizhao@tencent.com>
> 
> Simple test results:
> 
> Command:
> ./ffmpeg -y -hwaccel videotoolbox -hwaccel_output_format videotoolbox_vld \
>  -i test.mp4 -an -c:v h264_videotoolbox -benchmark out.mp4
> 
> Before:
> frame= 1221 fps= 66 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.6kbits/s dup=4 drop=0 speed= 1.1x
> bench: utime=2.714s stime=1.218s rtime=18.574s
> 
> After:
> frame= 1221 fps=137 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.4kbits/s dup=4 drop=0 speed=2.28x
> bench: utime=1.450s stime=1.440s rtime=8.924s
> 
> It has limited usecase since there is no video filter support, so
> a log message is added to notify the user.
> ---
> It has a good performance with limited usecases like transcoding without
> autoscale/autorotate, and I don't know if it break some special usecase,
> since the RFC.
> 
> fftools/ffmpeg_videotoolbox.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
> 
> diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
> index a6b78d0f7d..4ba8618539 100644
> --- a/fftools/ffmpeg_videotoolbox.c
> +++ b/fftools/ffmpeg_videotoolbox.c
> @@ -29,6 +29,7 @@
> 
> typedef struct VTContext {
>     AVFrame *tmp_frame;
> +    int log_once;
> } VTContext;
> 
> char *videotoolbox_pixfmt;
> @@ -44,6 +45,13 @@ static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame)
>     int linesize[4] = { 0 };
>     int planes, ret, i;
> 
> +    if (frame->format == ist->hwaccel_output_format) {
> +        av_log_once(s, AV_LOG_INFO, AV_LOG_TRACE, &vt->log_once,
> +            "There is no video filter for videotoolbox pix_fmt now, remove the "
> +            "-hwaccel_output_format option if video filter doesn't work\n");
> +        return 0;
> +    }
> +
>     av_frame_unref(vt->tmp_frame);
> 
>     switch (pixel_format) {
> -- 
> 2.31.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Steven Liu June 10, 2021, 11:54 a.m. UTC | #3
"zhilizhao(赵志立)" <quinkblack@foxmail.com> 于2021年6月10日周四 下午12:15写道:
>
> Ping.
>
> > On Apr 27, 2021, at 1:09 PM, Zhao Zhili <quinkblack@foxmail.com> wrote:
> >
> > From: zhilizhao <zhilizhao@tencent.com>
> >
> > Simple test results:
> >
> > Command:
> > ./ffmpeg -y -hwaccel videotoolbox -hwaccel_output_format videotoolbox_vld \
> >  -i test.mp4 -an -c:v h264_videotoolbox -benchmark out.mp4
> >
> > Before:
> > frame= 1221 fps= 66 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.6kbits/s dup=4 drop=0 speed= 1.1x
> > bench: utime=2.714s stime=1.218s rtime=18.574s
> >
> > After:
> > frame= 1221 fps=137 q=-0.0 Lsize=    3144kB time=00:00:20.33 bitrate=1266.4kbits/s dup=4 drop=0 speed=2.28x
> > bench: utime=1.450s stime=1.440s rtime=8.924s
> >
> > It has limited usecase since there is no video filter support, so
> > a log message is added to notify the user.
> > ---
> > It has a good performance with limited usecases like transcoding without
> > autoscale/autorotate, and I don't know if it break some special usecase,
> > since the RFC.
> >
> > fftools/ffmpeg_videotoolbox.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
> > index a6b78d0f7d..4ba8618539 100644
> > --- a/fftools/ffmpeg_videotoolbox.c
> > +++ b/fftools/ffmpeg_videotoolbox.c
> > @@ -29,6 +29,7 @@
> >
> > typedef struct VTContext {
> >     AVFrame *tmp_frame;
> > +    int log_once;
> > } VTContext;
> >
> > char *videotoolbox_pixfmt;
> > @@ -44,6 +45,13 @@ static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame)
> >     int linesize[4] = { 0 };
> >     int planes, ret, i;
> >
> > +    if (frame->format == ist->hwaccel_output_format) {
> > +        av_log_once(s, AV_LOG_INFO, AV_LOG_TRACE, &vt->log_once,
> > +            "There is no video filter for videotoolbox pix_fmt now, remove the "
> > +            "-hwaccel_output_format option if video filter doesn't work\n");
> > +        return 0;
> > +    }
> > +
> >     av_frame_unref(vt->tmp_frame);
> >
> >     switch (pixel_format) {
> > --
> > 2.31.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> >
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

pushed

Thanks
Steven
diff mbox series

Patch

diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
index a6b78d0f7d..4ba8618539 100644
--- a/fftools/ffmpeg_videotoolbox.c
+++ b/fftools/ffmpeg_videotoolbox.c
@@ -29,6 +29,7 @@ 
 
 typedef struct VTContext {
     AVFrame *tmp_frame;
+    int log_once;
 } VTContext;
 
 char *videotoolbox_pixfmt;
@@ -44,6 +45,13 @@  static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame)
     int linesize[4] = { 0 };
     int planes, ret, i;
 
+    if (frame->format == ist->hwaccel_output_format) {
+        av_log_once(s, AV_LOG_INFO, AV_LOG_TRACE, &vt->log_once,
+            "There is no video filter for videotoolbox pix_fmt now, remove the "
+            "-hwaccel_output_format option if video filter doesn't work\n");
+        return 0;
+    }
+
     av_frame_unref(vt->tmp_frame);
 
     switch (pixel_format) {