whitphx / streamlit-webrtc

Real-time video and audio processing on Streamlit
https://discuss.streamlit.io/t/new-component-streamlit-webrtc-a-new-way-to-deal-with-real-time-media-streams/8669
MIT License
1.41k stars 189 forks source link

webrtc_streamer - does not save audio and does not display video #1208

Closed DmitryRyumin closed 1 year ago

DmitryRyumin commented 1 year ago

I have such a problem. There is a code:

from streamlit_webrtc import webrtc_streamer, WebRtcMode

from aiortc.contrib.media import MediaRecorder

def recorder_factory():
    return MediaRecorder("test.mp4")

streamer = webrtc_streamer(
    key="rec_streamer",
    mode=WebRtcMode.SENDONLY,
    rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
    media_stream_constraints={"video": True, "audio": True},
    in_recorder_factory=recorder_factory,
)

At the output, I need to display the video so that it can be seen and write to 1 video file with an audio track. If possible, an example of such work. I would be very grateful.

whitphx commented 1 year ago

For displaying the video, just replace WebRtcMode.SENDONLY with WebRtcMode.SENDRECV.

I also confirmed that the audio track was successfully recorded with this code in my environment.

DmitryRyumin commented 1 year ago

For displaying the video, just replace WebRtcMode.SENDONLY with WebRtcMode.SENDRECV.

I also confirmed that the audio track was successfully recorded with this code in my environment.

Thanks for the answer! This did start the stream, however now while recording I get an mp4 output file where the audio is recorded and the video is displayed for the first few seconds and then the video freezes and the audio goes on. The output has this message:

[libx264 @ 0x7fc4ef045f00] non-strictly-monotonic PTS
[mp4 @ 0x7fc4f01ddbc0] Application provided invalid, non monotonically increasing dts to muxer in stream 1: -512 >= -512
Spisor commented 5 months ago

For displaying the video, just replace WebRtcMode.SENDONLY with WebRtcMode.SENDRECV. I also confirmed that the audio track was successfully recorded with this code in my environment.

Thanks for the answer! This did start the stream, however now while recording I get an mp4 output file where the audio is recorded and the video is displayed for the first few seconds and then the video freezes and the audio goes on. The output has this message:

[libx264 @ 0x7fc4ef045f00] non-strictly-monotonic PTS
[mp4 @ 0x7fc4f01ddbc0] Application provided invalid, non monotonically increasing dts to muxer in stream 1: -512 >= -512

@DmitryRyumin did you manage to solve this? I am facing the same issue

it looks like an aiortc thing, but i haven't find a solution for this yet