ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.32k stars 5.33k forks source link

The first few seconds of audio will be lost, only video without audio play #4151

Open jin19961220 opened 3 weeks ago

jin19961220 commented 3 weeks ago

!!! Before submitting a new bug report, please ensure you have searched for any existing bugs and utilized the Ask AI feature at https://ossrs.io or https://ossrs.net (for users in China). Duplicate issues or questions that are overly simple or already addressed in the documentation will be removed without any response.

Describe the bug the first few seconds of audio will be lost, only video without audio play

Version Develop branch

To Reproduce Steps to reproduce the behavior: The push stream code is as follows command = ( f'ffmpeg -re -f image2pipe -f rawvideo -pix_fmt rgb24 -s {self.inferenceVideoWith}x{self.inferenceVideoHeight} ' f'-r {self.audio_fps} -i - -i {self.currentAudioFilePathCycle} ' f'-c:v libx264 -c:a aac -filter:v scale=720:-1 -g 75 ' f'-preset ultrafast -crf 32 -shortest {self.rtmpStream}{curBranch} ' ) print(command) self.inferenceVideoProcess = run_subprocess(command, pipeIn=True)

        if curBranch == '01':
            curBranch = '02'
        elif curBranch == '02':
            curBranch = '01'
    # self.inferenceVideoProcess.stdin.write(abyte)
    try:
        self.inferenceVideoProcess.stdin.write(bytesVal)
        ## self.inferenceVideoProcess.stdin.flush()
    except Exception as e:
        print(f"Error writing to ffmpeg: {e}")

Expected behavior After a short video stream, the next push streaming audio and video can play normally

Screenshots

Additional context

jin19961220 commented 3 weeks ago

I stream through RTMP, pull through webrtc, when I stream to an RTMP address, this time I push the content audio time is too short, the next time the stream plays the first few seconds of audio will be lost, only video without audio play

jin19961220 commented 3 weeks ago

Audio less than 5s will cause the above problem

lvlinmufeng commented 2 weeks ago

Capture the desktop screen at a frame rate of 30 frames per second, with the top-left corner of the capture area starting at coordinates (0,0), and the capture resolution set to 1920x1080 pixels. Use the DirectShow input device to capture audio from the microphone named "麦克风 (2- HECATE GS02 GAMING SOUND CARD)". Encode the audio using the AAC codec, amplify the volume by a factor of 2.0, and encode the video using the libx264 codec with zero-latency tuning and an ultrafast preset for minimal delay. Apply a bitstream filter to convert H.264 NAL units to MP4 format Annex B, set the Group of Pictures (GOP) size to 15 frames with a minimum keyframe interval of 15 frames, use the baseline profile at level 3.0 for compatibility with simple decoding scenarios, and set the pixel format to YUV420p. Use the H.264 codec for video compression with a bitrate of 5000 kilobits per second. Output the stream in FLV format to an RTMP server at the address rtmp://192.168.2.95:1935/hls/stream95faadb0-5c22-4cfc-b3e9-d47eb8b428e9.

TRANS_BY_GPT4

lvlinmufeng commented 2 weeks ago

No sound

green-cats commented 1 week ago

++ if stream with webrtc video coming first and audio with delay

winlinvip commented 1 week ago

It appears to be an issue with FFmpeg? Is there also a problem when playing HTTP-FLV streams?

TRANS_BY_GPT4

green-cats commented 1 week ago

@winlinvip Hi, this is was solution https://github.com/ossrs/srs/issues/4076, now all works fine, can you add this fix please?