sergey-dryabzhinsky / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
1.02k stars 216 forks source link

[Feature Request] Support Rtmp MetaData as parameter on Application #258

Open ctaity opened 6 years ago

ctaity commented 6 years ago

if useful can access framerate and resolution of rtmp signal. With this parameters the gop size of hls and resolutions can be dynamic example:

if(resolution=720) do 720 do 480 do 360

if(resolution=1080) do 1080 do 720 do 480 do 360

and cand adjust -g (gop) parameter of ffmpeg to generate keyframes. exmaple -g $framerate * 2

matiaspl commented 6 years ago

I highly doubt you'd ever really want to adjust the GOP length like this. It's better to force intra frame placement because you can directly tie that to the FPS value of the incoming stream. Use: -force_key_frames expr:gte(t,n_forced*GOP_LEN_IN_SECONDS) in your ffmpeg line/script.

ctaity commented 6 years ago

force key frames dont work with h264_nvenc only work if i force generate idr frames, but mobile phones dont like idr frames on flowplayer . Only -g gop alternative.

ffmpeg -v verbose -i granito.mp4 -vcodec h264_nvenc -zerolatency 1 -gpu 0 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq -maxrate 500k -bufsize 1m -force_key_frames "expr:gte(t,n_forced*2)" -vf scale=-2:360 -acodec aac -ar 22050 -b:a 64k -hls_time 10 -hls_list_size 0 -f hls index.m3u8

ctaity commented 6 years ago

For now i using script:

#!/bin/bash

on_die () {
    # kill all children
    pkill -KILL -P $$
}
trap 'on_die' TERM

FR="$(mediainfo --Inform='Video;%FrameRate%' rtmp://localhost/video-1080/$1)";
GOP=$(bc <<< "$FR * 2")

/usr/bin/ffmpeg -v verbose -i rtmp://localhost/video-1080/$1 \
              -vcodec h264_nvenc -zerolatency 1 -gpu 0 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq  -maxrate 500k -bufsize 1m -g $GOP  -vf scale=-2:360  -acodec aac -ar 22050   -b:a 64k   -f flv rtmp://localhost/hls-video/$1_360 \
              -vcodec h264_nvenc -zerolatency 1 -gpu 1 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq  -maxrate 1M -bufsize 2M   -g $GOP  -vf scale=-2:480  -acodec aac -ar 22050  -b:a 96k   -f flv rtmp://localhost/hls-video/$1_480 \
              -vcodec h264_nvenc -zerolatency 1 -gpu 0 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq  -maxrate 2M -bufsize 4M   -g $GOP  -vf scale=-2:720  -acodec aac -ar 22050   -b:a 128k  -f flv rtmp://localhost/hls-video/$1_720 \
              -vcodec h264_nvenc -zerolatency 1 -gpu 1 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq  -maxrate 3M -bufsize 6M   -g $GOP  -vf scale=-2:1080 -acodec aac -ar 22050  -b:a 128k -f flv rtmp://localhost/hls-video/$1_1080 &
matiaspl commented 6 years ago

Do you get better quality compared to libx264? The rumour has it that hw gpgpu encoders produce worse quality video compared to x264 at the same bitrate even at veryhigh preset.

Matt

27.11.2017 18:46 "ctaity" notifications@github.com napisał(a):

For now i using script:

!/bin/bash

on_die () {

kill all children

pkill -KILL -P $$ } trap 'on_die' TERM

FR="$(mediainfo --Inform='Video;%FrameRate%' rtmp://localhost/video-1080/$ 1)"; GOP=$(bc <<< "$FR * 2")

/usr/bin/ffmpeg -v verbose -i rtmp://localhost/video-1080/$1 -vcodec h264_nvenc -zerolatency 1 -gpu 0 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq -maxrate 500k -bufsize 1m -g $GOP -vf scale=-2:360 -acodec aac -ar 22050 -b:a 64k -f flv rtmp://localhost/hls-video/$1_360 -vcodec h264_nvenc -zerolatency 1 -gpu 1 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq -maxrate 1M -bufsize 2M -g $GOP -vf scale=-2:480 -acodec aac -ar 22050 -b:a 96k -f flv rtmp://localhost/hls-video/$1_480 -vcodec h264_nvenc -zerolatency 1 -gpu 0 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq -maxrate 2M -bufsize 4M -g $GOP -vf scale=-2:720 -acodec aac -ar 22050 -b:a 128k -f flv rtmp://localhost/hls-video/$1_720 -vcodec h264_nvenc -zerolatency 1 -gpu 1 -profile:v main -level 4.2 -preset llhq -bf:v 2 -rc vbr_hq -maxrate 3M -bufsize 6M -g $GOP -vf scale=-2:1080 -acodec aac -ar 22050 -b:a 128k -f flv rtmp://localhost/hls-video/$1_1080 &

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/issues/258#issuecomment-347264339, or mute the thread https://github.com/notifications/unsubscribe-auth/AB049kkaD1WppellezIYXvqOAEjLm08Rks5s6vVigaJpZM4QqOv2 .

ctaity commented 6 years ago

I get good quality, but 10x faster with 2 quadro cpu.

ariselseng commented 6 years ago

In my tests with a gtx 770, the visual quality is a bit worse for nvidia vs libx264 at the same encoding speed (adjusted presets to make it about the same speed), but with nvidia the cpu is almost idle. But for absolute best picture, libx264 crushes gpu encoding.

ctaity commented 6 years ago

Thath depende ffmpeg cuda parameters, i think, i use this and quality is good.

!/bin/bash

on_die () {

kill all children

pkill -KILL -P $$

}

trap 'on_die' TERM

THUMBS="/mnt/disk2/hls/thumbs/$1"

FR="$(mediainfo --Inform='Video;%FrameRate%' rtmp://localhost/video-1080/$1)"; GOP=$(bc <<< "$FR * 2")

AC="libfdk_aac"

AC="aac"

AC="copy"

PRESET="llhq"

PRESET="slow"

PROFILE="high" LEVEL="4.2" RC="vbr_hq"

RC="vbr_hq"

mkdir -p "$THUMBS"

echo $THUMBS >> /var/log/nginx/ff-$1.log

/usr/bin/ffmpeg -hwaccel cuvid -c:v h264_cuvid -deint 1 -drop_second_field 1 -i rtmp://localhost/video-1080/$1 \ -vcodec h264_nvenc -zerolatency 1 -profile:v $PROFILE -level $LEVEL -preset $PRESET -bf:v 2 -rc $RC -maxrate 300k -bufsize 300k -g $GOP -vf scale_npp=w=-2:h=240 -acodec $AC -ac 2 -f flv rtmp://localhost/hls-video/$1_240 \ -vcodec h264_nvenc -zerolatency 1 -profile:v $PROFILE -level $LEVEL -preset $PRESET -bf:v 2 -rc $RC -maxrate 500k -bufsize 500k -g $GOP -vf scale_npp=w=-2:h=360 -acodec $AC -ac 2 -f flv rtmp://localhost/hls-video/$1_360 \ -vcodec h264_nvenc -zerolatency 1 -profile:v $PROFILE -level $LEVEL -preset $PRESET -bf:v 2 -rc $RC -maxrate 1M -bufsize 1M -g $GOP -vf scale_npp=w=-2:h=480 -acodec $AC -ac 2 -f flv rtmp://localhost/hls-video/$1_480 \ -vcodec h264_nvenc -zerolatency 1 -profile:v $PROFILE -level $LEVEL -preset $PRESET -bf:v 2 -rc $RC -maxrate 2M -bufsize 2M -g $GOP -vf scale_npp=w=-2:h=720 -acodec $AC -ac 2 -f flv rtmp://localhost/hls-video/$1_720 \ -vcodec h264_nvenc -zerolatency 1 -profile:v $PROFILE -level $LEVEL -preset $PRESET -bf:v 2 -rc $RC -maxrate 3M -bufsize 3M -g $GOP -vf scale_npp=w=-2:h=1080 -acodec $AC -ac 2 -f flv rtmp://localhost/hls-video/$1_1080 2>/var/log/nginx/ff-$1.log

-vcodec mjpeg -an -filter:v

fps=1/5,scale_npp=w=-2:h=144:interp_algo=lanczos,hwdownload,format=nv12 -f image2 "$THUMBS/thumb-%d.jpg" 2>/var/log/nginx/ff-$1.log

wait

On Mon, Mar 26, 2018 at 9:04 AM, Ari notifications@github.com wrote:

In my tests with a gtx 770, the visual quality is a bit worse for nvidia vs libx264 at the same encoding speed (adjusted presets to make it about the same speed), but with nvidia the cpu is almost idle. But for absolute best picture, libx264 crushes gpu encoding.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/issues/258#issuecomment-376142652, or mute the thread https://github.com/notifications/unsubscribe-auth/AE93tgkFaboehO3edi4HIFdE3W2J11jUks5tiNlcgaJpZM4QqOv2 .

Fenrirthviti commented 6 years ago

NVENC quality is more closely tied to the generation of GPU you're using. NVENC on a 10-series GPU is roughly equivalent to x264 at the veryfast preset. Older versions of NVENC have significantly worse quality by comparison.