A small set of FFmpeg commands covers most of the transcoding and streaming tasks that come up in practice. They are not exhaustive—just the invocations that tend to be reused. One useful detail: most of the HLS playlist commands below become live push commands once you add -re, which tells FFmpeg to read the input at its native frame rate.
Transcoding
H.264 to MP4
$ ffmpeg -i "input.h264" -c:v copy -f mp4 "output.mp4"
MP4 to TS
$ ffmpeg -i faded.mp4 -c copy -vbsf h264_mp4toannexb faded.ts
Splitting a TS file into segments
$ ffmpeg -i faded.ts -c copy -map 0 -f segment -segment_list playlist.m3u8 -segment_time 5 output%03d.ts
MP4 to an HLS playlist (MPEG-TS segments)
$ ffmpeg -i faded.mp4 -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls playlist.m3u8
MP4 to an HLS playlist (FMP4 segments)
$ ffmpeg -i faded.mp4 -f hls -hls_segment_type fmp4 -hls_time 10 -report playlist.m3u8
Adding -hls_flags single_file produces a single-file playlist with byte-range offsets instead of separate segment files:
$ ffmpeg -i faded.mp4 -f hls -hls_segment_type fmp4 -hls_time 10 -report -hls_flags single_file playlist.m3u8
Streaming
Listen on a UDP port and republish as HLS
If the incoming video is H.264 or H.265 and the audio is AAC, the stream can be passed through directly:
$ ffmpeg -i udp://127.0.0.1:10000 -c copy -f hls playlist.m3u8
Otherwise, transcode first:
$ ffmpeg -i udp://127.0.0.1:10000 -c:v x264 -c:a aac -f hls playlist.m3u8
Push an MP4 file over UDP as an MPEG-TS stream
This command sends the stream; the previous command can listen on the address and republish it.
$ ffmpeg -re -i faded.mp4 -codec copy -bsf:v h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316
Push an MP4 file over UDP as an RTSP stream
$ ffmpeg -re -i faded.mp4 -rtsp_transport tcp -vcodec h264 -f rtsp rtsp://192.168.3.4/test
Push an H.264 file to an RTMP server
$ ffmpeg -re -i hik.h264 -c copy -f flv rtmp://192.168.3.4/live/fromh264
Cameras
Restream a Hikvision RTSP feed to an RTMP server
$ ffmpeg -rtsp_transport tcp -i rtsp://username:[email protected]:554/h264/ch1/main/av_stream -vcodec copy -acodec copy -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 -f flv rtmp://192.168.3.4/live/fromrtsp
Hikvision RTSP URLs follow this pattern. Main stream:
rtsp://admin:[email protected]:554/h264/ch1/main/av_stream
rtsp://admin:[email protected]:554/mpeg-4/ch1/main/av_stream
Sub stream:
rtsp://admin:[email protected]/h264/ch1/sub/av_stream
rtsp://admin:[email protected]/h264/mpeg-4/sub/av_stream