When I use the hevc_videotoolbox encoder in ffmpeg it always prompts me the same error - macos

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

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" ?

FFMPEG Input area failure

I'm trying to convert an input clip to a fixed, padded output and applying an overlay on it.
This command works fine for resizing:
ffmpeg -y -i clip.mp4 -vf scale="min(iw*375/ih\,500):min(375\,ih*500/iw),pad=500:375:(500-iw)/2:(375- ih)/2" output.mp4
I created the following one to make sure the overlay would be created:
ffmpeg -y -i clip.mp4 -i clip_overlay.png -strict -2 -filter_complex "[0]scale=min(iw*375/ih\,500):min(375\,ih*500/iw),pad=500:375:(500-iw)/2:(375-ih)/2[v];[v][1]overlay=x=W-w-5:y=H-h-5" output.mp4
I cannot find the error, but ffmpeg returns:
[Parsed_pad_1 # 0x2eae8e0] Input area 144:0:355:375 not within the padded area 0:0:500:374 or zero-sized
[Parsed_pad_1 # 0x2eae8e0] Failed to configure input pad on Parsed_pad_1
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #1:0
[aac # 0x2eb3020] Qavg: 102.113
[aac # 0x2eb3020] 2 frames left in the queue on closing
Why does that upper command work, and combined with the second one, it doesn't?
The most common pixel format in a typical MP4 video stream is yuv420p and the default encoder (x264) requires that the dimensions be even.
So, set pad to use even dimensions,
ffmpeg -y -i clip.mp4 -i clip_overlay.png -strict -2 -filter_complex "[0]scale=min(iw*375/ih\,500):min(375\,ih*500/iw),pad=500:376:(500-iw)/2:(376-ih)/2[v];[v][1]overlay=x=W-w-5:y=H-h-5" output.mp4

Invalid key_frame(I) and P- frame sequence in h264 Binary stream

I am getting video from USB webcam and encoding into h.264 raw stream as follows...
ffmpeg.exe -f dshow -rtbufsize 200M -i video="Logitech HD Webcam C270" -vcodec libx264 -preset ultrafast -tune zerolatency -g 30 -s 480x640 -buf
size:v 50M output.h264
I am expecting 1-Key frame and 29-P Frame(with SPS/PPS) in output.h264 stream.But I am not getting the expected result.However video is playing fine.
I tried to get Metadata of same file using ffprob ..
ffprobe -show_frames videofilename.h264 > outputlogfile.txt
Here I can see proper sequence 1-Key frame and 29-P frames.But if we open h264 file in binary reader(I am using HDX) I can see Key/P frames not in proper sequence.
You can download h264 sample and ffprob logs from below links.
https://www.dropbox.com/s/3ghpkqdc36wdgxr/TimerSample.h264?dl=0
https://www.dropbox.com/s/gdn64004o0udrfk/TimerSample.txt?dl=0
You can find binary sequence of same file from here (filtered by start code)
Please let me know whether i am missing some filter. Thank you.
The highlighted elements in the screenshot show that the bitstream begins with a SPS unit, then a PPS unit, then a SEI unit, followed by slices of an IDR picture, then non-reference picture slices. This is all normal and expected.
Use
ffmpeg -i videofilename.h264 -c copy -bsf:v trace_headers -f null -
to see a text dump of the parsing of the bitstream.

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.

Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

I am using this command to convert an avi,mov,m4v video files to flv format via FFMPEG
/usr/local/bin/ffmpeg -i '/home/public_html/files/video_1355440448.m4v' -s '640x360' -sameq -ab '64k' -ar '44100' -f 'flv' -y /home/public_html/files/video_1355440448.flv
[flv # 0x68b1a80] requested bitrate is too low
Output #0, flv, to '/home/files/1355472099-50cadce349290.flv':
Stream #0.0: Video: flv, yuv420p, 640x360, q=2-31, pass 2, 200 kb/s, 90k tbn, 25 tbc
Stream #0.1: Audio: adpcm_swf, 44100 Hz, 2 channels, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height
-------------------------------
RESULT
-------------------------------
Execute error. Output for file "/home/public_html/files/video_1355472099.avi" was found, but the file contained no data. Please check the available codecs compiled with FFmpeg can support this type of conversion. You can check the encode decode availability by inspecting the output array from PHPVideoToolkit::getFFmpegInfo().
But if I manually used this command then its working
/usr/local/bin/ffmpeg -i '/home/public_html/files/video_1355440448.m4v' -s '640x360' -sameq -ab '64k' -ar '44100' -f 'flv' -y /home/public_html/files/video_1355440448.flv
This is because you have two streams and output will be encoding then resizing, see your output messages:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
... you use adpcm_swf audio and yuv420p video
The answer is very simple, you need to put copy as your audio codec ...
See my example with video mpeg4,yuv420p and audio ac3 ...
ffmpeg -i input.mkv -vf scale=720:-1 -acodec copy -threads 12 output.mkv
this will change first size = 720 with aspect ratio = -1 (unknown). Also you need to use:
-acodec copy -threads 12
If don't use this you will have one error.
For example: When I used it, the output encoding messages show me this and it works well:
[h624 # 0x874e4a0] missing picture in access unit93 bitrate=1034.4kbits/s
Last message repeated 1163 times5974kB time=53.47 bitrate= 915.3kbits/s
You need to use for flv format file, something like this:
ffmpeg -i input.mp4 -c:v libx264 -crf 19 output.flv
You are given an error message
[flv # 0x68b1a80] requested bitrate is too low
You need to change bitrate to a valid. It is better if you use a different codec
-acodec libmp3lame
And remove the option -sameq. This option does NOT mean 'same quality'. Actually means 'same quantizers'!
I had a similar problem due to size constraints. The original image size was strange (width=1343), meaning that when I tried to specify a new size with -s, any rounding error caused problems. Make sure that the new image size can have the exact same aspect ratio!
I have got the same issue
- requested bitrate is too low
and just resolved this issue by lowering down the bit rate
by adding -b:a 32k

Resources