Skip to content

Commit

Permalink
change resolution on fly
Browse files Browse the repository at this point in the history
It is also necessary to send the SPS\PPS along with the keyframe, in addition to the AVCSequenceHeader

Now all players do not freeze and change resolution anywhere in the stream!
Tested: PotPlayer, MPC (hard accel\soft), Chrome, Forefox, FFplay (also with h264_qsv decoder)

See
begeekmyfriend#832
  • Loading branch information
thegobot authored Nov 28, 2021
1 parent 7f6312a commit db7eba4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions library/src/main/java/net/ossrs/yasea/SrsFlvMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ private class SrsFlv {
private ByteBuffer h264_pps;
private boolean h264_pps_changed;
private boolean h264_sps_pps_sent;
private boolean h264_sps_pps_changed;
private boolean aac_specific_config_got;

public SrsFlv() {
Expand All @@ -721,6 +722,7 @@ public void reset() {
h264_sps_changed = false;
h264_pps_changed = false;
h264_sps_pps_sent = false;
h264_sps_pps_changed = false;
aac_specific_config_got = false;
if (null != h264_sps){
Arrays.fill(h264_sps.array(),(byte) 0x00);
Expand Down Expand Up @@ -896,12 +898,32 @@ public void writeVideoSample(final ByteBuffer bb, MediaCodec.BufferInfo bi) {
frame_pps.data.get(pps);
h264_pps_changed = true;
h264_pps = ByteBuffer.wrap(pps);
//writeH264SpsPps(dts, pts);
}


if(h264_sps_changed || h264_pps_changed){
writeH264SpsPps(dts, pts);
h264_sps_pps_changed = true;
}

return;
} else if (nal_unit_type != SrsAvcNaluType.NonIDR) {
return;
}

if(type == SrsCodecVideoAVCFrame.KeyFrame && h264_sps_pps_changed ){
//prepend SPS\PPS to IDR
SrsFlvFrameBytes sps_frame = new SrsFlvFrameBytes(h264_sps);
SrsFlvFrameBytes pps_frame = new SrsFlvFrameBytes(h264_pps);

ipbs.add(avc.muxNaluHeader(sps_frame));
ipbs.add(sps_frame);
ipbs.add(avc.muxNaluHeader(pps_frame));
ipbs.add(pps_frame);
h264_sps_pps_changed = false;
Log.i(TAG, String.format("prepend key frame SPS/PPS. DTS: %d, SPS/PPS size: %d/%d, IDR size: %d", dts, sps_frame.size, pps_frame.size, frame.size));
}

ipbs.add(avc.muxNaluHeader(frame));
ipbs.add(frame);
Expand Down

0 comments on commit db7eba4

Please sign in to comment.