ffmpeg-php encoding ending at random places

336 views
Skip to first unread message

Allan

unread,
Nov 18, 2009, 8:09:24 PM11/18/09
to ffmpeg-php
Hi.

I have another problem.

While using ffmpeg-php to encode .avi file to .flv the encoding
process seems to be ending at random places without encoding the full
length of the original file. It is not due to some system timeout
since the system seems to think it's done encoding and the rest of the
page loads as it should (I have a timer set up that shows how long did
the encoding process take - the numbers show up).

+ It does not end at the same place. When trying to encode a 30 min.
video I get random results with ffmpeg-php: 22 minutes, 28 minutes, 26
minutes etc.

ffmpeg -y -i video.avi -b 941k -qscale 7 -ar 44100 -ab 128 -acodec
libmp3lame -f flv -s 624x352 video.flv (941k and the size come from
the original file).

When using the same command in console it works every time, new files
length is as it should.

Todd Kirby

unread,
Nov 18, 2009, 8:54:42 PM11/18/09
to ffmpe...@googlegroups.com
ffmpeg-php does not encode video


--

You received this message because you are subscribed to the Google Groups "ffmpeg-php" group.
To post to this group, send email to ffmpe...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ffmpeg-php?hl=.



Allan

unread,
Nov 19, 2009, 7:06:59 AM11/19/09
to ffmpeg-php
I know ffmpeg-php does not encode anything by itself and is an
extension for ffmpeg, but the problem is still the same.

Allan

unread,
Nov 19, 2009, 7:10:49 AM11/19/09
to ffmpeg-php
I guess I should have said "using ffmpeg from PHP .. exec(command)".

Todd Kirby

unread,
Nov 19, 2009, 7:14:26 AM11/19/09
to ffmpe...@googlegroups.com
What is your max execution time set to in php.ini?

On Thu, Nov 19, 2009 at 4:10 AM, Allan <muu...@gmail.com> wrote:
I guess I should have said "using ffmpeg from PHP .. exec(command)".

vipin sahu

unread,
Nov 19, 2009, 7:20:53 AM11/19/09
to ffmpe...@googlegroups.com
First check your max execution time i wrote some tutorial over ffmpeg and php plz take a look

 http://vipinkrsahu.blogspot.com/2009/08/ffmpeg-conversion-and-image-conversion.html

and

http://vipinkrsahu.blogspot.com/2009/09/how-to-get-durationlength-of-video-file.html
--
Vipin Sahu
_____________________________
http://vipinkrsahu.blogspot.com
http://sahu.vipin.googlepages.com
http://twitter.com/vipinsahu
_____________________________

Allan

unread,
Nov 19, 2009, 7:35:30 AM11/19/09
to ffmpeg-php
When max execution time exceeds I should get an error and the rest of
the page would not load, right?
I have changed my max execution time and as I said in the first post,
the rest of the page does load + it does not stop at a certain time,
it stops when-ever it wants for some reason.

It stops at random times like 283s, 307s, 316s (I have a timer set up
that see how long it takes to encode a file) - full video would take
about 340s to encode.

Allan

unread,
Nov 19, 2009, 7:40:02 AM11/19/09
to ffmpeg-php
Since I use my system in fast-cgi mode I have put the following into
the ISPConfig-s Options area (I did get the max_execution timeout at
first).

<IfModule mod_fcgid.c>
SocketPath /tmp/fcgid_sock/
IdleTimeout 3600
ProcessLifeTime 7200
MaxProcessCount 1000
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 100
IPCConnectTimeout 8
IPCCommTimeout 600
BusyTimeout 300
</IfModule>

Todd Kirby

unread,
Nov 19, 2009, 8:46:14 AM11/19/09
to ffmpe...@googlegroups.com
Check your apache error log. Also try running your script using the commanline php and see if it gives you an error message.

Allan

unread,
Nov 19, 2009, 9:04:00 AM11/19/09
to ffmpeg-php
No errors anywhere. Did run the PHP from command line, shows ffmpeg
encoding file as usual (with the same messages I get when using ffmpeg
directly) but still just manages to complete just 27 minutes of video
(original: 34).

The other thing is, it takes a LOT longer when using ffmpeg through
PHP-s exec command. When I run ffmpeg in commandline it takes 240
seconds and makes a complete file for me but when I run it through php
& exec it just took 420 seconds and finished just 27 minutes of the
original file.

Allan

unread,
Nov 19, 2009, 10:26:17 AM11/19/09
to ffmpeg-php
Solved. & wow, I just managed to make a total ass out of myself.

It turned out that I had a small miscalculation in the part of my PHP
that calculates new width and height from the original file dimensions
- a miscalculation that lead height to be 6px higher than it should.
And I guess for some reason ffmpeg does not handle encoding videos not
in original ratio well.

Found out when I deleted the PHP and just used the exec command with
preset values from original file (as i did in commandline with just
ffmpeg).

So, my mistake. Sorry. This topic should be deleted.

Allan

unread,
Nov 19, 2009, 10:38:15 AM11/19/09
to ffmpeg-php
This place needs an "edit" button.
Seems that my ffmpeg encoding is breaking with no visible error every
time I use dimensions larger than original files..

Todd Kirby

unread,
Nov 19, 2009, 3:24:36 PM11/19/09
to ffmpe...@googlegroups.com
Are you dimensions power of two?

Allan

unread,
Nov 19, 2009, 5:42:39 PM11/19/09
to ffmpeg-php
Yes. It seems to be working most of the times now but I still
sometimes get a bit shorter files while using php + exec - encoding
the same file twice in a row can produce different results (length-
wise). Strange.

Todd Kirby

unread,
Nov 19, 2009, 6:22:43 PM11/19/09
to ffmpe...@googlegroups.com
That is strange. You could try running php in gdb and see if there's anything out of the ordinary going on. Or maybe run it in strace.


gdb --args php myscript.php


Allan

unread,
Nov 19, 2009, 7:34:39 PM11/19/09
to ffmpeg-php
This getting to be pretty annoying.

I was just about to post that "I think I fixed it (again)" - by
replacing bit rate "941k" with the full number from original file,
940007 - because after I did that my php script encoded file correctly
3 times in a row (it never did it before when I had changed target
file dimensions).. but just as I was typing the message and running
script the 4-th time the result file came in 5 min short again.

When I run my php file through commandline I always seem to get the
correct result, so strace didn't return anything unusual.

Todd Kirby

unread,
Nov 19, 2009, 7:45:59 PM11/19/09
to ffmpe...@googlegroups.com
Does anything show in the command output from exec?

exec($cmd, $output $retval);
print_r($output);


Try taking ffmpeg out of the equation. Put some timing code in your php script and change the ffmpeg call to just call sleep(1000).  See if you get consistant results.



Allan

unread,
Nov 19, 2009, 9:10:43 PM11/19/09
to ffmpeg-php
Using sleep(400) gives me something of a mystery. My server has it's
own mind of how the time should flow :s

Pass 1: 310.8976
Pass 2: 371.723
Pass 3: 400.074
Pass 4: 368.934

Todd Kirby

unread,
Nov 19, 2009, 9:18:52 PM11/19/09
to ffmpe...@googlegroups.com
Hmmm,  not sure what's going on there. Try restarting apache in single process mode and see if the timings are still whacked.

Allan

unread,
Nov 19, 2009, 9:43:11 PM11/19/09
to ffmpeg-php
I left some parts from previous script intact (not encoding, just
reading the source file info with new ffmpeg_movie() - that normally
takes < 0.001 sec when I refresh page without sleep()) for the first
tests.

Now I made a clean file with just timer and sleep() in it and it seems
to be returning constant results - that is until I try
"multitasking" (opening multiple tabs in firefox with the page-s url)
- then some black magic starts to happen again. The scripts with sleep
(400) in them take something around 9 minutes to run but try to tell
me that they ran only for 360 - 375 seconds.

Something wrong with my apache?

Todd Kirby

unread,
Nov 19, 2009, 9:47:04 PM11/19/09
to ffmpe...@googlegroups.com
Sounds like it. I can't think of anything else to try without looking at it directly. You might try running in single process mode with gdb but that probably won't tell you much since it's not failing outright.

-T-

Allan

unread,
Nov 20, 2009, 8:40:13 AM11/20/09
to ffmpeg-php
Thanks for you help! I would have never found the timing issue by
myself.
I'll have a system engineer look at it at the server farm where my box
is hosted, hopefully get this sorted out.
Reply all
Reply to author
Forward
0 new messages