When making audio and video playback, many companies use the open source iJkPlayer. Ijkplayer is based on FFMPEG at the bottom, which may often encounter various problems in a certain model. Today, we sorted out the problems we encountered in using iJkPlayer, as well as the issues and solutions according to the iJkPlayer community. As follows:

1, summarize the broadcast technology (3) ijkplayer record some of the problems optimization blog.csdn.net/hejjunlin/a…

2, video broadcast technology (4) : use Ijkplayer broadcast live video www.cnblogs.com/renhui/p/64…

Not regularly update of the 3, IJKPlayer question highlights – www.jianshu.com/p/220b00d00…

4, live technical summary (3) ijkplayer record some of the problems optimization – blog.csdn.net/hejjunlin/a…

5, ijkplayer RTMP seconds on ijkplayer set RTMP seconds on, can make RTMP load time from 5~10 seconds to less than 1s, in order to achieve second on and low latency:

IjkMediaPlayer ijkMediaPlayer = null;  
ijkMediaPlayer = new IjkMediaPlayer();  
ijkMediaPlayer.setOption(1, "analyzemaxduration", 100L);  
ijkMediaPlayer.setOption(1, "probesize", 10240L);  
ijkMediaPlayer.setOption(1, "flush_packets", 1L);  
ijkMediaPlayer.setOption(4, "packet-buffering", 0L);  
ijkMediaPlayer.setOption(4, "framedrop", 1L); 
Copy the code

6. When ijkPlayer plays streaming media with high real-time requirements such as RTMP in real time, there will be a delay of about 10S. The reason is that the buffer processing is added, which can reduce its cache setting to achieve real-time effect:

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);  
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0);  
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);  
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter"And 8); ijkMediaPlayer.setOption(1,"analyzemaxduration", 100L);  
ijkMediaPlayer.setOption(1, "probesize", 10240L);  
ijkMediaPlayer.setOption(1, "flush_packets", 1L);  
ijkMediaPlayer.setOption(4, "packet-buffering", 0L);  
ijkMediaPlayer.setOption(4, "framedrop", 1L);
Copy the code

7, fast live streams: live technical summary (5) how to quickly broadcast live streaming – blog.csdn.net/hejjunlin/a… The latter is optimized by modifying two parameters, probesize and analyzedUration, respectively to control the amount and duration of data read. Reducing probesize and analyzeduration can reduce avFormat_find_stream_info’s function time and speed up playback

ijkMediaPlayer.setOption(1,"analyzemaxduration",xxx);
ijkMediaPlayer.setOption(1,"probesize",xxx);
Copy the code

Caton optimization and second open, weak network optimization

  • Ijkplayer RTMP delay long solution to second open results – blog.csdn.net/yyhjifeng/a…
  • Ijkplayer live players use the rule of thumb – caton optimization and seconds – blog.csdn.net/cmshao/arti…

9, ijkplayer lost frame processing scheme of https://www.jianshu.com/p/ecf51ee32589 live delay, if delay is too big, can take two strategies, one is a lost frame, is a kind of frame. We can consider losing the audio package to achieve this, the audio package is not the key frame problem, it is easier to lose the operation, and then because the video is synchronized to the audio, so the video will catch the frame, also will follow.

10, using Ijkplayer times someone who comported himself solutions to problems – www.cnblogs.com/renhui/p/65…

public void setSpeed(float speed) {
    _setPropertyFloat(FFP_PROP_FLOAT_PLAYBACK_RATE, speed);
}
public float getSpeed(float speed) {
    return _getPropertyFloat(FFP_PROP_FLOAT_PLAYBACK_RATE, .0f);
}
Copy the code

Error code in ijkPlayer:

IJKMEDIA: SDL_JNI_DetachThreadEnv IjkPlayer how to break the handshake Android? How does ijkPlayer release the connection to Android? /* * Do not change these values without updating their counterpartsinnative */ int MEDIA_INFO_UNKNOWN = 1; Int MEDIA_INFO_STARTED_AS_NEXT = 2; Int MEDIA_INFO_VIDEO_RENDERING_START = 3; Int media_info_video_track_temper = 700; Int MEDIA_INFO_BUFFERING_START = 701; Int MEDIA_INFO_BUFFERING_END = 702; Int MEDIA_INFO_NETWORK_BANDWIDTH = 703; Int MEDIA_INFO_BAD_INTERLEAVING = 800; // Int MEDIA_INFO_BAD_INTERLEAVING = 800; // int MEDIA_INFO_NOT_SEEKABLE = 801; Int MEDIA_INFO_METADATA_UPDATE = 802; int MEDIA_INFO_METADATA_UPDATE = 802; // int MEDIA_INFO_TIMED_TEXT_ERROR = 900; int MEDIA_INFO_UNSUPPORTED_SUBTITLE = 901; Int MEDIA_INFO_SUBTITLE_TIMED_OUT = 902; // Subtitle timeout int MEDIA_INFO_VIDEO_INTERRUPT= -10000; Int MEDIA_INFO_VIDEO_ROTATION_CHANGED = 10001; Int MEDIA_INFO_AUDIO_RENDERING_START = 10002; Int MEDIA_ERROR_SERVER_DIED = 100; // The service hangs up and the video is interrupted. The video source is abnormal or the video type is not supported. int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200; // Data error no valid reclaim int MEDIA_ERROR_IO = -1004; //IO error int MEDIA_ERROR_MALFORMED = -1007; int MEDIA_ERROR_UNSUPPORTED = -1010; Int MEDIA_ERROR_TIMED_OUT = -110; // Data timeout Error (-10000,0)Copy the code

12. Ijkplayer Experience:

A, IJKPlayer does not rotate the video Angle like system player, so you need to go to onInfo what == iMediaPlayer. MEDIA_INFO_VIDEO_ROTATION_CHANGED to get the Angle and rotate the screen yourself; Or open hard hard decoding, not hard decoding easy to cause black screen silence, you are careful ah O__O “… .

mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1);
Copy the code

B, IJKPlayer appears black with sound but no image, check whether your video encoding is H264, whether pixel format exists, whether the audio encoding is AAC? IJKPlayer does not support 3PG by default. -? *)? , does not support MEPG (such as this library RecordVideoDemo), does not support AMR. So if you really want support, refer to this #1961, turn on MPEG support, reprogram FFMPEG, and then play MPEG by hard decoding; Or through the system to record VideoRecord; Or choose another JAVACV to record and encapsulate FFmpegRecorder.

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec_mpeg4", 1);
Copy the code

C, fast forward and slow play interface, only support API23 above, 23 below, it is necessary to configure ffmpeg to support avfilter, but there may be voice tremor and other problems, the official said unstable, refer to #1690. Tryavfilter but the audio sounds shaking = = For avfilter, only support software decoder.

D, pause, back to the background and then back to the foreground, the screen black? GetBitmap (point. X, point. Y); Get the paused image, display it with ImageView, hide the ImageView when onSurfaceTextureUpdated to connect the image.

E. Some video return codes

int MEDIA_INFO_VIDEO_RENDERING_START = 3; Int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200; // Video ready render int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200; Int MEDIA_INFO_BUFFERING_START = 701; // Start buffering int MEDIA_INFO_BUFFERING_END = 702; Int MEDIA_INFO_VIDEO_ROTATION_CHANGED = 10001; // Video selection information int MEDIA_ERROR_SERVER_DIED = 100; // Video interrupts. Generally, the video source is abnormal or the video type is not supported. Int MEDIA_ERROR_IJK_PLAYER = -10000,// MediaPlayer Error (-10000,0) Player internal errorCopy the code

F, some video when SeekTo, will drag the position before the jump, this is because the problem of key frames of video, popular is not compatible with FFMPEG, video compression is too severe, the seek only supports the key frames, this case is the original video file I frame is less, the player will get the latest key frames in the position of the drag, Currently, IJKPlayer has no solution.

You can obtain the download speed from getTcpSpeed of IjkMediaPlayer.

H. If hard decoding is enabled for high resolution, it will automatically switch to soft solution if it is not supported. Even if Mediacodec is enabled, if the device does not support it, the decoder displayed is also avCodec soft solution.

I, ijkMediaPlayer.setOption can be configured with the corresponding header file reference: ff_ffplay_options.

If (secProgress > 95) secProgress = 100; if (secProgress > 95) secProgress = 100;

IJK’s EXOPlayer and MediaPlayer are compatible, but they are not as good as IJK’s in terms of details, such as EXOPlayer: The problem of returning to the foreground and switching the rendering control’s black screen for a period of time is that I have found no other way but to use Seekto. This experience led me to choose IJKPlayer.

IjkPlayer public void setDataSource(String path, Map<String, String> headers) See ijkPlayer’s issues-1150, headers is converted internally using the same setOption method as issuses.

13. Ijkplayer FAQ and solutions

A, ijkPlayer plays RTMP live stream, delay is obvious – github.com/Bilibili/ij… B, full screen c, sometimes there will be a black screen when the live broadcast begins D, sometimes there will be a splintered screen E, set the decoding mode f, How to distinguish the live broadcast on demand G, whether to enable hardware acceleration H, How to set up only listen to the sound does not show video? – github.com/Bilibili/ij… J, The traffic speed is mostly depending on The quality of video CDN, Not player itself. k, how to mute and unmute system volume.There is no mute/unmute API in ijkplayer.l, video black screen, However, iJK only uses H264 decoding code m by default. Adaptation problems exist. For different CPU architectures, different so libraries need to be compiled

 cat game05.m3u8 | grep EXTINF | wc -l32 P, How to change the video quality? Video quality is determined when being encoded.I don't think it can be changed by player.Copy the code

Q, why does seek only support keyframes after dragging the progress bar forward? Seek only supports keyframes because there are few I frames in the original video file, so the player will look for the nearest keyframe in the position of dragging. R, how to change URL when ijkPlayer is playing RTMP video Create new player. s, how to add subtitle? If you want accurate subtitle time, you can perform parsing and time synchronization in native layer, and call back to Java layer when the time is up. Generally, subtitle file loading is done in Java layer, parse the file format, and then display according to the time interval. T, how to set the hard solution?

IjkMediaPlayer. SetOption (ijkMediaPlayer OPT_CATEGORY_PLAYER, "mediacodec", 1); ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,"http-detect-range-support", 0);
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "analyzeduration"."2000000");
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "probsize"."4096");
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 0);
Copy the code

U, HTTP redirects to RTMP /Https, ijkPlayer cannot play video

ijkMediaPlayer.setOption( IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_clear", 1);
Copy the code

V, Android mediaPlayer error (-38,0) prepare() This error occurs when mediaPlayer.getDuration() is called after mediaplayer.reset (). Methods like getDuration cannot be used without setting the data source for the mediaPlayer object. We need to check which method is used when setting MediaPlayer’s data source:

  • When MediaPlayer is initialized, set the data source using the create method. The mediaPlayer.prepare () method cannot be written, in which case an error is reported.
  • 2. If you initialize MediaPlayer using the MediaPlayer constructor and then set the datasource using the setDataSource method, you need to compile the datasource using the mediaPlayer.prepare () method before starting (). Can avoid the error (-38,0).

References:

  • Github.com/Bilibili/ij…
Welcome to pay attention to my wechat public number “code farming breakthrough”, audio and video, multimedia technology dry goods