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" ?
Related
when i use
ffmpeg -i BabyShark.mp4 -c:v hevc_videotoolbox -b:v 6000k BabyShark1.mp4
it always returns an error like
[hevc_videotoolbox # 0x7fec79206e00] Error encoding frame: -12905
[hevc_videotoolbox # 0x7fec79206e00] popping: -542398533 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 [aac # 0x7fec79208a80] Qavg: 13693.864 [aac #
0x7fec79208a80] 2 frames left in the queue on closing Conversion
failed!
but
ffmpeg -i BabyShark1.mp4 -c:v h264_videotoolbox -b:v 6000k BabyShark2.mp4
works fine.
Other tutorials say that the above error is a problem of out-of-sync audio and video
But I changed a lot of videos, the error still appears, even the videos I recorded myself.
How can i fix it.
My computer model is MacBook Pro 2019
I want to use GPU to convert video to H265 encoding
Same problem with a computer using another M1 chip With GPU
I'm using ffmpeg to restream a live feed. Unfortunately occasionally the input resolution changes but ffmpeg continues running. The nginx rtmp server I'm using doesn't cope well with this, and continues the stream with audio, but the video is mostly black or green with some artifacts.
Ideally what I want to happen is for ffmpeg to stop on an input resolution change, as I have a script that detects ffmpeg stopping and will restart it again.
I'm using -c:v copy in my ffmpeg command as unfortunately my machine is not powerful enough to re-encode the live video on the fly to a constant resolution (not without a significant quality reduction at least)
ffmpeg -i "http://mpegts-live-stream" -c:v copy -c:a aac -ac 2 -f flv "rtmp://nginxserver/live/streamname"
So, ffmpeg can't detect input parameter change during streamcopy but we can work around that by adding a minimal decoding load to the process.
ffmpeg -xerror -skip_frame:v nokey -flags:v +drop_changed -i "http://mpegts-live-stream" -c:v copy -c:a aac -ac 2 -f flv "rtmp://nginxserver/live/streamname" -an -f null -
-xerror : exits upon error
-skip_frame:v nokey : only decodes keyframes of video stream
-flags:v +drop_changed : drops frame and signals error when parameters (like resolution) change
-an -f null - : maps a video output stream which needs a decoded stream, needed else no decoding will occur.
I'm trying to convert my library from various formats into HEVC 8-bit mainly to shrink my library down. This is generally working but I've run into an issue when trying to convert an existing file from 10-bit H.265 to 8-bit H.265.
My processor, an Intel Celeron J3455, supports hardware decoding/encoding H.265 at 8-bit but only hardware decoding for 10-bit.
It seems that ffmpeg is attempting to keep the video as 10-bit to match the source rather than allowing me to convert to 8-bit and this is creating an error.
Here is a sample command that I'm using:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.10bit.x265.mkv -map 0:0 -c:v:0 hevc_vaapi -vf "scale_vaapi=w=-1:h=1080" -b:v 4027047 -map 0:1 -c:a:0 aac -b:a 384000 -ac 6 -map 0:s -scodec copy -map_metadata:g -1 -metadata JBDONEVERSION=1 -metadata JBDONEDATE=2020-06-06T20:52:36.072Z -map_chapters 0 output.8bit.x265.mkv
The error I get is:
[hevc_vaapi # 0x5568b27fb1c0] No usable encoding entrypoint found for profile VAProfileHEVCMain10 (18).
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
From what I can tell ffmpeg looks at the source and selectes VAProfileHEVCMain10 instead of VAProfileHEVCMain. I'd like to force it to output 8-bit.
I've tried adding -pix_fmt yuv420p but that gives me this error:
Incompatible pixel format 'yuv420p' for codec 'hevc_vaapi', auto-selecting format 'vaapi_vld'
I've also tried making this change to the command: "scale_vaapi=w=-1:h=1080,format=yuv420p"
However that gives me the error:
Impossible to convert between the formats supported by the filter 'Parsed_scale_vaapi_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Any suggestions?
I've just been figuring this out as well. Your problem is (most likely) with -hwaccel_output_format vaapi. It's outputting frames in VAAPI format and not the format you need (read more here, also quoted a section at the end of this comment). So you need to adjust for 8-bit there: -hwaccel_output_format yuv420p.
In my case I'm also using -filter_hw_device vaapi0 -vf format=nv12|vaapi,hwupload (specified before -c:v hevc_vaapi). The vaapi0 here is a named device I've initialised with init_hw_device. You're directly using a path with -hwaccel_device so I'm not sure what the name of your device is, but you may not need these extra arguments.
The hardware codecs used by VAAPI are not able to access frame data in arbitrary memory. Therefore, all frame data needs to be uploaded to hardware surfaces connected to the appropriate device before being used. All VAAPI hardware surfaces in ffmpeg are represented by the vaapi pixfmt (the internal layout is not visible here, though).
The hwaccel decoders normally output frames in the associated hardware format, but by default the ffmpeg utility download the output frames to normal memory before passing them to the next component. This allows the decoder to work standlone to make decoding faster without any additional options:
ffmpeg -hwaccel vaapi ... -i input.mp4 -c:v libx264 ... output.mp4
For other outputs, the option -hwaccel_output_format can be used to specify the format to be used. This can be a software format (which formats are usable depends on the driver), or it can be the vaapi hardware format to indicate that the surface should not be downloaded.
I've been testing different parameters to capture my desktop video and audio (desktop audio, not mic) and I find that no matter what settings I have, the resulting webm file's framerate is around 5fps and is horribly inconsistent. It starts at around 20fps and slowly drops over time until about 4-5fps. I'm not really sure what I'm doing wrong, but here is the basic command I'm using:
ffmpeg -y -video_size 1920x1080 -f gdigrab -framerate 60 -i desktop -c:v libvpx-vp9 -acodec libvorbis -c:a libopus -b:v 2M -threads 4 output.webm
I've tried anywhere between 30-60 fps and tested different bitrates but nothing seems to affect the output framerate.
Also, I know that acodec and c:a are for audio but I'm not sure how to specify the audio device to use.
So my issues are horrible framerate for webm and how to include desktop audio in the recording.
You can use arecord and pipe it through stdout and ffmpeg can read it from stdin.
aplay piping to arecord using a file instead of stdin and stdout
Replacing the aplay command with your ffmpeg. Dont forget to add '-i -' in ffmpeg.
A doubt: why are you defining audio encoder two times?
It's impossible to say why the video frame rate is low from the question. It can be an issue with encoder. Or issue in reading input. Remove the video encoding option. See if the issue persists. If it's working fine, try some other encoders.
Use -c:v libx264 instead of -c:v libvpx-vp9. libvpx-vp9's realtime encoding quality is really bad, even regular libvpx (i.e. VP8) is much better. If you insist on using libvpx, use options like -deadline realtime and -cpu-used -4
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.