begeekmyfriend / yasea

RTMP live streaming client for Android
MIT License
4.86k stars 1.32k forks source link

SrsEncoder video reconfigure on fly #836

Open thegobot opened 2 years ago

thegobot commented 2 years ago

If you reset MediaCodec in the middle of the stream, then the video freezes (artifacts) in the players. After the experiments, I seem to understand what the reason is. Not all predicred frames have time to be sent to the stream (the encoder stops). Therefore, first we complete the sending of all P-frames (this is signaled by the MediaCodec.BUFFER_FLAG_KEY_FRAME), then we reconfigure the encoder with new parameters.

Tested in latest Chrome and FF. The video now changes format and continues to play

Perhaps you will have other thoughts about this. Please give comments

ChunkDemuxer Selected FFmpegAudioDecoder for audio decoding, config: codec: aac, profile: unknown, bytes_per_channel: 2, channel_layout: STEREO, channels: 2, samples_per_second: 44100, sample_format: Signed 16-bit, bytes_per_frame: 4, seek_preroll: 0us, codec_delay: 0, has extra data: false, encryption scheme: Unencrypted, discard decoder delay: false, target_output_channel_layout: STEREO, has aac extra data: true Video rendering in low delay mode. Failed to initialize DecryptingVideoDecoder Effective playback rate changed from 0 to 1 Starting Initialization of DXVAVDA Using D3D9 device for DXVA Selected VDAVideoDecoder for video decoding, config: codec: h264, profile: h264 baseline, level: not available, alpha_mode: is_opaque, coded size: [480,640], visible rect: [0,0,480,640], natural size: [480,640], has extra data: false, encryption scheme: Unencrypted, rotation: 0°, flipped: 0, color space: {primaries:BT709, transfer:BT709, matrix:BT709, range:LIMITED} video decoder config changed midstream, new config: codec: h264, profile: h264 baseline, level: not available, alpha_mode: is_opaque, coded size: [1080,1920], visible rect: [0,0,1080,1920], natural size: [1080,1920], has extra data: false, encryption scheme: Unencrypted, rotation: 0°, flipped: 0, color space: {primaries:BT709, transfer:BT709, matrix:BT709, range:LIMITED} Failed to initialize VDAVideoDecoder Failed to initialize DecryptingVideoDecoder Failed to initialize VDAVideoDecoder Failed to initialize VpxVideoDecoder Failed to initialize Dav1dVideoDecoder Selected FFmpegVideoDecoder for video decoding, config: codec: h264, profile: h264 baseline, level: not available, alpha_mode: is_opaque, coded size: [1080,1920], visible rect: [0,0,1080,1920], natural size: [1080,1920], has extra data: false, encryption scheme: Unencrypted, rotation: 0°, flipped: 0, color space: {primaries:BT709, transfer:BT709, matrix:BT709, range:LIMITED}

begeekmyfriend commented 2 years ago

I am afraid I am not sure whether shall I pick your commit into this project since there are other users using it. Maybe it is better you keep this feature for your own project.