srs icon indicating copy to clipboard operation
srs copied to clipboard

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

Open jin19961220 opened this issue 1 year ago • 8 comments

!!! 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 avatar Aug 22 '24 04:08 jin19961220

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 avatar Aug 22 '24 04:08 jin19961220

Audio less than 5s will cause the above problem

jin19961220 avatar Aug 22 '24 10:08 jin19961220

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 avatar Aug 26 '24 10:08 lvlinmufeng

No sound

lvlinmufeng avatar Aug 26 '24 10:08 lvlinmufeng

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

green-cats avatar Sep 01 '24 11:09 green-cats

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

TRANS_BY_GPT4

winlinvip avatar Sep 02 '24 12:09 winlinvip

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

green-cats avatar Sep 03 '24 04:09 green-cats

@winlinvip will this fix included in v6?

green-cats avatar Sep 29 '24 03:09 green-cats