Skip to content

Instantly share code, notes, and snippets.

@hoangnt2601
Last active September 14, 2022 01:44
Show Gist options
  • Select an option

  • Save hoangnt2601/79800418c61b0782592bd6e35f1cc265 to your computer and use it in GitHub Desktop.

Select an option

Save hoangnt2601/79800418c61b0782592bd6e35f1cc265 to your computer and use it in GitHub Desktop.
streamming
  1. GStreamer
  • Play video:
gst-launch-1.0 playbin uri=rtsp://...
gst-launch-1.0 rtspsrc location=rtsp://... latency=200 protocols=4 ! queue ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink
gst-launch-1.0 filesrc location=file.mp4 ! decodebin ! videoconvert ! autovideosink
  • Write image:
gst-launch-1.0 uridecodebin source::latency=200 uri=rtsp://... ! videoconvert ! queue ! videoconvert ! jpegenc ! multifilesink location=image_%06d.jpg
  • Record video:
1. gst-launch-1.0 -e rtspsrc location=rtsp://... protocols=tcp ! rtph264depay ! h264parse ! mp4mux ! filesink location=output.mp4

2. gst-launch-1.0 uridecodebin uri=rtsp://... ! 'video/x-raw,width=1920,height=1080,format=RGB,framerate=60/1' ! videoconvert ! queue ! videoconvert ! jpegenc ! filesink location=output.mp4

3. ffmpeg -rtsp_transport tcp -i rtsp://... -c:v copy -c:a aac video.mp4
  1. ffmpeg
  • Record video
ffmpeg -i rtsp://... -vcodec copy test.mp4
ffmpeg -rtsp_transport tcp -i rtsp://... -vcodec copy test.mp4
  • Fast speed
ffmpeg -i input.mp4 -filter:v "setpts=PTS/60" output.mp4
  • Cut video
ffmpeg -i video.mp4 -ss 01:06:56 -to 01:07:08 -c copy cut.mp4
  • Concat video
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
  • convert avi to mp4
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i video.avi -c:a mp2 -c:v h264_nvenc video.mp4
  1. vlc restream
1. Restream rtsp
vlc rtsp://... --sout='#transcode{vcodec=h264,scale=Auto,acodec=none,scodec=none}:rtp{sdp=rtsp://:8554/mystream}' --no-sout-all --sout-keep -Idummy

2. mp4 to rtsp
vlc file.mp4 --sout='#transcode{vcodec=h264,scale=Auto,acodec=none,scodec=none}:rtp{sdp=rtsp://:8554/mystream}' --no-sout-all --sout-keep --loop -Idummy
  1. ffmpeg restream
docker run --rm -it --network=host aler9/rtsp-simple-server

ffmpeg -re -stream_loop -1 -i cam1.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream
  1. h264 to h265
ffmpeg -i test.mp4 -c:v libx265 test2.mp4
  1. ERROR from element sink_encoder: Can not initialize x265 encoder.
ffmpeg -i ./20220321_15h-16h_p2.mp4 -vcodec h264 -acodec mp2 ./20220321_15h-16h_p2_.mp4
  1. decodebin0/GstMpegPSDemux:mpegpsdemux0: Internal data stream error.
ffmpeg -i video.mp4 -c:v copy -c:a aac video1.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment