diff mbox series

[FFmpeg-devel,v1] avcodec/v4l2_m2m_enc: Set bitrate mode to cbr by default

Message ID 20200429081426.19637-1-ming.qian@nxp.com
State New
Headers show
Series [FFmpeg-devel,v1] avcodec/v4l2_m2m_enc: Set bitrate mode to cbr by default | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Ming Qian April 29, 2020, 8:14 a.m. UTC
Without this setting, bitrate may have no effect
    if the default value of bitrate mode is VBR.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
---
 libavcodec/v4l2_m2m_enc.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andriy Gelman April 30, 2020, 4:31 a.m. UTC | #1
On Wed, 29. Apr 16:14, Ming Qian wrote:
>     Without this setting, bitrate may have no effect
>     if the default value of bitrate mode is VBR.
> 
> Signed-off-by: Ming Qian <ming.qian@nxp.com>
> ---
>  libavcodec/v4l2_m2m_enc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> index 8454e2326c..6296ad88c6 100644
> --- a/libavcodec/v4l2_m2m_enc.c
> +++ b/libavcodec/v4l2_m2m_enc.c
> @@ -191,6 +191,7 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
>  
>      /* set ext ctrls */
>      v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE), MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode", 0);
> +    v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE_MODE), MPEG_VIDEO(BITRATE_MODE_CBR), "bit rate mode", 1);
>      v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate", 1);
>      v4l2_set_ext_ctrl(s, MPEG_CID(FRAME_RC_ENABLE), 1, "frame level rate control", 0);
>      v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop size", 1);
> -- 
> 2.26.0
> 

On the RPI4 it causes streamon to fail:

./ffmpeg -y -i 7799x264.mp4 -an -codec:v h264_v4l2m2m out.264
[h264_v4l2m2m @ 0x3d6e3b0] VIDIOC_STREAMON failed on output context
Video encoding failed                                                                       
Conversion failed!

[41648.654237] bcm2835-codec bcm2835-codec: bcm2835_codec_start_streaming: Failed enabling i/p port, ret -3                                                                             
[41648.654243] ------------[ cut here ]------------
[41648.654267] WARNING: CPU: 2 PID: 26254 at drivers/media/common/videobuf2/videobuf2-core.c:1365 vb2_start_streaming+0xe4/0x160 [videobuf2_common]                                     
[41648.654271] Modules linked in: bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q garp stp llc vc4 v3d gpu_sched drm_kms_helper brcmfmac brcmutil drm snd_soc_core sha256_generic snd_compress snd_pcm_dmaengine drm_panel_orientation_quirks syscopyarea sysfillrect sysimgblt fb_sys_fops raspberrypi_hwmon cfg80211 hwmon snd_bcm2835(C) snd_pcm rfkill snd_timer bcm2835_v4l2(C) snd bcm2835_codec(C) v4l2_mem2mem v4l2_common bcm2835_mmal_vchiq(C) videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media vc_sm_cma(C) rpivid_mem uio_pdrv_genirq uio ip_tables x_tables ipv6
[41648.654351] CPU: 2 PID: 26254 Comm: ffmpeg Tainted: G        WC        4.19.97-v7l+ #1294
[41648.654355] Hardware name: BCM2835
[41648.654374] [<c0212e04>] (unwind_backtrace) from [<c020d5e0>] (show_stack+0x20/0x24)
[41648.654383] [<c020d5e0>] (show_stack) from [<c09b15c8>] (dump_stack+0xe0/0x124)
[41648.654392] [<c09b15c8>] (dump_stack) from [<c0222544>] (__warn+0x104/0x11c)
[41648.654400] [<c0222544>] (__warn) from [<c0222694>] (warn_slowpath_null+0x50/0x58)
[41648.654414] [<c0222694>] (warn_slowpath_null) from [<bf2126f8>] (vb2_start_streaming+0xe4/0x160 [videobuf2_common])                                                                  
[41648.654434] [<bf2126f8>] (vb2_start_streaming [videobuf2_common]) from [<bf214130>] (vb2_core_streamon+0x130/0x16c [videobuf2_common])                                               
[41648.654451] [<bf214130>] (vb2_core_streamon [videobuf2_common]) from [<bf2368a8>] (vb2_streamon+0x40/0x60 [videobuf2_v4l2])                                                          
[41648.654467] [<bf2368a8>] (vb2_streamon [videobuf2_v4l2]) from [<bf27eaa0>] (v4l2_m2m_streamon+0x30/0x48 [v4l2_mem2mem])                                                              
[41648.654480] [<bf27eaa0>] (v4l2_m2m_streamon [v4l2_mem2mem]) from [<bf27ead8>] (v4l2_m2m_ioctl_streamon+0x20/0x24 [v4l2_mem2mem])                                                     
[41648.654518] [<bf27ead8>] (v4l2_m2m_ioctl_streamon [v4l2_mem2mem]) from [<bf188e3c>] (v4l_streamon+0x28/0x2c [videodev])                                                              
[41648.654571] [<bf188e3c>] (v4l_streamon [videodev]) from [<bf18ba38>] (__video_do_ioctl+0x268/0x528 [videodev])                                                                       
[41648.654621] [<bf18ba38>] (__video_do_ioctl [videodev]) from [<bf18f470>] (video_usercopy+0x218/0x600 [videodev])                                                                     
[41648.654670] [<bf18f470>] (video_usercopy [videodev]) from [<bf18f878>] (video_ioctl2+0x20/0x24 [videodev])                                                                           
[41648.654720] [<bf18f878>] (video_ioctl2 [videodev]) from [<bf187144>] (v4l2_ioctl+0x4c/0x60 [videodev])                                                                               
[41648.654751] [<bf187144>] (v4l2_ioctl [videodev]) from [<c03e98a4>] (do_vfs_ioctl+0xbc/0x804)                                                                                         
[41648.654759] [<c03e98a4>] (do_vfs_ioctl) from [<c03ea030>] (ksys_ioctl+0x44/0x6c)
[41648.654765] [<c03ea030>] (ksys_ioctl) from [<c03ea070>] (sys_ioctl+0x18/0x1c)
[41648.654771] [<c03ea070>] (sys_ioctl) from [<c0201000>] (ret_fast_syscall+0x0/0x28)
[41648.654775] Exception stack(0xc0157fa8 to 0xc0157ff0)
[41648.654780] 7fa0:                   ffffffff 7fffffff 00000005 40045612 befe66d8 00000005
[41648.654785] 7fc0: ffffffff 7fffffff 00000001 00000036 00000001 00000000 b6fb4000 befe66e4
[41648.654788] 7fe0: 01a045dc befe66cc 013350bc b64e551c
[41648.654793] ---[ end trace 874bc099afe54842 ]---

Not sure if this is a known issue on the RPI4...

Thanks,
Ming Qian April 30, 2020, 5:47 a.m. UTC | #2
> On Wed, 29. Apr 16:14, Ming Qian wrote:
> >     Without this setting, bitrate may have no effect
> >     if the default value of bitrate mode is VBR.
> >
> > Signed-off-by: Ming Qian <ming.qian@nxp.com>
> > ---
> >  libavcodec/v4l2_m2m_enc.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> > index 8454e2326c..6296ad88c6 100644
> > --- a/libavcodec/v4l2_m2m_enc.c
> > +++ b/libavcodec/v4l2_m2m_enc.c
> > @@ -191,6 +191,7 @@ static int v4l2_prepare_encoder(V4L2m2mContext
> *s)
> >
> >      /* set ext ctrls */
> >      v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE),
> > MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode", 0);
> > +    v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE_MODE),
> > + MPEG_VIDEO(BITRATE_MODE_CBR), "bit rate mode", 1);
> >      v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate", 1);
> >      v4l2_set_ext_ctrl(s, MPEG_CID(FRAME_RC_ENABLE), 1, "frame level
> rate control", 0);
> >      v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop
> > size", 1);
> > --
> > 2.26.0
> >
> 
> On the RPI4 it causes streamon to fail:
> 
> ./ffmpeg -y -i 7799x264.mp4 -an -codec:v h264_v4l2m2m out.264
> [h264_v4l2m2m @ 0x3d6e3b0] VIDIOC_STREAMON failed on output context
> Video encoding failed Conversion failed!
> 
> [41648.654237] bcm2835-codec bcm2835-codec:
> bcm2835_codec_start_streaming: Failed enabling i/p port, ret -3
> [41648.654243] ------------[ cut here ]------------ [41648.654267] WARNING: CPU:
> 2 PID: 26254 at drivers/media/common/videobuf2/videobuf2-core.c:1365
> vb2_start_streaming+0xe4/0x160 [videobuf2_common] [41648.654271]
> Modules linked in: bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q
> garp stp llc vc4 v3d gpu_sched drm_kms_helper brcmfmac brcmutil drm
> snd_soc_core sha256_generic snd_compress snd_pcm_dmaengine
> drm_panel_orientation_quirks syscopyarea sysfillrect sysimgblt fb_sys_fops
> raspberrypi_hwmon cfg80211 hwmon snd_bcm2835(C) snd_pcm rfkill
> snd_timer bcm2835_v4l2(C) snd bcm2835_codec(C) v4l2_mem2mem
> v4l2_common bcm2835_mmal_vchiq(C) videobuf2_vmalloc
> videobuf2_dma_contig videobuf2_memops videobuf2_v4l2
> videobuf2_common videodev media vc_sm_cma(C) rpivid_mem
> uio_pdrv_genirq uio ip_tables x_tables ipv6
> [41648.654351] CPU: 2 PID: 26254 Comm: ffmpeg Tainted: G        WC
> 4.19.97-v7l+ #1294
> [41648.654355] Hardware name: BCM2835
> [41648.654374] [<c0212e04>] (unwind_backtrace) from [<c020d5e0>]
> (show_stack+0x20/0x24) [41648.654383] [<c020d5e0>] (show_stack) from
> [<c09b15c8>] (dump_stack+0xe0/0x124) [41648.654392] [<c09b15c8>]
> (dump_stack) from [<c0222544>] (__warn+0x104/0x11c) [41648.654400]
> [<c0222544>] (__warn) from [<c0222694>] (warn_slowpath_null+0x50/0x58)
> [41648.654414] [<c0222694>] (warn_slowpath_null) from [<bf2126f8>]
> (vb2_start_streaming+0xe4/0x160 [videobuf2_common]) [41648.654434]
> [<bf2126f8>] (vb2_start_streaming [videobuf2_common]) from [<bf214130>]
> (vb2_core_streamon+0x130/0x16c [videobuf2_common]) [41648.654451]
> [<bf214130>] (vb2_core_streamon [videobuf2_common]) from [<bf2368a8>]
> (vb2_streamon+0x40/0x60 [videobuf2_v4l2]) [41648.654467] [<bf2368a8>]
> (vb2_streamon [videobuf2_v4l2]) from [<bf27eaa0>]
> (v4l2_m2m_streamon+0x30/0x48 [v4l2_mem2mem]) [41648.654480]
> [<bf27eaa0>] (v4l2_m2m_streamon [v4l2_mem2mem]) from [<bf27ead8>]
> (v4l2_m2m_ioctl_streamon+0x20/0x24 [v4l2_mem2mem]) [41648.654518]
> [<bf27ead8>] (v4l2_m2m_ioctl_streamon [v4l2_mem2mem]) from
> [<bf188e3c>] (v4l_streamon+0x28/0x2c [videodev]) [41648.654571]
> [<bf188e3c>] (v4l_streamon [videodev]) from [<bf18ba38>]
> (__video_do_ioctl+0x268/0x528 [videodev]) [41648.654621] [<bf18ba38>]
> (__video_do_ioctl [videodev]) from [<bf18f470>]
> (video_usercopy+0x218/0x600 [videodev]) [41648.654670] [<bf18f470>]
> (video_usercopy [videodev]) from [<bf18f878>] (video_ioctl2+0x20/0x24
> [videodev]) [41648.654720] [<bf18f878>] (video_ioctl2 [videodev]) from
> [<bf187144>] (v4l2_ioctl+0x4c/0x60 [videodev]) [41648.654751] [<bf187144>]
> (v4l2_ioctl [videodev]) from [<c03e98a4>] (do_vfs_ioctl+0xbc/0x804)
> [41648.654759] [<c03e98a4>] (do_vfs_ioctl) from [<c03ea030>]
> (ksys_ioctl+0x44/0x6c) [41648.654765] [<c03ea030>] (ksys_ioctl) from
> [<c03ea070>] (sys_ioctl+0x18/0x1c) [41648.654771] [<c03ea070>] (sys_ioctl)
> from [<c0201000>] (ret_fast_syscall+0x0/0x28) [41648.654775] Exception
> stack(0xc0157fa8 to 0xc0157ff0)
> [41648.654780] 7fa0:                   ffffffff 7fffffff 00000005 40045612
> befe66d8 00000005
> [41648.654785] 7fc0: ffffffff 7fffffff 00000001 00000036 00000001 00000000
> b6fb4000 befe66e4 [41648.654788] 7fe0: 01a045dc befe66cc 013350bc
> b64e551c [41648.654793] ---[ end trace 874bc099afe54842 ]---
> 
> Not sure if this is a known issue on the RPI4...
> 
> Thanks,
> --
> Andriy

It's strange, in my opinion, the change is unlikely to affect the streamon. But it led to a kernel panic.
Andriy Gelman April 30, 2020, 2:47 p.m. UTC | #3
On Thu, 30. Apr 05:47, Ming Qian wrote:
> 
> 
> > On Wed, 29. Apr 16:14, Ming Qian wrote:
> > >     Without this setting, bitrate may have no effect
> > >     if the default value of bitrate mode is VBR.
> > >
> > > Signed-off-by: Ming Qian <ming.qian@nxp.com>
> > > ---
> > >  libavcodec/v4l2_m2m_enc.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> > > index 8454e2326c..6296ad88c6 100644
> > > --- a/libavcodec/v4l2_m2m_enc.c
> > > +++ b/libavcodec/v4l2_m2m_enc.c
> > > @@ -191,6 +191,7 @@ static int v4l2_prepare_encoder(V4L2m2mContext
> > *s)
> > >
> > >      /* set ext ctrls */
> > >      v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE),
> > > MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode", 0);
> > > +    v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE_MODE),
> > > + MPEG_VIDEO(BITRATE_MODE_CBR), "bit rate mode", 1);
> > >      v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate", 1);
> > >      v4l2_set_ext_ctrl(s, MPEG_CID(FRAME_RC_ENABLE), 1, "frame level
> > rate control", 0);
> > >      v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop
> > > size", 1);
> > > --
> > > 2.26.0
> > >
> > 
> > On the RPI4 it causes streamon to fail:
> > 
> > ./ffmpeg -y -i 7799x264.mp4 -an -codec:v h264_v4l2m2m out.264
> > [h264_v4l2m2m @ 0x3d6e3b0] VIDIOC_STREAMON failed on output context
> > Video encoding failed Conversion failed!
> > 
> > [41648.654237] bcm2835-codec bcm2835-codec:
> > bcm2835_codec_start_streaming: Failed enabling i/p port, ret -3
> > [41648.654243] ------------[ cut here ]------------ [41648.654267] WARNING: CPU:
> > 2 PID: 26254 at drivers/media/common/videobuf2/videobuf2-core.c:1365
> > vb2_start_streaming+0xe4/0x160 [videobuf2_common] [41648.654271]
> > Modules linked in: bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q
> > garp stp llc vc4 v3d gpu_sched drm_kms_helper brcmfmac brcmutil drm
> > snd_soc_core sha256_generic snd_compress snd_pcm_dmaengine
> > drm_panel_orientation_quirks syscopyarea sysfillrect sysimgblt fb_sys_fops
> > raspberrypi_hwmon cfg80211 hwmon snd_bcm2835(C) snd_pcm rfkill
> > snd_timer bcm2835_v4l2(C) snd bcm2835_codec(C) v4l2_mem2mem
> > v4l2_common bcm2835_mmal_vchiq(C) videobuf2_vmalloc
> > videobuf2_dma_contig videobuf2_memops videobuf2_v4l2
> > videobuf2_common videodev media vc_sm_cma(C) rpivid_mem
> > uio_pdrv_genirq uio ip_tables x_tables ipv6
> > [41648.654351] CPU: 2 PID: 26254 Comm: ffmpeg Tainted: G        WC
> > 4.19.97-v7l+ #1294
> > [41648.654355] Hardware name: BCM2835
> > [41648.654374] [<c0212e04>] (unwind_backtrace) from [<c020d5e0>]
> > (show_stack+0x20/0x24) [41648.654383] [<c020d5e0>] (show_stack) from
> > [<c09b15c8>] (dump_stack+0xe0/0x124) [41648.654392] [<c09b15c8>]
> > (dump_stack) from [<c0222544>] (__warn+0x104/0x11c) [41648.654400]
> > [<c0222544>] (__warn) from [<c0222694>] (warn_slowpath_null+0x50/0x58)
> > [41648.654414] [<c0222694>] (warn_slowpath_null) from [<bf2126f8>]
> > (vb2_start_streaming+0xe4/0x160 [videobuf2_common]) [41648.654434]
> > [<bf2126f8>] (vb2_start_streaming [videobuf2_common]) from [<bf214130>]
> > (vb2_core_streamon+0x130/0x16c [videobuf2_common]) [41648.654451]
> > [<bf214130>] (vb2_core_streamon [videobuf2_common]) from [<bf2368a8>]
> > (vb2_streamon+0x40/0x60 [videobuf2_v4l2]) [41648.654467] [<bf2368a8>]
> > (vb2_streamon [videobuf2_v4l2]) from [<bf27eaa0>]
> > (v4l2_m2m_streamon+0x30/0x48 [v4l2_mem2mem]) [41648.654480]
> > [<bf27eaa0>] (v4l2_m2m_streamon [v4l2_mem2mem]) from [<bf27ead8>]
> > (v4l2_m2m_ioctl_streamon+0x20/0x24 [v4l2_mem2mem]) [41648.654518]
> > [<bf27ead8>] (v4l2_m2m_ioctl_streamon [v4l2_mem2mem]) from
> > [<bf188e3c>] (v4l_streamon+0x28/0x2c [videodev]) [41648.654571]
> > [<bf188e3c>] (v4l_streamon [videodev]) from [<bf18ba38>]
> > (__video_do_ioctl+0x268/0x528 [videodev]) [41648.654621] [<bf18ba38>]
> > (__video_do_ioctl [videodev]) from [<bf18f470>]
> > (video_usercopy+0x218/0x600 [videodev]) [41648.654670] [<bf18f470>]
> > (video_usercopy [videodev]) from [<bf18f878>] (video_ioctl2+0x20/0x24
> > [videodev]) [41648.654720] [<bf18f878>] (video_ioctl2 [videodev]) from
> > [<bf187144>] (v4l2_ioctl+0x4c/0x60 [videodev]) [41648.654751] [<bf187144>]
> > (v4l2_ioctl [videodev]) from [<c03e98a4>] (do_vfs_ioctl+0xbc/0x804)
> > [41648.654759] [<c03e98a4>] (do_vfs_ioctl) from [<c03ea030>]
> > (ksys_ioctl+0x44/0x6c) [41648.654765] [<c03ea030>] (ksys_ioctl) from
> > [<c03ea070>] (sys_ioctl+0x18/0x1c) [41648.654771] [<c03ea070>] (sys_ioctl)
> > from [<c0201000>] (ret_fast_syscall+0x0/0x28) [41648.654775] Exception
> > stack(0xc0157fa8 to 0xc0157ff0)
> > [41648.654780] 7fa0:                   ffffffff 7fffffff 00000005 40045612
> > befe66d8 00000005
> > [41648.654785] 7fc0: ffffffff 7fffffff 00000001 00000036 00000001 00000000
> > b6fb4000 befe66e4 [41648.654788] 7fe0: 01a045dc befe66cc 013350bc
> > b64e551c [41648.654793] ---[ end trace 874bc099afe54842 ]---
> > 
> > Not sure if this is a known issue on the RPI4...
> > 
> > Thanks,
> > --
> > Andriy
> 
> It's strange, in my opinion, the change is unlikely to affect the streamon. But it led to a kernel panic.
> 

I upgraded the RPi4, but the issue is still there... 
If I set the mode to VBR it works fine. I'll try to debug the driver.
diff mbox series

Patch

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 8454e2326c..6296ad88c6 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -191,6 +191,7 @@  static int v4l2_prepare_encoder(V4L2m2mContext *s)
 
     /* set ext ctrls */
     v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE), MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode", 0);
+    v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE_MODE), MPEG_VIDEO(BITRATE_MODE_CBR), "bit rate mode", 1);
     v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate", 1);
     v4l2_set_ext_ctrl(s, MPEG_CID(FRAME_RC_ENABLE), 1, "frame level rate control", 0);
     v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop size", 1);