Play the video from a path to browser. This will stream the video non stop, play pause is supported but since grpc is streaming video there is a challenge to handle seeking forward and backward explicitly. Typical HTTP video streaming protocols like HLS or DASH support this feature inherently by segmenting the video, which is not supported in this code.
protoc --go_out=. --go-grpc_out=. video_stream.proto
Ensure you have protoc installed. You can download it from the Protocol Buffers releases page.
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Run the protoc command again with the updated .proto file:
protoc --go_out=. --go-grpc_out=. -I=. video_stream.proto
protoc --go_out=. --go-grpc_out=. -I=. video_streaming.proto
- Temporary Environment Variable You can set an environment variable for the current terminal session by using the export command:
export VIDEO_FOLDER="/path/to/your/video/folder"
To set the environment variable permanently, you can add the export command to your shell configuration file (~/.bash_profile, ~/.zshrc, or ~/.bashrc depending on the shell you are using).
- Make the script executable:
chmod +x start_servers.sh
- Run the script: After setting the variable, you can run your script:
./start_servers.sh
-
Open PowerShell.
-
Temporary Environment Variable You can set an environment variable for the current PowerShell session by using the $env command:
$env:VIDEO_FOLDER = "D:\19\uploads"
To set the environment variable permanently, you can use the System Properties dialog or set it via PowerShell.
In Advanced system settings click on the Environment Variables button.
In the System variables section, click New to add a new environment variable.
Enter VIDEO_FOLDER as the variable name and D:\19\uploads
as the variable value.
Click OK to save the changes.
or Using PowerShell
[System.Environment]::SetEnvironmentVariable("VIDEO_FOLDER", "D:\19\uploads", "Machine")
- Run the script: After setting the variable, you can run your script:
.\start_servers.ps1
harish $ grpcurl -plaintext -d '{"video_name": "data1.mp4"}' localhost:50051 videostreaming.VideoStreamingService/StreamVideo
{
"content": "AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAA9ULbW9vdgAAAGxtdmhkAAAAAAAAAAAAAAAAAAAD6AAD4KgAAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAw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ABVrAAAVeAAAFZEAABWgAAAVsAAAFcAAABXSAAAV4QAAFjcAABZwAAAWgAAAFowAABaxAAAWwAAAFswAABbxAAAXAA=="
}
{...}
Breakdown of the command:
-plaintext
: Indicates that the server does not use TLS.
-d '{"video_name": "data1.mp4"}'
: The JSON payload sent to the StreamVideo RPC, where "video_name" should match the field name defined in the .proto file.
localhost:50051: The address of the gRPC server.
videostreaming.VideoStreamingService/StreamVideo: The full name of the RPC method in the VideoStreamingService.
harish $ grpcurl -plaintext localhost:50051 list
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
videostreaming.VideoStreamingService
harish $ grpcurl -plaintext localhost:50051 list videostreaming.VideoStreamingService
videostreaming.VideoStreamingService.ListVideos
videostreaming.VideoStreamingService.StreamVideo