Storm
Posts: 14
Joined: Tue Sep 22, 2015 9:39 am

Pb Picamera Bitrate unstable

Fri Oct 16, 2015 4:18 pm

Hello,

I need " Picamera " to use both video and photo .

I send the video to a network , it needs a stable and constant bitrate, +/- 1 000 kbits/s.
I ask Picamera bitrate = 1000000

Problem when sending video , bitrate remains constant for 1 minute but then it is constantly increasing.

With " raspivid " and "-b 1000000 " , the flow is stable.

Is there a solution?

Thank

User avatar
jbeale
Posts: 3469
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Pb Picamera Bitrate unstable

Fri Oct 16, 2015 5:38 pm

It would probably make debugging this easier if you post code that demonstrates the problem.

Storm
Posts: 14
Joined: Tue Sep 22, 2015 9:39 am

Re: Pb Picamera Bitrate unstable

Sat Oct 17, 2015 10:01 am

Thank for reponse
Exact, an example.

Code: Select all

with picamera.PiCamera() as camera:
 while True:
    camera.resolution = (900, 680)
    camera.framerate = 25
    camera.start_recording(sys.stdout, format='h264', bitrate=1000000)
    camera.wait_recording(295)
    camera.capture('test.jpg', use_video_port=True)
    camera.wait_recording(5)
    camera.stop_recording()
I run python

The first seconds:

Code: Select all

frame=  214 fps= 21 q=-1.0 size=    1077kB time=00:00:08.52 bitrate=1035.6kbits/s
frame=  225 fps= 21 q=-1.0 size=    1131kB time=00:00:08.96 bitrate=1033.5kbits/s
frame=  235 fps= 21 q=-1.0 size=    1216kB time=00:00:09.40 bitrate=1059.0kbits/s
frame=  242 fps= 21 q=-1.0 size=    1234kB time=00:00:09.64 bitrate=1049.0kbits/s
3 minutes later.

Code: Select all

frame= 4400 fps=8.8 q=-1.0 size=   50008kB time=00:02:55.96 bitrate=2328.2kbits/s
frame= 4403 fps=8.8 q=-1.0 size=   50070kB time=00:02:56.08 bitrate=2329.5kbits/s
frame= 4405 fps=8.8 q=-1.0 size=   50147kB time=00:02:56.16 bitrate=2332.0kbits/s
frame= 4407 fps=8.8 q=-1.0 size=   50223kB time=00:02:56.24 bitrate=2334.5kbits/s
Thank

User avatar
jbeale
Posts: 3469
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Pb Picamera Bitrate unstable

Thu Oct 22, 2015 3:58 pm

I assume the complexity of the scene is unchanged? You have clearly stated the problem, but I do not know the reason. If the same bitrate does work with raspivid, that suggests something about the Picamera library. Have you tried video but without also taking the still image?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7008
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pb Picamera Bitrate unstable

Thu Oct 22, 2015 4:43 pm

Really one for waveform80 as I suspect it is a Picamera specific thing.
You're calling

Code: Select all

camera.capture('test.jpg', use_video_port=True)
whilst recording. There is only one video port but you've told it to do two jobs. I suspect Picamera is tearing down the video encoder to do the still capture, and then forgets to reset the bitrate when it sets things up to resume recording.

Try removing the "use_video_port=True" as a first step.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Storm
Posts: 14
Joined: Tue Sep 22, 2015 9:39 am

Re: Pb Picamera Bitrate unstable

Wed Oct 28, 2015 10:18 am

Thank you for your answers.

Finally bitrate is more stable when I change the bitrate in the "encoders.py" file and I play with intra-refresh.

One question: is it possible to have a real CBR with PiCamera?
When night falls, bitrate collapses instead of staying at 1 000 000.

Thank

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7008
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pb Picamera Bitrate unstable

Wed Oct 28, 2015 11:23 am

Storm wrote:Finally bitrate is more stable when I change the bitrate in the "encoders.py" file and I play with intra-refresh.
Raise an issue under https://github.com/waveform80/picamera/issues then. waveform80 is generally fairly responsive, and you've done most of the work for him (you could even fix it properly and create a pull request!)
Storm wrote:One question: is it possible to have a real CBR with PiCamera?
When night falls, bitrate collapses instead of staying at 1 000 000.
There is no such thing as a totally constant bitrate - I frames are always bigger than P frames.
You can request an approximately constant bitrate over a period of around a second via MMAL. It looks like Picamera hasn't implemented it though.
You'd be looking to set MMAL parameter MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL to MMAL_VIDEO_ENCODER_RC_MODEL_CBR (see https://github.com/raspberrypi/userland ... rs_video.h for definitions).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
waveform80
Posts: 303
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pb Picamera Bitrate unstable

Mon Nov 23, 2015 8:19 pm

Sorry - haven't been watching the forums as much recently (too busy with other projects!). Sounds like I've got something wrong though.

@6by9: the pipeline under picamera when recording video and capturing an image with "use_video_port=True" at the same time involves the video splitter (picamera always constructs one for the video port). So the pipeline will look like the third image down here (video port to splitter to H264 encoder and JPEG encoder); in other words, the H264 encoder should remain setup constantly throughout. At a guess I'd assume I've done something wrong in setting the bitrate. If someone wants to open a github ticket for this, I'll look into it as soon as I can (though I can't promise when that will be - gpiozero and real-life are keeping me rather busy at the moment, sorry!)


Dave.

Return to “Camera board”