A ffmpeg h.265 hardware issue - ffmpeg

Hi i have a ffmpeg hardware related problem.
Simply put: The conversion works on mac, but on some TV screens the converted h.265 video will give a few seconds of delay when it starts playing!
A response will be much appreciated!
Input:
UHD(3840x2160) Prores 422(HQ) master file
What we used to recompile to a 16bit renderer:
brew uninstall ffmpeg
brew uninstall x265
brew uninstall --force x265
brew install x265 --16-bit
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265
Code we used in FFMpeg:
-b:v 36000k -maxrate 38000k -c:v libx265 -pix_fmt yuv420p10le -x265-params "profile=main10:level=5.1:b=36000k" -c:a aac -strict experimental -b:a 256k
Preferred Output
3840x2160 resolution
10bit 4:2:0 colordepth
Main 10#L5.1#High format profile
MP4 container
HEVC codec
24p framerate
38Mb Variable bitrate
256Kb Variable bitrate/AAC audio
Output device is Tarakan UHD Stream Generator T7
Our problem:
The encode file that FFmpeg gives is correct, on spec level.
I would like the file to have a Main 10 High level 5.1 format profile.
Based on the specs I've put into FFmpeg, it automatically makes a file with a level 5.0 profile, as it doesn't need a higher level based on the specs.
The file plays correctly on a Mac.
The file must also play correctly on a Tarakan UHD Stream Generator(media player with multiple HDMI outputs). The file takes a while to load, chops off 5-6 seconds of the beginning of the film, then plays correctly.

I guess this might be an decoder performance issue.
First, the bitrate. 38Mbps, is very high so the decoding takes more time for the first several frames.
Second, 10 bit also increases the loading of the decoder.
You may add "-t fast-decode" to x265 for better decoding performance.

Related

ffmpeg h264_nvenc force level=41

I have some videos at 1080p 60fps.
These videos are with level=50 and my TV plays only videos up to level=41, so I want to convert my videos using ffmpeg and hardware acceleration.
I have a Windows 10 machine with ffmpeg and Geforce 2060, so I try run below command:
ffmpeg -i video.mp4 -vcodec h264_nvenc -preset slow -level 4.1 output.mp4
but I get this error:
[h264_nvenc # 000001dd43cd07c0] InitializeEncoder failed: invalid param (8): Invalid Level.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
When I try to run the same command above using "-level 4.2" or above, the encode process works! But it is useless for me, because I really need "-level 4.1".
I noticed that if use libx264 instead of h264_nvenc, the encode process accepts "-level 4.1", but it take too long to complete (I want to enjoy hardware acceleration instead of CPU).
How can I force h264_nvenc to accept "level=4.1" ?

get consistent 60fps while recording X screen with ffmpeg

I wrote the following script to record an X screen for a specified amount of time, to make sure that it's lossless I've separated it into two steps
record for the specified amount in a codec that requires almost no compression (so there's no overhead that might cause frames to be dropped)
re-encode the original video into HEVC to make the filesize significantly smaller
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -vsync 1 -f x11grab -probesize 128M -s 1920x1080 -r 60 -i :0.0 -qscale 0 -vcodec huffyuv -t 00:01:13 "$video.avi" # record the screen losslessly
ffmpeg -hwaccel cuvid -vsync 1 -i "$video.avi" -map 0:0 -c:v:0 hevc_nvenc -crf 23 -preset medium "$video-clean.mp4"
This works just like I expect it to some of the time, but very often it drops a lot of frames (I've seen as many as 10000 frames dropped on occasion)
The gpu is a 1080 TI that's being used just for rendering an X server with a chrome window and recording it, according to nvidia-smi the usage never goes to higher than 50% even in the most extreme cases.
I don't know what else to try, I thought about using a ramdisk to write the file to as it might be an IO problem, but ffmpeg refuses to write to tmpfs (for some reason I can't explain)
Solved it, recording to a tmpfs turned out to be the solution for me, however because I was using the snap version of ffmpeg I couldn't directly write to ram (because of permission issues), so I just compiled ffmpeg myself (needed support for cuda, and since this script runs on an ubuntu-based machine and the apt version of ffmpeg doesn't have access to cuda for some specific encoders I just compiled ffmpeg myself)

How encode video using hevc/h265 codec via ffmpeg OSX

I try to encode video using hevc codec
./ffmpeg -i 1234.mp4 -vcodec hevc_videotoolbox -vb 1000k -acodec aac -ab 192k -sn 2.mp4
error:
[hevc_videotoolbox # 0x7fc681813a00] Error: cannot create compression session: -12908
[hevc_videotoolbox # 0x7fc681813a00] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
i try change bitrate, width, height, error still exist
is it possible encode video on my macbook air 2015?
is videotoolbox can't use my old GPU and its possible on newest macbooks?
I have the same question recently, I found this when I was looking for answers:
Screenshot from this pdf: enter link description here
It's possible that old mac doesn't support HEVC hardware acceleration natively, I don't have a new mac to test if ffmpeg has anything related to it, maybe someone whose mac has 6th Gen CPU can help you address the problem.
Edit:
I tested following code on the latest 2018 mbp and it worked.
ffmpeg -i VIDEO_PATH -vcodec hevc_videotoolbox -tag:v hcv1 OUT_PATH
The size of the hevc_videotoolbox-encoded video#1 is smaller than the original test file(h264) but larger than libx265-encoded video#2 (using default parameters).
Unexpectedly, the quality of video#1 is much worse than that of the original, whereas video#2 seems untouched. Besides, hevc_videotoolbox doesn't support -crf option, so I'm still stick to libx265, even though it is really slow.

optimize hevc_toolbox encoding to look like x265 encoding in ffmeg

I am encoding videos from h264 to h265 using ffmpeg. First I used the x265 software version for a 30 sec movie clip reducing the file size from 18Mb to 2Mb and got the following still-frame result in 45 sec
Next I used the hevc_videotoolbox hardware accelerated version, first going from 18 to 1.6 Mb and the results were so poor I decided to up the bitrate to 1.5Mbit/s, thus getting a 5.7Mb file in 12 sec. However, the result is clearly inferior to the x265 version despite the almost 3x increase in filesize.
Any ideas if it is possible to improve the hevc_toolbox quality and still retain the speed advantage?
ffmpeg -i test.mp4 -an -c:v libx265 -vtag hvc1 -y test_x265.mp4
ffmpeg -i test.mp4 -an -c:v hevc_videotoolbox -vtag hvc1 -y -b:v 1.5M test_vt.mp4
I am on a MB pro late 2017 version with kaby lake
hevc_videotoolbox is hardware accelerated and because of that it will never be as efficient as x265. If you have the time I would recommend you using x265.

ffmpeg setting for HD and normal quality

Hello i need to have two versions of the same file stored on my server, medium and HD quality, the thing is that don't really know ffmpeg that well so im just trying this is code at random, i'm using the code belo but I end up with a much larger file, however it works,it plays.
ffmpeg -i inputfile.wmv -vcodec libx264 -ar 44100 -b 200 -ab 56 -crf 22 -s 360x288 -vpre medium -f flv tmp.flv
Just need the two commands to create the 2 different files
You need to give more information about what bitrate, quality or target file size you are aiming for and the size and quality of your source material preferably including codecs used and relevant parameters.
You should read the manual or ffmpeg -h or both. There are several problems with your command line:
You are using constant rate factor, crf = 22, while still trying to limit the bitrate using -b 200.
Bitrate is specified in bits/s (unless you are using a very old ffmpeg), and 200 bps is not usable for anything, add k to get kilobits/s.
You have not specified an audio codec, but you have specified an audio bitrate, ffmpeg will try to guess the audio codec for you but I don't know what codec is the default for .flv-files.
I'm assuming that the command line you posted is supposed to be for the 'medium' quality file.
Some suggestions that you can try:
Try this first: specify audio codec, e.g. -acodec libmp3lame, or if the audio is already in a good format you can just copy it without modification using -acodec copy
Try a different rate factor, e.g. -crf 30, higher numbers mean uglier picture quality, but also smaller file size.
Try a different encoder preset, e.g. -vpre slow, in general, the slower presets enable features that require more CPU cycles when encoding but results in a better picture quality, see x264 --fullhelp or this page to see what each preset contains.
Do a 2-pass encode, link.
If you don't want to read all the documentation for ffmpeg and the codec parameters that you need I suggest you look at this cheat sheet, although the command line switches have changed over the different versions of ffmpeg so the examples might not work.
An example command line:
ffmpeg -i inputfile.wmv -vcodec libx264 -crf 25 -s 360x288 -vpre veryslow -acodec libmp3lame -ar 44100 -ab 56k -f flv tmp.flv
The parameter -s [size] is the size of the output video, in pixels, for the HD file you probably want something around 1280x720, if your material is 5:4 ratio (as 360x288 is) you'll want to try 1280x1024, 960x768 or 900x720. Don't set a size larger than the source material as that will simply upscale the video and you will (probably) end up with a larger file without any noticeable improvement in quality. The -ab parameter is the audio bitrate, you'll probably want to increase this parameter on the HD version as well.

Resources