1

Mp4ize (python) is a utility for converting video files to mp4 for use on iPhone and iPod. I'm trying to get it to run on Windows.

The python script relies on the library fcntl, and according to another question ( fcntl substitute on Windows ), the Windows equivalent is win32api. The other question also says:

If you provide more details about the fcntl calls people can find windows equivalents.

and since I've had no luck trying to rewrite the code myself, I thought I'd ask here.

How can I rewrite the following code for use on Windows?

fcntl.fcntl(
    p.stderr.fileno(),
    fcntl.F_SETFL,
    fcntl.fcntl(p.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK,
)

See here for the full source code.

Community
  • 1
  • 1
tttppp
  • 7,723
  • 8
  • 32
  • 38
  • Any luck with my suggestion? I'd like to know what version of ffmpeg works with mp4ize. – agf Jul 23 '11 at 14:08
  • @agf After finding this documentation page (http://www.ffmpeg.org/ffmpeg.html) which mentions that padtop has been deprecated, I changed the code to use this padding instruction padstr = '-vf "pad=%d:%d:%d:%d:black"'%(width, user_height, 0, pad). I'm now getting ffmpeg to start running, but it only converts the first megabyte before freezing. – tttppp Jul 24 '11 at 07:10
  • That line only works if the width hasn't been changed. I fixed it in the patch in my answer below. – agf Jul 24 '11 at 13:10

1 Answers1

2

This command sets the NONBLOCK option of the standard error file descriptor. This lets it pass data through before the entirety of the data has been written to it.

The patch at http://pastebin.com/Zr5LN8Ui will work, with progress indicators, on Windows. However, it will sometimes report a bad encode even when the encode was good.

It uses the solution from Non-blocking read on a subprocess.PIPE in python to allow non blocking IO, and fixes the pad option (your version didn't work for my test file) and progress bar for a modern FFMpeg.

Note that it is hardcoded to use the linked method when FFMpeg gets passed 3 or more command line options, as it messes up the first call to FFMpeg which gets the resolution of the input file.

Community
  • 1
  • 1
agf
  • 171,228
  • 44
  • 289
  • 238
  • Thanks - that patch has got ffmpeg working from the script. Incidentally I didn't need the changes related to the progress display. – tttppp Jul 26 '11 at 10:00
  • That was an attempt to get it to correctly report good and bad encodes. – agf Jul 26 '11 at 12:30