nginx-rtmp-module icon indicating copy to clipboard operation
nginx-rtmp-module copied to clipboard

[Feature Request] Support Rtmp MetaData as parameter on Application

Open ctaity opened this issue 8 years ago • 8 comments

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

ctaity avatar Nov 24 '17 23:11 ctaity

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.

matiaspl avatar Nov 25 '17 22:11 matiaspl

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 avatar Nov 25 '17 23:11 ctaity

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 &

ctaity avatar Nov 27 '17 17:11 ctaity

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" [email protected] 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 .

matiaspl avatar Nov 27 '17 20:11 matiaspl

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

ctaity avatar Nov 27 '17 22:11 ctaity

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.

ariselseng avatar Mar 26 '18 12:03 ariselseng

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 [email protected] 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 .

ctaity avatar Mar 26 '18 14:03 ctaity

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.

Fenrirthviti avatar Mar 26 '18 15:03 Fenrirthviti