Howto automate JPEG to MP4 with Mencoder in Windows

Questions? Suggestions? Need help? Talk about anything related to Yawcam...
Post Reply
tijeff
Posts: 11
Joined: Fri Jan 07, 2011 5:36 am

Howto automate JPEG to MP4 with Mencoder in Windows

Post by tijeff »

Howto automate JPEG to MP4 with Mencoder in Windows

With this process, you can convert motions detected jpg in a viewable MP4 video. Since it is called from a command line , you can easily automate the process. If CPU usage is an issue, you can also convert to mjpeg( motion jpeg) which is basically a stack of jpeg in a mpeg file, It will use less cpu power , but will build a file as big as your original JPEG. MJPEG might be more compatible to more video reader.


Performances on a 2.4ghz Core2 quad , 4gb ram, Windows XP to :

Convert 4800 95kb 720x480 jpg (total450mb) to MP4 :
Output file size: 24mb
3-10 minutes
Use a 10-20mb of ram while in the process
Use 25% of cpu
Edit:
(Doesn't seem to bee possible to use more that a core)
(Windows split the task on many cores thus: )
(Will usee 100% on a single core)
(Will usee 50% on a dual core)
(Will usee 25% on a quad core)


Convert 4800 95kb 720x480 jpg (total450mb) to MJPEG :
Output file size: 415mb
2 minutes
Use a 3-5mb of ram while in the process
Use 2% of cpu




Step 1 :
Download and unzip (you might need 7zip) Mplayer with MEncoder
http://www.mplayerhq.hu/design7/dload.html
Actualy you only need Mencoder, the Player is useless for this process

It wasn’t really well sorted out on there web page when I’ve searched for it, here is a direct download link, Pick the one with your CPU
http://sourceforge.net/projects/mplayer ... z/download

Step 2:
You only need the mencoder.exe file, put it in your JPEG folder, havent found a better working way to do it :(

Step3:
Build yourself a .bat file in the same folder , here is mine:
______________
:begining

REM ------MJPEG-------
mencoder mf://*.jpg -mf w=720:h=480:fps=20:type=jpg -ovc copy -oac copy -o cam1.avi

REM ------MP4---------
REM mencoder mf://*.jpg -mf w=720:h=480:fps=20:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o cam1.avi

xcopy cam1.avi .. /Y
del cam1.avi

ping 127.0.0.2 -w 5000
ping 127.0.0.2 -w 5000
goto :beginning
________________

It basically compress all jpeg in the same folder to a video file
(Remove the REM comment) before the compression type you need.
It moves the video file in the preceding Folder
It wait 10 seconds while doing fake ping commands, and do it all again.

Step 4
Use VLC to read the file


Sources :
http://www.mplayerhq.hu/DOCS/HTML/en/me ... mages.html




Command line result:

C:\camera\cam1\move>REM ------MJPEG-------
C:\camera\cam1\move>REM mencoder mf://*.jpg -mf w=720:h=480:fps=20:type=jpg –ovc copy -oac copy -o cam1.avi

C:\camera\cam1\move>REM ------MP4---------
C:\camera\cam1\move>mencoder mf://*.jpg -mf w=720:h=480:fps=20:type=jpg -ovc lav
c -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o cam1.avi
MEncoder SVN-r32735-4.2.5 (C) 2000-2010 MPlayer Team
success: format: 16 data: 0x0 - 0x0
MF file format detected.
[mf] search expr: *.jpg
[mf] number of files: 5311 (21244)
VIDEO: [IJPG] 720x480 24bpp 20.000 fps 0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:16 fourcc:0x47504A49 size:720x480 fps:20.000 ftime:=0.0500
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffmjpeg] vfm: ffmpeg (FFmpeg MJPEG)
==========================================================================
Movie-Aspect is 1.50:1 - prescaling to correct movie aspect.
videocodec: libavcodec (720x480 fourcc=34504d46 [FMP4])
[VE_LAVC] High quality encoding selected (non-realtime)!
Fontconfig error: Cannot load default config file
Fontconfig failed to select a font. Trying without fontconfig...
New_Face failed. Maybe the font path is wrong.
Please supply the text font file (~/.mplayer/subfont.ttf).
subtitle font: load_sub_face failed.
Fontconfig failed to select a font. Trying without fontconfig...
New_Face failed. Maybe the font path is wrong.
Please supply the text font file (~/.mplayer/subfont.ttf).
subtitle font: load_sub_face failed.
Writing header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp h
eader.
Writing header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp h
eader.
Pos: 98.8s 1975f (37%) 17.46fps Trem: 3min 25mb A-V:0.000 [804:0]]
:( :oops:
Last edited by tijeff on Sun Jan 09, 2011 7:08 am, edited 1 time in total.
z3r0c00l12
Moderator
Posts: 1210
Joined: Wed Jan 14, 2009 3:50 am

Post by z3r0c00l12 »

This sounds very interesting, I'll give it a try when I have time.

Since you seem pretty good, can you explain here what the different switches are in the batch file for mencoder. What I am looking for is mostly the explanation for every possible switched to mencoder in order to modify your command line to work with my current settings.

As an example, I use a resolution of 320x240 recording at 1 fps, saving as .jpg. I would likely be playing the video at a slightly higher fps, say 3-5 fps, and make it look like a fast-forwarded video. I would output as an MP4 because CPU usage isn't an issue but disk space is.

z3r0c00l12
buntay
Posts: 32
Joined: Sun May 04, 2008 6:46 am

I like this, good find,

Post by buntay »

Once this is thoroughly tested I would like to build this in to JAMCAM4 ver.2. Will I need permissions or such? JAMCAM4 Has the ability to import video files from a remote machine on a local network but the files have to be pre-created. merging these two softwares would make yawcam and the subwares an amazing security system for home or small buisness. go here http://bunsoft.10fast.net to find out more what JAMCAM4 can do.

thanks for the time.
buntay
tijeff
Posts: 11
Joined: Fri Jan 07, 2011 5:36 am

Post by tijeff »

z3r0c00l12:

I would simply try something like this then :
I’m pretty convinced it would work great

mencoder mf://*.jpg -mf w=320:h=240:fps=3:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o cam1.avi


But from what I know :
mf://*.jpg --> Get all the files in the current folder
w=320:h=240:fps=3:type=jpg --> Width Height FPS
ovc --> Stand for Output video compression
lavc -lavcopts vcodec=mpeg4:mbd=2:trell --> Video option for the mp4 compression
-oac copy --> Output audio compression, useless, but I gess you could include a wav or and MP3?l
-o cam1.avi --> The output File

For more Video compression options, have a look at the 11.8.3.2. lavcopts section here:
http://www.mplayerhq.hu/DOCS/HTML/en/me ... d-dvd.html

For the Mp4 options you may want to have a peek here:
http://personal.cscs.ch/~mvalle/mencoder/mencoder.html
http://web.njit.edu/all_topics/Prog_Lan ... oding.html
Last edited by tijeff on Sun Jan 09, 2011 6:12 pm, edited 2 times in total.
tijeff
Posts: 11
Joined: Fri Jan 07, 2011 5:36 am

Re: I like this, good find,

Post by tijeff »

buntay wrote:Once this is thoroughly tested I would like to build this in to JAMCAM4 ver.2. Will I need permissions or such? JAMCAM4 Has the ability to import video files from a remote machine on a local network but the files have to be pre-created. merging these two softwares would make yawcam and the subwares an amazing security system for home or small buisness. go here http://bunsoft.10fast.net to find out more what JAMCAM4 can do.

thanks for the time.
buntay

I have No clue , thoses are not my softwares !
tony2012
Posts: 19
Joined: Sun Mar 27, 2011 12:56 am

Post by tony2012 »

This .bat file works great fore me :)

What is the command I can include in the .bat file that deletes all the jpg files after completing the avi file?

Thank you.
tijeff
Posts: 11
Joined: Fri Jan 07, 2011 5:36 am

Post by tijeff »

del *.jpg

( they probably wont go to your "recycle bin" and they will be deleted for-ever)
tony2012
Posts: 19
Joined: Sun Mar 27, 2011 12:56 am

Post by tony2012 »

tijeff wrote:del *.jpg

( they probably wont go to your "recycle bin" and they will be deleted for-ever)
Well that was easy lol
generalsu
Posts: 28
Joined: Sat Jul 07, 2012 10:28 pm

Post by generalsu »

Is there a way to compile jpg files in nested folders?
bugmenot-user
Posts: 12
Joined: Fri Feb 08, 2008 1:37 am

Re: Howto automate JPEG to MP4 with Mencoder in Windows

Post by bugmenot-user »

you can use following script

Code: Select all

:beginning

REM ------MP4---------
mencoder mf://*.jpg -mf w=720:h=480:fps=20:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o cam1.avi

xcopy cam1.avi .. /Y
del cam1.avi

ping 127.0.0.2 -w 5000
ping 127.0.0.2 -w 5000
goto :beginning
This script will compress all JPEG files in the same folder into a video file in MP4 format.
It moves the resulting video file to the parent folder, waits for 10 seconds with fake ping commands, and then repeats the process.
if you have small quantity of image and want fine compression of your images then you can use this jpeg compressor tool, It can support JPEG, JPG, PNG, SVG, WEBP, GIF, and Heic.
Post Reply