Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Buffer Size #13

Closed
rocxteady opened this issue Apr 18, 2014 · 11 comments
Closed

Setting Buffer Size #13

rocxteady opened this issue Apr 18, 2014 · 11 comments

Comments

@rocxteady
Copy link

Hello.

How can I set the buffer size of a stream? Or buffer time?
I am streaming only audio.
Default buffer time is around 5 seconds. How can I decrease this?

Thanks

@bbcallen
Copy link
Contributor

  1. If you want to decrease them once and for all, just modify these macros in ff_ffplay_def.h
// buffer bytes
#define DEFAULT_HIGH_WATER_MARK_IN_BYTES    (128 * 1024)

// buffer duration, in milliseconds
#define DEFAULT_MAX_HIGH_WATER_MARK_IN_MS       (5 * 1000)

// buffer duration for the 1st time, in milliseconds
#define DEFAULT_FAST_HIGH_WATER_MARK_IN_MS      (100)
  1. if you want to set them from application, add these api
// see how ijkmp_set_overlay_format() does
ijkmp_set_high_water_mark()
ffp_set_high_water_mark()
  1. if you want to change them from application while streaming, multiple-thread issues would be concerned. I would prefer to implement dynamic strategy inside read_thread() in ff_ffplay.c

@rocxteady
Copy link
Author

#define DEFAULT_HIGH_WATER_MARK_IN_BYTES (8 * 1024)

#define DEFAULT_MAX_HIGH_WATER_MARK_IN_MS (0.25 * 1000)
#define DEFAULT_NORMAL_HIGH_WATER_MARK_IN_MS (0.1 * 1000)
#define DEFAULT_FAST_HIGH_WATER_MARK_IN_MS (100)

I set them like these. It is still around 5 seconds...

@bbcallen
Copy link
Contributor

Could you uncomment this line in ff_ffplay.c and paste some log?

// ff_ffplay.c
#define FFP_SHOW_DEMUX_CACHE

@rocxteady
Copy link
Author

audio cache=%1923 (4784/250)
time cache=%1923 (4784/250)
size cache=%489 (39847/8192)
audio cache=%1942 (4830/250)
time cache=%1942 (4830/250)
size cache=%494 (40230/8192)
audio cache=%1960 (4876/250)
time cache=%1960 (4876/250)
size cache=%498 (40603/8192)
audio cache=%1979 (4922/250)
time cache=%1979 (4922/250)
size cache=%503 (40990/8192)
audio cache=%1997 (4968/250)
time cache=%1997 (4968/250)
size cache=%508 (41382/8192)
audio cache=%2016 (5014/250)
time cache=%2016 (5014/250)
size cache=%512 (41761/8192)
audio cache=%2034 (5060/250)
time cache=%2034 (5060/250)
size cache=%517 (42141/8192)
audio cache=%2053 (5106/250)
time cache=%2053 (5106/250)
size cache=%522 (42525/8192)
audio cache=%2071 (5152/250)
time cache=%2071 (5152/250)
size cache=%526 (42904/8192)
audio cache=%2090 (5198/250)
time cache=%2090 (5198/250)
size cache=%531 (43291/8192)
audio cache=%2090 (5198/250)
audio cache=%2108 (5244/250)
time cache=%2108 (5244/250)
size cache=%536 (43680/8192)
audio cache=%2127 (5290/250)
time cache=%2127 (5290/250)
size cache=%541 (44079/8192)
audio cache=%2145 (5336/250)
time cache=%2145 (5336/250)
size cache=%545 (44459/8192)
audio cache=%2145 (5336/250)
audio cache=%2164 (5382/250)
time cache=%2164 (5382/250)
size cache=%550 (44830/8192)
audio cache=%1868 (4646/250)
time cache=%1868 (4646/250)
size cache=%472 (38511/8192)
audio cache=%1886 (4692/250)
time cache=%1886 (4692/250)
size cache=%477 (38889/8192)
audio cache=%1905 (4738/250)
time cache=%1905 (4738/250)
size cache=%482 (39269/8192)
audio cache=%1923 (4784/250)
time cache=%1923 (4784/250)
size cache=%487 (39656/8192)
audio cache=%1942 (4830/250)
time cache=%1942 (4830/250)
size cache=%491 (40038/8192)
audio cache=%1960 (4876/250)
time cache=%1960 (4876/250)
size cache=%496 (40419/8192)
audio cache=%1979 (4922/250)
time cache=%1979 (4922/250)
size cache=%501 (40800/8192)
audio cache=%1997 (4968/250)
time cache=%1997 (4968/250)
size cache=%505 (41182/8192)
audio cache=%2016 (5014/250)
time cache=%2016 (5014/250)
size cache=%510 (41566/8192)
audio cache=%2034 (5060/250)
time cache=%2034 (5060/250)
size cache=%515 (41953/8192)
audio cache=%2053 (5106/250)
time cache=%2053 (5106/250)
size cache=%519 (42333/8192)
audio cache=%2071 (5152/250)
time cache=%2071 (5152/250)
size cache=%524 (42714/8192)
audio cache=%2090 (5198/250)
time cache=%2090 (5198/250)
size cache=%529 (43098/8192)
audio cache=%2108 (5244/250)
time cache=%2108 (5244/250)
size cache=%533 (43479/8192)
audio cache=%2108 (5244/250)
size cache=%532 (43403/8192)
audio cache=%2127 (5290/250)
time cache=%2127 (5290/250)
size cache=%537 (43782/8192)
audio cache=%1905 (4738/250)
time cache=%1905 (4738/250)
size cache=%483 (39400/8192)
audio cache=%1923 (4784/250)
time cache=%1923 (4784/250)
size cache=%488 (39787/8192)
audio cache=%1942 (4830/250)
time cache=%1942 (4830/250)
size cache=%493 (40173/8192)
audio cache=%1960 (4876/250)
time cache=%1960 (4876/250)
size cache=%498 (40573/8192)
audio cache=%1720 (4278/250)
time cache=%1720 (4278/250)
size cache=%438 (35709/8192)
audio cache=%1738 (4324/250)
time cache=%1738 (4324/250)
size cache=%442 (36063/8192)
audio cache=%1757 (4370/250)
time cache=%1757 (4370/250)
size cache=%447 (36432/8192)
audio cache=%1775 (4416/250)
time cache=%1775 (4416/250)
size cache=%451 (36802/8192)
audio cache=%1794 (4462/250)
time cache=%1794 (4462/250)
size cache=%456 (37171/8192)
audio cache=%1812 (4508/250)
time cache=%1812 (4508/250)
size cache=%460 (37533/8192)
audio cache=%1720 (4278/250)
time cache=%1720 (4278/250)
size cache=%437 (35619/8192)
audio cache=%1738 (4324/250)
time cache=%1738 (4324/250)
size cache=%442 (36003/8192)
audio cache=%1757 (4370/250)
time cache=%1757 (4370/250)
size cache=%446 (36385/8192)
audio cache=%1775 (4416/250)
time cache=%1775 (4416/250)
size cache=%451 (36765/8192)
audio cache=%1794 (4462/250)
time cache=%1794 (4462/250)
size cache=%456 (37157/8192)
audio cache=%1812 (4508/250)
time cache=%1812 (4508/250)
size cache=%461 (37543/8192)
audio cache=%1831 (4554/250)
time cache=%1831 (4554/250)
size cache=%465 (37921/8192)
audio cache=%1849 (4600/250)
time cache=%1849 (4600/250)
size cache=%470 (38305/8192)
audio cache=%1868 (4646/250)

@bbcallen
Copy link
Contributor

The DEFAULT_MAX_HIGH_WATER_MARK_IN_MS means the least buffer to resume.
Player only resume from "stalled buffering" when pre-read data above this size.
It effect the player start delay.

If you mean the max pre-reading size, I think it should be

// Player does pre-reading only below this size, in bytes
#define MAX_QUEUE_SIZE (15 * 1024 * 1024)

// MIN_FRAMES=5 in original ffplay,  packets/frames in pre-reading queue.
#define MIN_FRAMES 50000

Which one did you mean when you mention ''5 seconds"?
Do you want to reduce the delay of the start, or reduce the pre-reading size?

@rocxteady
Copy link
Author

When I change stream on the server, in the app I see the change 5 seconds later. Then I decided to decrease the buffersize.

@bbcallen
Copy link
Contributor

Then you should reduce MIN_FRAMES or/and MAX_QUEUE_SIZE

@ened
Copy link
Contributor

ened commented Sep 17, 2016

@bbcallen:

Does this API:

if you want to set them from application, add these api
// see how ijkmp_set_overlay_format() does
ijkmp_set_high_water_mark()
ffp_set_high_water_mark()

still exist?

@developeralp
Copy link

@ened

You can ,

                    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", 1024*1024);
                    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0);
                    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames",5);
                    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "first-high-water-mark-ms",100);
                    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "next-high-water-mark-ms",100);

On IjkVideoView.

Also , you can learn variables from ,

https://github.com/Bilibili/ijkplayer/blob/master/ijkmedia/ijkplayer/ff_ffplay_def.h
https://github.com/Bilibili/ijkplayer/blob/master/ijkmedia/ijkplayer/ff_ffplay_options.h#L110

@ened
Copy link
Contributor

ened commented Nov 6, 2016

HI @developeralp ,

Thank you!

I was using this before:

        opts.setPlayerOptionIntValue(5 * 1000, forKey: "first-high-water-mark-ms")
        opts.setPlayerOptionIntValue(50 * 1000, forKey: "next-high-water-mark-ms")
        opts.setPlayerOptionIntValue(100 * 1000, forKey: "last-high-water-mark-ms")
        opts.setPlayerOptionIntValue(10000, forKey: "min-frames")
        opts.setPlayerOptionIntValue((128 * 1024 * 1024), forKey: "max-buffer-size")

Will re-evaluate today, as it did not seem to work.

Why did you set ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0); ?

@spaul13
Copy link

spaul13 commented Feb 21, 2018

can anyone, @rocxteady , @bbcallen @ened @developeralp @tewilove please tell me how to change the size of the video buffer? what's the size of video buffer by default?

from where it's calling the buffer to write into it and who takes the data out of the buffer?

I am getting an error
E/tv.danmaku.ijk.media.player.IjkMediaPlayer: Buffer (100%) 26468/14750

I have seen ijkfifobuffer is implemented but I want to know where the buffer is written actually? I have seen an array based contiguous allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants