ffmpeg enforces bitrate value other than what specified - ffmpeg

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.

Related

ffmpeg setting ouput option correctly (-r)

I would like to use ffmpeg on Ubuntu with the following command:
ffmpeg -i input_video -vf scale=w=320:h=-1 -y -vcodec libx264 -preset ultrafast -r 60 output_video
For the -r option the documentation says:
-r[:stream_specifier] fps (input/output,per-stream)
Set frame rate (Hz value, fraction or abbreviation).
As an input option, ignore any timestamps stored in the file and
instead generate timestamps assuming constant frame rate fps. This is
not the same as the -framerate option used for some input formats like
image2 or v4l2 (it used to be the same in older versions of FFmpeg).
If in doubt use -framerate instead of the input option -r.
As an output option, duplicate or drop input frames to achieve
constant output frame rate fps.
I would like to use the output option. How can I do this? What is the per-stream option doing (it is not written above)?
Second, is it correct that the -vf scale=w=320:h=-1 option scaled the video to width 320 and keeping the aspect ratio?
I would like to use the -r output option. How can I do this?
Your command is using it as an output option. The location of options is important as it determines what is applied to the input or the output:
ffmpeg [input options] -i input [output options] output
What is the per-stream option doing (it is not written above)?
"per-stream" means that this option can be declared several times to apply to different streams using stream specifiers. Since you have only one video stream in your output you can ignore this.
Second, is it correct that the -vf scale=w=320:h=-1 option scaled the video to width 320 and keeping the aspect ratio?
Yes, but when encoding with libx264 consider using -2 instead of -1. It does the same thing but makes sure the result is divisible by 2 which is required for this encoder (there are exceptions).

How to get a lossless encoding with ffmpeg - libx265

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

Animation from large number of jpg files

I have more than 100,000 jpg images in a directory and want to create an animation from these files. These files are sequentially numbered from file1 to file125000. I have tried using ImageMagick and many other free tools, but hasn't worked. After 3 hours, imagemagick gave an error saying that the number of files is too large. Is there any tool (Windows) that can process this?
You can use ffmpeg with a command like this one:
ffmpeg.exe -f image2 -r 30 -i image%06d.jpg -codec:v libx264 -crf 23 video.mp4
ffmpeg command line have a structure like this:
ffmpeg [input params] -i <input> [output params] <output>
Input params are:
-f: is used to force input or output format. In my example is used to indicate that input file is intended to be parsed as image2, an internal ffmpeg format which can be used to specify multiple images using a pattern;
-r: can be used to force frame rate both on input or output. If used only on input, output framerate is inherited.
-i image%06d.jpg: this flag specify to read all image with 6 integer digits, filled with leading zeroes (from image000000.jpg to image999999.jpg). Of course ffmpeg will stop at last existing file.
Other params are used to specify output format and video codec. In particular:
-codec:v libx264: specify video codec (x264 using libx264)
-crf 23: this parameter is peculiar of x264 encoder, used to specify Constant RateFactor, and influences output bitrate and others.
video.mp4: If not specified, FFMpeg try to guess output format from the output file name. In my example I used .mp4, so FFmpeg will encode video using libx264 encoder and MP4 format.
FFMpeg windows build can be download from zeranoe
Edit: if your images names don't have leading zeroes try using file%6d.jpg instead of file%06d.jpg as input filename (without 0).

ffmpeg speed up video - Windows

In manual it says:
ffmpeg -i input.mkv -filter:v 'setpts=0.5*PTS' output.mkv
But when I run:
ffmpeg -i input.mp4 -filter:v 'setpts=0.5*PTS' speedup.mp4
I get an error:
[AVFilterGraph # 0000000002500600] No such filter: 'setpts=0.5*PTS'
Error opening filters!
Not sure if it means that filter can't be opened at all or simply this filter is not available.
How do I run it correctly? Or maybe my release does not support it, then where can I get the release that would work right? Win32/x64 binary
Use both setpts and atempo to speed up both video and audio:
ffmpeg -i input-video.mp4 -vf "setpts=0.68*PTS" -filter:a "atempo=1.467" output-video.mp4
From: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
You'll have to do the right math for the numbers, of course. The setpts needs to be smaller to make the video go faster, but atempo needs to be larger to speed up the audio.
Audio value needed = 1 / Video value
if you have your ffmpeg.exe (mine for windows) for ex you can list all the available filters with this command line, you can edit the txt file c:\filters.txt to see them.
ffmpeg -filters > c:\yfilters.txt
in mine i can se the filter SETPS (VIDEO TO VIDEO only):
setpts V->V Set PTS for the output video frame.
your command line is correct and work with the ffmpeg version that have this filter(try to download the latest version)
this command line works also for me :
ffmpeg -i video_input -vf "setpts=factor*PTS" video_output
the factor can be :
1.for speeding the video 0.2,0.4,0.6,0.8..(<1)
2.for slowing the video:1.2,1.4,1.6,1.8,2.0,3.0,4.0,5.0,10.0... (>1)
Try using double quotes. e.g. ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" speedup.mp4

ffmpeg -r option

I am trying to use ffmpeg (under linux) to add a small title to a video. So, I use:
ffmpeg -i hk.avi -r 30000/1001 -metadata title="SOF" hk_titled.avi
The addition of title seems to work, but, the problem is the output file is about a 1/3rd of the file size of the input file and I was wondering why this is? Is this at the expense of quality of the video? I am unsure.. How do I preserve the same quality/size as the input file?
The main point I am unable to figure out is the use of -r option. Going through the ffmpeg docs, it seems to suggest that -r is frames per second (The input video is 23.9fps). At the moment, (30000/1001) works out to 29 fps, but I was unsure if I should be using this value.
Thanks for your time.
The default settings for ffmpeg do not always provide a good quality output when you encode, but this depends on your output format and the available encoders. With your output ffmpeg will use the default of -b 200k or -b:v 200k.
However, you can tell ffmpeg to simply copy the input streams without re-encoding and this is recommended if you just want to add or edit metadata. These examples do the same thing but use different syntax depending on your ffmpeg version:
ffmpeg -i hk.avi -vcodec copy -acodec copy -metadata title="SOF" hk_titled.avi
ffmpeg -i hk.avi -c copy -metadata title="SOF" hk_titled.avi

Resources