convert from jpg to mp4 by ffmpeg
Asked Answered
F

6

29

I have 320 jpg(320x574) images which I have recorded them with 2004 fps. I want to make a .mp4 video of them. I have run below codes in cmd (win7) and it just make a video of jpg number 320 and if I go for this ('*.jpg') insted of 320 it does not work. I really appreciate any help.

ffmpeg -r 1/5 -i C:\data-Sam\320.jpg -c:v libx264 -r 30 -pix_fmt yuv420p C:\data-Sam\out.mp4
Fiber answered 9/4, 2014 at 14:23 Comment(1)
2004 fps makes your video of length 80/501 seconds (under 0.2 seconds)!Urinal
O
27

Depending on your file names you'll want:

ffmpeg -f image2 -i /path/to/file/image%3d.jpg test.avi

The image%3d would be for files named: image000.jpg, image001.jpg, image002.jpg, etc.

If your files are named image0.jpg, image1.jpg, image2.jpg, etc. then you'd use /path/to/file/image%d.jpg.

See FFmpeg image2 demuxer examples

Oconnor answered 9/4, 2014 at 15:1 Comment(6)
My files name are sorted from 1.jpg to 320.jpg . I have to change them or I still could use them as it is.Fiber
when I run the code which you left, this attention note pops up in the cmd that Frame rate very high for a muxer not efficiently supporting it.Fiber
when I run the code which you left, this attention note pops up in the cmd that Frame rate very high for a muxer not efficiently supporting it. and asked me to use other muxer or -vsync 2. Indeed I have recorded my images which is 320 jpg with 2000 fps. I use this code: ffmpeg -f image2 -i Path/To/File/filename%d.jpg -r 2000 -pix_fmt yuv420p path\to\result\test.mp4 what do you think?Fiber
I am using ffmpeg binary on windows it doesn't take %d in option.Maxa
Trying to do this on Windows, as far as I can tell, it doesn't work. I only get the first frame.Palace
You can also use -pattern_type glob -i '*.jpg' if the file order presented by ls works for you.Disinherit
B
15

I can show you an example here,

ffmpeg -f image2 -r 60 -i path/filename%03d.jpg -vcodec libx264 -crf 18  -pix_fmt yuv420p test.mp4
  • f: force format
  • r: frame rate
  • i: input files assuming your files are filename001.jpg, filename002.jpg, ...
  • vcodec: video codec
  • crf: constant rate factor (0-51). 17-18 is (nearly) visually lossless. See Encode/H.264
  • pix_fmt: pixel format
Babysitter answered 1/11, 2020 at 18:46 Comment(0)
A
9

Use cat

finally, I came up with a solution, it is using cat to get a .mkv and then convert it to .mp4

navigate to the folder that contains the .jpg files

cat *.jpg | ffmpeg -f image2pipe -i - output.mkv

and then

ffmpeg -i output.mkv -codec copy output.mp4
Agriculturist answered 23/6, 2022 at 13:37 Comment(0)
F
7

You have other option like :

  • framerate = Set the frame rate for the video stream. It defaults to 25
  • -r = set frame rate

    ffmpeg -framerate 10 -i Path/To/File/filename%3d.jpg -r 5 -y Path/To/File/test.mp4
    
Feathercut answered 12/3, 2019 at 6:5 Comment(1)
what's the difference between -framerate and -r, if they both set the frame rate?Zaragoza
S
4

The main folder in it is ffmpeg.exe, the Your_files folder and the Result folder.
In the Your_files folder, upload a series of images.
Bat file will sort them in the order of the queue by name.
The finished video will be in the Result folder.

echo off
color a
set a="Your_files\*.jpg"
set b="Result\video.mp4"
set c=ffmpeg
set f=-c:v libx264 -pix_fmt yuv420p -r 30 -crf 20
set tmp="Result\list.tmp"
for %%f in (%a%) do (@echo file 'file:%cd%\%%f' >> %tmp%)
%c% -y -f concat -safe 0 -i %tmp% %f% %b%
cd /d Result
del /f /q list.tmp
exit

-c:v libx264 - We will encode in the MP4 format with the x264 codec.
-loglevel 16 – Show all errors, including ones which can be recovered from.
-r 30 – FPS frame rate. It takes effect after all filtering, but before encoding the video stream.
-crf 20 – Constant Rate Factor (CRF) is a quality setting (and rate control). values from 0 to 51, where lower values will result in better quality at the expense of higher file sizes. Higher values mean more compression, but at some point you will notice quality degradation. The default is 23.

Syphilis answered 3/2, 2021 at 21:22 Comment(1)
Great answer and explanation!Scoreboard
D
-5

I am using ffmpeg binary on windows it doesn't take %d in option.

You are using cmd.exe, Right? Then do it like:

"file%d.jpg"

cmd.exe uses %PATH% to imitate $PATH used in real shells, so gets confused with file%d.jpg.

Disconsider answered 27/12, 2017 at 3:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.