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

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

Open
jin19961220 opened this issue Aug 22, 2024 · 8 comments

Comments

@jin19961220
Copy link

!!! 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
Copy link
Author

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

Audio less than 5s will cause the above problem

@lvlinmufeng
Copy link

lvlinmufeng commented Aug 26, 2024

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

No sound

@green-cats
Copy link

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

@winlinvip
Copy link
Member

winlinvip commented Sep 2, 2024

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

TRANS_BY_GPT4

@green-cats
Copy link

green-cats commented Sep 3, 2024

@winlinvip Hi, this is was solution #4076, now all works fine, can you add this fix please?

@green-cats
Copy link

@winlinvip will this fix included in v6?

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

No branches or pull requests

4 participants