This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VE-Q1: How to set encoder bitrate

Part Number: TDA4VE-Q1
Other Parts Discussed in Thread: TEST2

We use J721S2 and SDK8.4

We test encoder sample cmd and we want to set different bitrate.

Test1: bitrate=10000000

gst-launch-1.0 videotestsrc pattern=ball num-buffers=100 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc bitrate=10000000 ! h264parse ! filesink location=./demo.264

Test2: bitrate=100000000

gst-launch-1.0 videotestsrc pattern=ball num-buffers=100 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc bitrate=100000000 ! h264parse ! filesink location=./demo.264

Test3: bitrate=50000

gst-launch-1.0 videotestsrc pattern=ball num-buffers=100 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc bitrate=50000! h264parse ! filesink location=./demo.264

But the result is the same.

How to set encoder bitrate?

  • Hi Joe, 

    You can see the controls menu for the J721s2 by entering v4l2-ctl -d 3 --list-ctrls-menu in the command line. Here you can see that to set bitrate you need to use "enc,video_bitrate=10000000"

    Here is an example pipeline that should work: 

    gst-launch-1.0 videotestsrc pattern=ball num-buffers=100 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,video_bitrate=100000000" ! h264parse ! filesink location=/test_streams/demo1.264

    Thank you,
    Sarabesh S

  • This is our testcase: 

    Testcase1:

    gst-launch-1.0 videotestsrc pattern=ball num-buffers=100 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,video_bitrate=10000" ! h264parse ! filesink lo
    cation=demo1.264

    output size is 16573Byte

    Testcase1:

    gst-launch-1.0 videotestsrc pattern=ball num-buffers=100 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,video_bitrate=100000000" ! h264parse ! filesink lo
    cation=demo1.264

    output size is 16573Byte

    But the result is the same.

    If we set bigger bitrate, output size should be bigger.

  • Hi Joe, 

    Currently investigating this and will provide you with an update why this is the case. I agree and tested this on multiple streams and bitrate does not appear to get set.

    Thanks,
    Sarabesh S

  • Hi Joe, 

    It looks like you need to enable the rate control in the pipeline with this: rate-control by using "frame_level_rate_control_enable=1"

    Here is an example of the pipeline from your testcase: 

    gst-launch-1.0 videotestsrc pattern=ball num-buffers=1000 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,frame_level_rate_control_enable=1,video_bitrate=20000000" ! h264parse ! filesink location=/test_streams/demo_20mbps.264

    The size output for this simple demo file does not vary by a lot but there is a slight increase in size with higher bitrates set. When I tested on more complex streams, the output size did show a larger difference. However, there is still some issues when setting higher bitrates (100mbps or 200mbps) on more complex streams, resulting in the pipeline to hang. Working to debug this and will keep you updated.

    Thank you,
    Sarabesh S

  • Test 1:

    gst-launch-1.0 videotestsrc pattern=ball num-buffers=100000 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,frame_level_rate_control_enable=1,video_bitrate=20000000" ! h264parse ! filesink location=demo_20mbps.264

    Output File Size : 52,805,520 Byte

    Test2: 

    gst-launch-1.0 videotestsrc pattern=ball num-buffers=100000 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,frame_level_rate_control_enable=1,video_bitrate=20000" ! h264parse ! filesink location=demo_20000bps.264

    Output File Size : 52,805,520 Byte

    The Result are all the same.

  • Hi Joe, 

    I received a patch from our IP vendor. I will do some testing to confirm this solves the problem and keep you updated. Thank you for your patience. 

    Regards, 
    Sarabesh S

  • Hi Joe, 

    I have tested the patch on different streams and was able to successfully encode different streams with different bitrates resulting in corresponding file sizes. I also tested the pattern ball stream with these pipelines below: 

    Test1:
    gst-launch-1.0 videotestsrc pattern=ball num-buffers=5000 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,frame_level_rate_control_enable=1,video_bitrate_mode=1,video_bitrate=5000000" ! h264parse ! filesink location=/test_streams/demo5mbps.264

    Test1 Output File Size: 2420459 bytes

    Test2:
    gst-launch-1.0 videotestsrc pattern=ball num-buffers=5000 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,frame_level_rate_control_enable=1,video_bitrate_mode=1,video_bitrate=20000000" ! h264parse ! filesink location=/test_streams/demo20mbps.264

    Test2 Output File Size: 2420965 bytes

    Test3:
    gst-launch-1.0 videotestsrc pattern=ball num-buffers=5000 ! video/x-raw, format=NV12, width=852, height=480, framerate=30/1 ! v4l2h264enc extra-controls="enc,frame_level_rate_control_enable=1,video_bitrate_mode=1,video_bitrate=100000000" ! h264parse ! filesink location=/test_streams/demo100mbps.264

    Test3 Output File Size: 2421522 bytes

    With more complex streams you should see a greater difference based on bitrate, but with this pattern-ball sample stream the difference is minimal.

    This patch is already merged into our tree so you can pull that. The link to the patch is below: 

    https://git.ti.com/cgit/ti-linux-kernel/ti-linux-kernel/commit/?h=ti-linux-6.1.y-cicd&id=12598d7a3ca52f5166b67cc714329029b4502543

    Thank you,
    Sarabesh S