How to get a lossless encoding with ffmpeg - libx265 - ffmpeg

I would like to convert 16 bits grayscale images in an HEVC/mkv video with the x265 encoder without loss, using ffmpeg. I use the monochrome12 profile. My first step is to convert images into yuv format:
ffmpeg -f image2 -i "C:\DATA FOLDER\images%d.png" video.yuv
And I try to convert it as a .mkv file, losslessly:
ffmpeg video.yuv video.mkv -c:v libx265 -x265-params "profile=monochrome12:crf=0:lossless=1:preset=veryslow:qp=0"
But I get
Unrecognized option '-lossless'
Error splitting the argument list : Option not found
When I don't write lossless=1 everything's right, but I don't manage to have a lossless video by this way.
thank you for your help.

It works for me if I make a few changes:
ffmpeg -i video.avi -c:v libx265 \
-x265-params "profile=monochrome12:crf=0:lossless=1:preset=veryslow:qp=0" \
video.mkv
This is like the command you've provided, except I'm using a different input format, and prepend -i to mark it as an input file.
I also put the output filename at the end, after the output options, otherwise they are not applied, and I get this warning among the output:
Trailing options were found on the commandline.
I don't think the command you gave would cause the error you get though.
libx265 will not give an error on params it doesn't recognise, but show a warning like:
[libx265 # 0x563e4520e740] Unknown option: lessloss.
I can reproduce your exact error by trying to add --lossless as a parameter to ffmpeg:
ffmpeg --lossless -i video.avi video.mkv
Unrecognized option '-lossless'.
Error splitting the argument list: Option not found

Related

FFMpeg printing "Option pixel_format not found" when using "pix_fmt"

I'm trying to do a relatively simple task - convert a video from one pixel format to another by re-encoding. This is my current command:
ffmpeg -hide_banner -loglevel error -pix_fmt yuv444p -i "%1" video.mp4
Where %1 is the filename. However, strangely enough, ffmpeg prints out this:
Option pixel_format not found.
It's in red, so it's an error. Adding -loglevel verbose does not give any more information. I'm really confused about this - I did not define any "pixel_format" option. This issue occurs both when calling this command from a batch file and directly from a cmd.exe instance.
Replacing "pix_fmt" with "pixel_format" and putting pix_fmt after -i does not solve the issue.
You're trying to read the input file forcibly with yuv444p. Try
ffmpeg -hide_banner -loglevel error -i "%1" -pix_fmt yuv444p video.mp4
The h264 decoder does not support user-specified pixel format thus the error: Option pixel_format not found. The default h264 encoder (libx264) on the other hand allows -pix_fmt option to specify the output pixel format.

ffmpeg watermark: scale2ref output can't be used in second overlay

I was able to add a watermark to 2 position(top left & bottom right) of a video with scaling image height to tenth of the video height in one command
ffmpeg -hide_banner -i /path/to/input.mp4 -i /path/to/watermark.jpg -filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[video-out][logo-out]overlay=10:10[flag];[1:v][flag]scale2ref=oh*mdar:ih/10[logo-out2][video-out2];[video-out2][logo-out2]overlay=W-w-10:H-h-10" -c:a copy /path/to/output.mp4
But the above command is too redundant, so I remove the second scale2ref
ffmpeg -hide_banner -i /path/to/input.mp4 -i /path/to/watermark.jpg -filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[video-out][logo-out]overlay=10:10[flag];[flag][logo-out]overlay=W-w-10:H-h-10" -c:a copy /path/to/output.mp4
But sadly, error occurs
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fb195013c00] Invalid stream specifier: logo-out.
Last message repeated 1 times
Stream specifier 'logo-out' in filtergraph description [1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[video-out][logo-out]overlay=10:10[flag];[flag][logo-out]overlay=W-w-10:H-h-10 matches no streams
I know error occurs because of the first overlay didn't set an image output specifier, but it seems we can't do this? I only know overlay can set a video stream specifier.
How can I use the [logo-out] specifier which output from scale2ref in the second overlay?
An output generated inside a filtergraph can only be consumed once. To reuse it, split it first.
ffmpeg -hide_banner -i /path/to/input.mp4 -i /path/to/watermark.jpg -filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[logo-out]split=2[logo-left][logo-right];[video-out][logo-left]overlay=10:10[flag];[flag][logo-right]overlay=W-w-10:H-h-10" -c:a copy /path/to/output.mp4

ffmpeg enforces bitrate value other than what specified

I have a folder containing 1701 image frames named "frame0000.jpg", "frame0001.jpg",..., "frame1700.jpg". When I try to convert them to a video using this command:
ffmpeg -r:1751/61 -b:2400k -i frame%3d.jpg video1.avi
It produces a video with a bitrate of 717kbs and 25 frames/second (so the FPS is also different than what I specified!); hence, it has a poor quality.
I read a lot about this issue such as:
FFMPEG ignores bitrate
But couldn't find the solution to my case.
Any help is appreciated.
Fixed command:
ffmpeg -framerate 1751/61 -i frame%3d.jpg -b:v 2400k video1.avi
Option placement is important
Syntax is:
ffmpeg [input options] -i input [output options] output
Use valid options
-r:1751/61 is incorrect. Use -framerate 1751/61. The image demuxer prefers -framerate, not -r.
-b:2400k is incorrect. Use -b:v 2400k
Refer to the log
It should have provided errors to help you determine the problem:
Invalid stream specifier: 1751/61
Option b (video bitrate (please use -b:v)) cannot be applied to input -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.

Error setting option pix_fmt to value -1: Pipe a mp4 video with ffmpeg

I was piping a mp4 file and always got Error setting option pix_fmt to value -1.
I was trying to put -pix_fmt option in front of '-i inputfile', as in the ffmpeg output I found a message: unspecified pixel format but it seems not work
The ffmpeg outpus is here: http://pastebin.com/8hNdLeQ2
By the way, the ffmpeg version I was using is the latest one from git repo
And the mp4 video clip is from a sumsung tablet.
The command I use:
$ cat b2.mp4 | ./ffmpeg -i pipe:0 -c:a copy a.mp4
I also tried:
The video is at: https://www.dropbox.com/s/oz0e51ggkbpgj0f/b2.mp4
Anyone can tell me how to pipe this mp4 video, Thanks,
Lewis

FFMPEG says "No such file or directory" when trying to convert image sequence

From the shell, when I specify a sequence of images via %d in the input filename, FFMPEG insists "No such file or directory", despite evidence to the contrary. Looking online, I haven't managed to find any references to generating video from a sequence of images using FFMPEG where %d is not used, yet it seems to fail here.
My images should be identified by FFMPEG from img%06d.gif. Issuing ls img[0-9][0-9][0-9][0-9][0-9][0-9].gif succeeds in the very same directory I issue the FFMPEG command.
The command I use is:
ffmpeg -i img%06d.gif -c:v libx264 -r 30 -pix_fmt yuv720p test.mp4
What could possibly be going wrong???
The following definitely works:
ffmpeg -i images%06d.png -c:v libx264 -r 30 test.mp4 -y
However it doesn't work with GIF pictures.
You can losslessly convert your pictures to PNG and run the above command line.

Resources