Question

Python - mencoder doesn't produce video in a different folder.

I'm using Python to call mencoder to take a bunch of images and convert them into a video. The code I have do to this is:

def Video(self,X,Y,location):#generate a video from the images
    location=location.replace('\\','/')
    name='Slide.avi'

    command = ('C:\Downloads\MPlayer-athlon-svn-34401\mencoder.exe',# location of mencoder
               'mf://'+location+'/*.png',# location of the images
               '-mf',
               'type=png:w='+str(X)+':h='+str(Y)+':fps=25',#size of video and fps
               '-ovc',
               'lavc',
               '-lavcopts',
               'vcodec=ffv1',
               '-oac',
               'copy',
               '-o',
               location+'/'+name)#output 

   subprocess.check_call(command)

Where location is the folder that contains all the images I want to string together into a video. Now the thing is, if my python script is in the folder that also has the images in it, this works just fine and I get a video. But if the location is different, mencoder simply gives me an empty video. I don't understand why that would be. The code works if my python script is in that folder, but doesn't if its a different folder.

I've turned on the verbose for mencoder and this is what I get when it succeeds:

MEncoder Sherpya-SVN-r34401-4.6.2 (C) 2000-2011 MPlayer Team

Setting PATH to C:\Downloads\MPlayer-athlon-svn-34401\codecs

get_path('codecs.conf') -> 'C:\Users\Main/mplayer/codecs.conf'

Reading optional codecs config file C:\Users\Main/mplayer/codecs.conf: No such file or directory

Reading optional codecs config file /mingw/etc/mplayer/codecs.conf: No such file or directory

Using built-in default codecs.conf.

init_freetype

Using MMX (with tiny bit MMX2) Optimized OnScreenDisplay

get_path('fonts') -> 'C:\Users\Main/mplayer/fonts'

Configuration: --extra-cflags=-I/c/Work/mplayer/live --extra-ldflags=-lws2_32 --prefix=/mingw --enable-static --enable-md5sum --enable-menu --enable-faac --enable-enca --enable-sdl --enable-caca --enable-gl --enable-freetype --enable-png --enable-mng --enable-jpeg --enable-gif --enable-tga --enable-mad --enable-tv --enable-theora --disable-vidix --disable-faac-lavc --disable-inet6 --flavor=athlon

WINSOCK2 init: 0

STREAM: [mf] mf://C:/Users/Main/Desktop/temp/*.png

STREAM: Description: Multiple files input

STREAM: Author: Benjamin Zores, Albeu

STREAM: Comment: 

success: format: 16  data: 0x0 - 0x0

MF file format detected.

[mf] search expr: C:/Users/Main/Desktop/temp/*.png

[mf] number of files: 50 (200)

==> Found video stream: 0

VIDEO:  [MPNG]  560x560  24bpp  25.000 fps    0.0 kbps ( 0.0 kbyte/s)

[V] filefmt:16  fourcc:0x474E504D  size:560x560  fps:25.000  ftime:=0.0400

WINSOCK2 init: 0

WINSOCK2 init: 0

[file] File size is 0 bytes

STREAM: [file] C:/Users/Main/Desktop/temp/Slide.avi

STREAM: Description: File

STREAM: Author: Albeu

STREAM: Comment: based on the code from ??? (probably Arpi)

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

[png @ 01235100]err{or,}_recognition separate: 2; 1

[png @ 01235100]err{or,}_recognition combined: 2; 196609

INFO: libavcodec init OK!

Selected video codec: [ffpng] vfm: ffmpeg (FFmpeg PNG)

==========================================================================

[ffmpeg] aspect_ratio: 0.000000

VDec: vo config request - 560 x 560 (preferred colorspace: RGB 24-bit)

Trying filter chain: expand lavc

Could not find matching colorspace - retrying with -vf scale...

Opening video filter: [scale]

SwScale params: -1 x -1 (-1=no scaling)

Trying filter chain: scale expand lavc

VDec: using RGB 24-bit as output csp (no 6)

Movie-Aspect is undefined - no prescaling applied.

VO Config (560x560->560x560,flags=0,'MPlayer',0x52474218)

SwScaler: reducing / aligning filtersize 1 -> 4

SwScaler: reducing / aligning filtersize 1 -> 4

SwScaler: reducing / aligning filtersize 1 -> 1

SwScaler: reducing / aligning filtersize 9 -> 8

[swscaler @ 01216d40]BICUBIC scaler, from rgb24 to yuv420p using MMX2

[swscaler @ 01216d40]560x560 -> 560x560

[swscaler @ 01216d40]lum srcW=560 srcH=560 dstW=560 dstH=560 xInc=65536 yInc=65536

[swscaler @ 01216d40]chr srcW=280 srcH=560 dstW=280 dstH=280 xInc=65536 yInc=131072

REQ: flags=0x401  req=0x0  

REQ: flags=0x401  req=0x0  

videocodec: libavcodec (560x560 fourcc=31564646 [FFV1])

[ffv1 @ 01235100]err{or,}_recognition separate: 1; 1

[ffv1 @ 01235100]err{or,}_recognition combined: 1; 65537

[ffv1 @ 01235100]Unsupported bit depth: 0

*** [scale] Allocating mp_image_t, 560x560x24bpp RGB packed, 940800 bytes

*** [lavc] Allocating mp_image_t, 560x560x12bpp YUV planar, 470400 bytes

*** [expand] Direct Rendering mp_image_t, 560x560x12bpp YUV planar, 470400 bytes

Unicode font: 773 glyphs.

Unicode font: 773 glyphs.

Muxer frame buffer sending 1 frame(s) to the muxer.

Writing header...

ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.

Writing header...

ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.

Pos:   0.0s      1f ( 1%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/14 D/B/S 0/0/0 


*** [scale] Allocating mp_image_t, 560x560x24bpp RGB packed, 940800 bytes

Pos:   0.1s      2f ( 3%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/12 D/B/S 0/0/0 
Pos:   0.1s      3f ( 5%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/11 D/B/S 0/0/0 
Pos:   0.2s      4f ( 7%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/11 D/B/S 0/0/0 
Pos:   0.2s      5f (10%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.2s      6f (11%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.3s      7f (14%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.3s      8f (15%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.4s      9f (18%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.4s     10f (20%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.4s     11f (21%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.5s     12f (23%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.5s     13f (25%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.6s     14f (28%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.6s     15f (30%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.6s     16f (31%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/10 D/B/S 0/0/0 
Pos:   0.7s     17f (34%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   0.7s     18f (36%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   0.8s     19f (37%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   0.8s     20f (40%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   0.8s     21f (41%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   0.9s     22f (43%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   0.9s     23f (46%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.0s     24f (47%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.0s     25f (50%)   0fps Trem:   0min   1mb  A-V:0.000 [0:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.0s     26f (52%)   0fps Trem:   0min   1mb  A-V:0.000 [5215:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.1s     27f (55%)   0fps Trem:   0min   1mb  A-V:0.000 [5176:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.1s     28f (56%)   0fps Trem:   0min   1mb  A-V:0.000 [5136:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.2s     29f (58%)   0fps Trem:   0min   1mb  A-V:0.000 [5097:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.2s     30f (61%)   0fps Trem:   0min   1mb  A-V:0.000 [5059:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.2s     31f (62%)   0fps Trem:   0min   1mb  A-V:0.000 [5021:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.3s     32f (64%)   0fps Trem:   0min   1mb  A-V:0.000 [4983:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.3s     33f (67%)   0fps Trem:   0min   1mb  A-V:0.000 [4946:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.4s     34f (68%)   0fps Trem:   0min   1mb  A-V:0.000 [4910:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.4s     35f (70%)   0fps Trem:   0min   1mb  A-V:0.000 [4873:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.4s     36f (73%)   0fps Trem:   0min   1mb  A-V:0.000 [4838:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.5s     37f (75%)   0fps Trem:   0min   1mb  A-V:0.000 [4802:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.5s     38f (76%)   0fps Trem:   0min   1mb  A-V:0.000 [4767:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.6s     39f (79%)   0fps Trem:   0min   1mb  A-V:0.000 [4732:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.6s     40f (81%)   0fps Trem:   0min   1mb  A-V:0.000 [4698:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.6s     41f (82%)   0fps Trem:   0min   1mb  A-V:0.000 [4664:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.7s     42f (85%)   0fps Trem:   0min   1mb  A-V:0.000 [4631:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.7s     43f (87%)   0fps Trem:   0min   1mb  A-V:0.000 [4599:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.8s     44f (88%)   0fps Trem:   0min   1mb  A-V:0.000 [4566:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.8s     45f (91%)   0fps Trem:   0min   1mb  A-V:0.000 [4534:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.8s     46f (93%)   0fps Trem:   0min   1mb  A-V:0.000 [4502:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.9s     47f (94%)   0fps Trem:   0min   1mb  A-V:0.000 [4471:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   1.9s     48f (97%)   0fps Trem:   0min   1mb  A-V:0.000 [4440:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   2.0s     49f (100%)   0fps Trem:   0min   1mb  A-V:0.000 [4409:0] A/Vms 0/9 D/B/S 0/0/0 
Pos:   2.0s     50f (100%)   0fps Trem:   0min   1mb  A-V:0.000 [4378:0] A/Vms 0/9 D/B/S 0/0/0 


ds_fill_buffer: EOF reached (stream: video)  



Flushing video frames.

Writing index...

Writing header...

ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.



Video stream: 4378.820 kbit/s  (547352 B/s)  size: 1094705 bytes  2.000 secs  50 frames

Uninit video: ffmpeg

WINSOCK2 uninit

deo stream: 4378.820 kbit/s  (547352 B/s)  

size: 1094705 bytes  2.000 secs  50 framesUninit video: ffmpegWINSOCK2 

uninit

But when I change the folder, I get this:

MEncoder Sherpya-SVN-r34401-4.6.2 (C) 2000-2011 MPlayer Team

Setting PATH to C:\Downloads\MPlayer-athlon-svn-34401\codecs

get_path('codecs.conf') -> 'C:\Users\Main/mplayer/codecs.conf'

Reading optional codecs config file C:\Users\Main/mplayer/codecs.conf: No such file or directory

Reading optional codecs config file /mingw/etc/mplayer/codecs.conf: No such file or directory

Using built-in default codecs.conf.

init_freetype

Using MMX (with tiny bit MMX2) Optimized OnScreenDisplay

get_path('fonts') -> 'C:\Users\Main/mplayer/fonts'

Configuration: --extra-cflags=-I/c/Work/mplayer/live --extra-ldflags=-lws2_32 --prefix=/mingw --enable-static --enable-md5sum --enable-menu --enable-faac --enable-enca --enable-sdl --enable-caca --enable-gl --enable-freetype --enable-png --enable-mng --enable-jpeg --enable-gif --enable-tga --enable-mad --enable-tv --enable-theora --disable-vidix --disable-faac-lavc --disable-inet6 --flavor=athlon

WINSOCK2 init: 0

STREAM: [mf] mf://C:/Users/Main/Desktop/marshmarshmarshmarsh/*.png

STREAM: Description: Multiple files input

STREAM: Author: Benjamin Zores, Albeu

STREAM: Comment: 

success: format: 16  data: 0x0 - 0x0

MF file format detected.

[mf] search expr: C:/Users/Main/Desktop/marshmarshmarshmarsh/*.png

[mf] number of files: 50 (200)

==> Found video stream: 0

VIDEO:  [MPNG]  560x560  24bpp  25.000 fps    0.0 kbps ( 0.0 kbyte/s)

[V] filefmt:16  fourcc:0x474E504D  size:560x560  fps:25.000  ftime:=0.0400

WINSOCK2 init: 0

WINSOCK2 init: 0

[file] File size is 0 bytes

STREAM: [file] C:/Users/Main/Desktop/marshmarshmarshmarsh/Slide.avi

STREAM: Description: File

STREAM: Author: Albeu

STREAM: Comment: based on the code from ??? (probably Arpi)

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

[png @ 01235100]err{or,}_recognition separate: 2; 1

[png @ 01235100]err{or,}_recognition combined: 2; 196609

INFO: libavcodec init OK!

Selected video codec: [ffpng] vfm: ffmpeg (FFmpeg PNG)

==========================================================================

ds_fill_buffer: EOF reached (stream: video)  



Flushing video frames.

Writing index...

Writing header...

ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.



Video stream:      nan kbit/s  (-2147483648 B/s)  size: 0 bytes  0.000 secs  0 frames

Uninit video: ffmpeg

WINSOCK2 uninit

This was a test run using just 50 png images. For the successful run, my python script was in the folder with the images and told it to put the video there. (the 'temp' folder)

The failed run was a folder that contained the images, but not my python script. (the 'marshmarshmarshmarsh' folder). It appears that its finding the images just fine, but somehow fails to produce a video from it. I'm not seeing why it works only in one folder, but fails to work when its told to put the video in some other folder.

Was it helpful?

Solution

Late answer: I had the same problem, and despite the ton of searches, the only workaround that I found was to change to the target directory, make the video then switch back to the original directory, if you need to do some further processing in it:

# Make sure the image directory exists
if not os.path.exists(img_dir):
    raise Exception("\nThe directory '" + img_dir + "' does not exist !")

# Navigate to the image directory
os.chdir(img_dir)

# Sort image files
subprocess.call('dir /b /o *.png > files.txt', shell=True)  


animationname = "Animation_" + foldername[:-1].lower() + "_" + scalar_to_export +  ".avi"
command = ('mencoder',
           'mf://@files.txt', #works only in the current dir
           '-mf',
           'type=png:fps='+str(fps),
           '-ovc',
           'lavc',
           '-lavcopts',
           'vcodec=mpeg4',
           '-oac',
           'copy',
           '-o',
           dirname + animationname )   
subprocess.call(command)    

# Switch back to the original directory
os.chdir(dirname)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top