Skip to content

Instantly share code, notes, and snippets.

View Koulil77's full-sized avatar

syfTec Koulil77

View GitHub Profile
@Koulil77
Koulil77 / ffmpeg-multi-instances-xargs.md
Created October 14, 2017 06:55 — forked from Brainiarc7/ffmpeg-multi-instances-xargs.md
This gist will show you how to launch multiple ffmpeg instances with xargs, very useful for NVIDIA NVENC based encoding where standard GPUs limit the maximum simultaneous encode sessions to two.

Spawning multiple ffmpeg processes with xargs:

On standard NVIDIA GPUs (Not the Quadros and Tesla lines), NVENC encodes are limited to two simultaneous sessions. The sample below illustrates how to pass a list of AVI files to ffmpeg and encode them to HEVC on two encode sessions:

$ find Videos/ -type f -name \*.avi -print | sed 's/.avi$//' |\
  xargs -n 1 -I@ -P 2 ffmpeg -i "@.avi" -c:a aac -c:v hevc_nvenc "@.mp4"

This will find all files with the ending .avi in the directory Videos/ and transcode them into HEVC/H265+AAC files with the ending .mp4. The noteworthy part here is the -P 2 to xargs, which starts up to two processes in parallel.

@Koulil77
Koulil77 / ffmpeg-hevc-encode-nvenc.md
Created October 14, 2017 06:54
This gist shows you how to encode specifically to HEVC with ffmpeg's NVENC on supported hardware, with a two-pass profile and optional CUVID-based hardware-accelerated decoding.

Encoding high-quality HEVC content with FFmpeg - based NVENC encoder on supported hardware:

If you've built ffmpeg as instructed here on Linux and the ffmpeg binary is in your path, you can do fast HEVC encodes as shown below, using NVIDIA's NPP's libraries to vastly speed up the process.

Now, to do a simple NVENC encode in 1080p, (that will even work for Maxwell Gen 2 (GM200x) series), start with:

ffmpeg  -i <inputfile>  \
-filter:v hwupload_cuda,scale_npp=w=1920:h=1080:format=nv12:interp_algo=lanczos,hwdownload \

-c:v hevc_nvenc -profile main -preset slow -rc vbr_hq \

@Koulil77
Koulil77 / hls_to_sdi.sh
Created October 9, 2017 14:13 — forked from max-verem/hls_to_sdi.sh
hls to sdi
#!/bin/bash
ffmpeg \
-i "http://live.m2.tv:80/hls/stream.m3u8" \
-vf "scale=720:576,fps=fps=25,setdar=dar=16/9,format=pix_fmts=uyvy422" \
-af "aresample=48000" -ac 2 \
-f decklink -y "DeckLink Mini Monitor" \
-acodec copy -vcodec copy \
-f mpegts \
-y "udp://239.1.100.2:10480?localaddr=10.1.5.57&pkt_size=1316&fifo_size=1000000" \
@Koulil77
Koulil77 / getgop.sh
Created May 13, 2017 10:21 — forked from ddennedy/getgop.sh
display the GOP structure of a video file (requires ffprobe)
#!/bin/sh
startswith() { case $1 in $2*) true;; *) false;; esac; }
ffprobe_output=$( ffprobe -show_frames "$1" 2>&1 )
GOP=1
maxGOP=1
Bframes=0
M=0
@Koulil77
Koulil77 / dash-avc264 command lines
Created May 13, 2017 10:20 — forked from ddennedy/dash-avc264 command lines
Use ffmpeg and mp4box to prepare DASH-AVC/264 v1.0 VoD
See my DASH-IF presentation from October, 2014:
https://s3.amazonaws.com/misc.meltymedia/dash-if-reveal/index.html#/
1. encode multiple bitrates with keyframe alignment:
ffmpeg -i ~/Movies/5D2_Portrait.MOV -s 1280x720 -c:v libx264 -b:v 1450k -bf 2 \
-g 90 -sc_threshold 0 -c:a aac -strict experimental -b:a 96k -ar 32000 out.mp4
My input was 30 fps = 3000 ms. If it were 29.97, then a GOP size of 90 frames will yield a base segment
size of 3003 milliseconds. You can make the segment size some multiple of this, e.g.: 6006, 9009, 12012.
@Koulil77
Koulil77 / SDI2-SD-qsv.sh
Created May 12, 2017 10:14 — forked from max-verem/SDI2-SD-qsv.sh
Produce live streams with decklink sdi input and intel's h264 codec
#!/bin/bash
D1="[f=hls:hls_flags=delete_segments:hls_list_size=10:hls_time=20]/var/www/html/hls2/stream.m3u8"
D2="[f=mpegts]udp://239.1.1.2:10480?localaddr=10.1.5.99&pkt_size=1316&fifo_size=1000000"
D3="[f=dash:window_size=5:extra_window_size=5:remove_at_exit=1]/var/www/html/dash2/stream.mpd"
ffmpeg \
-v verbose \
-f decklink -i "DeckLink SDI (2)@3" \
-vcodec h264_qsv -a53cc 0 \
@Koulil77
Koulil77 / dash2.html
Created May 12, 2017 10:13 — forked from max-verem/dash2.html
Dash player sample
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="content-type" content="text/html;">
<meta name="viewport" content="initial-scale=1.0 maximum-scale=1.0 user-scalable=no">
<title>M2</title>
<meta name="description" content="M2" />
<meta name="keywords" content="" />
<meta name="robots" content="index, nofollow" />
@Koulil77
Koulil77 / hls2.html
Created May 12, 2017 10:13 — forked from max-verem/hls2.html
HLS playback sample
<html>
<head>
<style>
body {
width: 982px;
margin: 50px auto;
}
</style>