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

SrsEncoder video reconfigure on fly #836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thegobot
Copy link
Contributor

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}

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
Copy link
Owner

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.

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

Successfully merging this pull request may close these issues.

None yet

2 participants