Hello
How can I convert multiple images to one YUV 4:2:0 file?
+ Reply to Thread
Results 1 to 21 of 21
-
I think it requires avisynth
Did you want to string together multiple images into 1 video ? What type of YUV video ? 4:2:0? Jpeg is usually RGB
You can use ImageSource() in avisynth and ffmpeg to encode
e.g.
ImageSource("file%03d.jpg", 0,1000, fps=29.97)
ConvertToYV12()
This uses sprintif syntax, so the input files are sequentially numbered like file000.jpg, file001.jpg etc.... of course adjust it to match whatever you have. "03d" is the number of placeholders. So file00001.jpg would use file%05d.jpg
IN ffmpeg
ffmpeg -i input.avs -pix_fmt yuv420p output.yuv
If you wanted other YUV types, you can specify that in the avisynth script and ffmpeg output
The RGB=>YUV conversion matrix is Rec.601 by default. You can specify another matrix in the avs script
You should be able to do with ffmpeg directly too, but you have less control over other parameters (like matrix conversion)
ffmpeg -i %03d.jpg -pix_fmt yuv420p -r 29.97 output.yuv -
Dear poisondeathray
I cannot understand.
It is complex.
I am beginner.
Is there any simpler solution?
I worked with any2yuv but it can only convert grayscal images.
I worked with ImageMagick but it cannot convert colors truly.
In C:\Program Files\AviSynth 2.5> I typed: ImageSource("im2.jpg",2,2,fps=29.97) but
I received this error: ImageSource is not recognized as an internal or external command, operable program or batch file.
What should I do now? -
Are you sure you need YUV ? as in raw ? or will uncompressed YV12 do ? because simplier solution would be use vdub to string together images and export uncompressed YV12
Avisynth needs too be installed. Read the instructions here
http://avisynth.org/mediawiki/Main_Page#New_to_AviSynth_-_start_here
You write a script in notepad, and change the extension from .txt to .avs. Or you can use a script editor like avspmod
ImageSource("im2.jpg",2,2,fps=29.97)
If you want only 1 picture, then simplify it to ImageSource("im2.jpg",fps=29.97) . This "video" will last 1 frame only. (1/30th of a second long)
You seem to understand the commandline, so try using ffmpeg directly (without avisynth) -
Dear poisondeathray
Thank you for your response
I converted one image using this command:
C:\Program Files\ImageMagick-6.6.9-Q16>ffmpeg -i zzim2.jpg -pix_fmt yuv420p zzim
2.yuv
FFmpeg version SVN-r23418, Copyright (c) 2000-2010 the FFmpeg developers
built on Jun 2 2010 04:12:01 with gcc 4.4.2
configuration: --target-os=mingw32 --enable-runtime-cpudetect --enable-avisynt
h --enable-gpl --enable-version3 --enable-bzlib --enable-libgsm --enable-libfaad
--enable-pthreads --enable-libvorbis --enable-libtheora --enable-libspeex --ena
ble-libmp3lame --enable-libopenjpeg --enable-libxvid --enable-libschroedinger --
enable-libx264 --extra-libs='-lx264 -lpthread' --enable-libopencore_amrwb --enab
le-libopencore_amrnb --enable-librtmp --extra-libs='-lrtmp -lssl -lcrypto -lws2_
32 -lgdi32 -lwinmm -lcrypt32 -lz' --arch=x86 --cross-prefix=i686-mingw32- --cc='
ccache i686-mingw32-gcc' --enable-memalign-hack
libavutil 50.16. 0 / 50.16. 0
libavcodec 52.72. 1 / 52.72. 1
libavformat 52.67. 0 / 52.67. 0
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.20. 0 / 1.20. 0
libswscale 0.11. 0 / 0.11. 0
Input #0, image2, from 'zzim2.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0.0: Video: mjpeg, yuvj420p, 450x375 [PAR 72:72 DAR 6:5], 25 tbr, 25
tbn, 25 tbc
[ffmpeg_output @ 03429480]auto-inserting filter 'auto-inserted scaler 0' between
the filter 'src' and the filter 'out'
[scale @ 034296d0]w:450 h:375 fmt:yuvj420p -> w:450 h:375 fmt:yuv420p flags:0x4
Output #0, rawvideo, to 'zzim2.yuv':
Metadata:
encoder : Lavf52.67.0
Stream #0.0: Video: rawvideo, yuv420p, 450x375 [PAR 1:1 DAR 6:5], q=2-31, 20
0 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
frame= 1 fps= 0 q=0.0 Lsize= 247kB time=0.04 bitrate=50670.0kbits/s
video:247kB audio:0kB global headers:0kB muxing overhead 0.000000%
C:\Program Files\ImageMagick-6.6.9-Q16>
But it wasn't converted truly and the colors are wrong.
Is it possible to do it yourself for me? -
sure I can do it; upload it here
but your original post says multiple images, not just 1 ?
but you haven't answered the questions:
1) what kind of yuv file? 420? 422?
2) how do you want the RGB=>YUV conversion done? ITU Rec601? Rec709? Full range? limited range? etc...
and how are you determining that hte "colors are wrong"? How are you viewing YUV ? -
Dear poisondeathray
Thank you very much for your kindly help
I want to convert two PNG files to one YUV 4:2:0 file.
I don't understand your second question.
I only know that my YUV files must like these files:
ftp://hvc:US88Hula@ftp.tnt.uni-hannover.de/testsequences
I view YUV files using YUV Player Deluxe.
I cannot upload the images.
May I have your email? -
I tested it and the ffmpeg alone method works with several YUV viewers, including elecard yuv viewer, avisynth's rawsource - if the color is "off" , I think it's a viewer setting problem or you haven't set the dimensions correct (when viewing raw data this is important)
when viewing you have to view as "IYUV" or "i420" - the arrangement of the chroma planes is different
don't worry about the 2nd question, when using SD material, you can usually assume Rec.601
I'll PM you my email
EDIT: I tested with YUV player deluxe and it works fine as well., I think you have it set up incorrectly for the wrong image sizeLast edited by poisondeathray; 2nd Apr 2011 at 17:21.
-
your problem might have something to do with the png dimensions. theres nothing wrong with the dimension when they are png, *but* if you want to convert to yuv then you have to follow certain rules, i.e. width / 4, and height / 2
simple way to check for even-ness is to divide width and height, if you get a decimal then you dimensions are off and you will probably have decoded color problems.
so in this case, make sure that the png images are evenly divisable as above and when you convert to yuv through
ffmpeg -i "g:\yuv.%03d.png" -pix_fmt yuv420p -r 29.970 -y "g:\output.yuv"
all will be well..
..where yuv.%03d.png as in yuv.001.png, yuv.002.png, ...
..and where -pix_fmt is the yuv color sampling format for the raw yuv image,
..and ffmpeg will pad the necessary yuv header in the raw .yuv source.
next, when you play the .yuv source it should be consistant with the frame rate you used in the ffmpeg command line param setting, i.e., -r 29.970 (frame rate) in this case.
download YUVPlayer.exe here: http://www.yuvplayer.com/
i'm not sure if this is in the tools section, but you can download a yuvplayer from the above link. it is very user-friendly configurable, i.e., i use a 360x172 test .png file and after following the same setup (mentioned above) and i set the player to this dimension, it played my source correctly. 360/4=90, and 172/2=86, (not 360/172) and no decimal error there.
note, i used FFmpeg version SVN-r24489 in this example.Last edited by vhelp; 2nd Apr 2011 at 18:17.
-
Not so, the default for ImageSource is to produce 1001 frames (start=0, end=1000).
(In this case, of course, they would all be identical.)
The original script does give a 1-frame result - perhaps by accident, as normally one would use
ImageSource("im2.jpg", end=0 ,fps=29.97) -
Dear vhelp
My image size is 450 x 375
What should I do?
Is it necessary to change the size? -
dear mma238 - please explain what is purpose of such YUV vile -why You need convert series of JPEG's to YUV - it is for encoding? making some special sequence or something else?
We need to know this to select (help You) proper tools and methodology for You.
My favorite way for such tasks is to use FFMPEG + AVISYNTH -
VirtualDub can open a sequentially numbered series of PNG files (File -> Open Video File -> select first image). Then save with a codec that uses YUV 4:2:0, aka YV12. Like Xvid, Lagarith, etc. Or you can force output to YV12 (video -> Color Depth -> Output -> 4:2:0/YV12) and save uncompressed.
-
Yes, it does - just run VirtualDub.exe.
You probably ran the other program vdub.exe instead, which has a command line interface. -
vhelp is correct - it doesn't comply to mod2 restrictions. When cropped 1 bottom pixel to 450x374 , the image works fine
@gavino - my mistake about imagesource , thanks for correction -
My image size is 450 x 375
also, make sure that all images are of the same dimensions--they must be!
just pad your png images' width/height to 452 x 376, and you can check the math on that, W 452/4=113 and H 376/2=188 and yuv should decode with proper color.
just pad your png images' width/height to 452 x 376, and you can check the math on that, W 452/4=113 and H 376/2=188 and yuv should decode with proper color. (the mod4 rule is for the width and mod2 for the height, what PDR mentioned earlier)
now, if you only have a couple of images, the quickest way to pad is to open in ms paint (windows xp) and pad a few extra pixels to the image W and H. there are other tools that can probably do this faster and/or easier, but ms paint is free quick for a couple of images.
how to: pad extra pixels
1. open ms paint, and load an image
2. move mouse to menu bar and select Image, then Attributes, then change W: 450 to 452 and H: 375 to 376
3. click [OK]
4. save back to png (open drop-down to select png) or else paint will deault to bmp
5. repeat for as many images
6. done
the above is a quicky solution. but the only thing weary about this is the odd pixel colors you will see on the bottom and far right-side because these will be black pixels. so, you may want to crop off pixels instead.
how to: crop off pixels
1. open ms paint, and load an image
2. move mouse to menu bar and select Image, then Attributes, then change W: 450 to 448 and H: 375 to 374
3. click [OK]
4. save back to png (open drop-down to select png) or else paint will deault to bmp
5. repeat for as many images
6. done
quick math check: W 448/4=112, and H 374/2=187, all even numbers.
in these cases you have to plan your image dimension first so you can decide how much actual data (detail) you want to see in the image sequence for yuv play or else consider adding borders if necessary. but as long as you remember the math check rule you can pretty much figure out how much image you want in a given dimension and not have to worry about cropping and padding and what-not.Last edited by vhelp; 3rd Apr 2011 at 09:03.
-
Dear all
The problem was solved.
The dimensions must be even as vhelp said.
Thanks to anyone replied
Special thanks to vhelp and poisondeathray
Similar Threads
-
MS-YUV - Sony Vegas
By francisco-drm in forum Capturing and VCRReplies: 2Last Post: 25th Nov 2011, 11:56 -
AVS to YUV
By fidogenial in forum Video ConversionReplies: 1Last Post: 21st Oct 2010, 21:53 -
Help reading .yuv files
By lotsoflayne in forum Newbie / General discussionsReplies: 1Last Post: 23rd Sep 2009, 20:09 -
convert .yuv to .ts
By mrzapp in forum Video ConversionReplies: 3Last Post: 19th Nov 2008, 07:34 -
YUV viewer
By mourya in forum ProgrammingReplies: 0Last Post: 31st Oct 2007, 13:38