1
votes

I am working with ffmpeg to convert videos into flv files via php. The tests I have done do not work for mp4 conversions. I have a 13 second video (videos will be limited to 15 seconds), when it is uploaded and I check the "duration" of the video it comes out over 300 seconds. I have tried changing around how I process the video:

// original
exec('ffmpeg -i <path>/<filename> 2>&1', $output);

// current
exec('ffmpeg -i <path>/<filename> 2>&1 | grep "Duration" | cut -d \' \' -f 4 | sed s/,//', $output);

The original method did not work for mpg files but the second does, but neither gives me the "correct" duration of a mp4 video. Is there a "special" way to process mp4 files?

Thank you for your time and help.

Update:

Command line

ffmpeg -i ./custom_scraping.mp4 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//
00:05:15.84

Complete output (formatted as best I could)

ffmpeg -i ./custom_scraping.mp4 2>&1
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 23:55:02 with gcc 4.1.2 20080704 (Red Hat 4.1.2-51)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
libavutil     50.15. 1 / 50.15. 1
libavcodec    52.72. 2 / 52.72. 2
libavformat   52.64. 2 / 52.64. 2
libavdevice   52. 2. 0 / 52. 2. 0
libavfilter    1.19. 0 /  1.19. 0
libswscale     0.11. 0 /  0.11. 0
libpostproc   51. 2. 0 / 51. 2. 0

Seems stream 1 codec frame rate differs from container frame rate: 5994.00 (5994/1) -> 29.97 (2997/100)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './custom_scraping.mp4':
Metadata:
major_brand     : mp42
minor_version   : 1
compatible_brands: mp42avc1
Duration: 00:05:15.84, start: 0.000000, bitrate: 36 kb/s
Stream #0.0(eng): Audio: aac, 44100 Hz, stereo, s16, 2 kb/s
Stream #0.1(eng): Video: h264, yuv420p, 480x360, 36 kb/s, 1.04 fps, 29.97 tbr, 2997 tbn, 5994 tbc

At least one output file must be specified

Don't know if it helps but from the listing of the file in Linux: 1432471 May 31 13:33 custom_scraping.mp4

Let me know if anything else is needed.

1
First cut out the PHP junk and use ffmpeg directly. Once it works as expected in ffmpeg then try it in PHP. Also include actual examples and the console outputs so we can easily duplicate it and see exactly what the issue is. - llogan
ffmpeg is complaining about some inconsistency. Is the file properly encoded and does it play as expected? - Salman A
I play the file in vlc and quicktime and it plays fine. It is a generic video I took off the web for testing purposes. - oach
When you watch the video is it 13 seconds long or 00:05:15.84 as ffmpeg states? Does using a more recent ffmpeg report the same time? Simply get the current FFmpeg source, compile with a plain ./configure, and run ./ffmpeg (no need to install). Or, alternatively, provide a link to the sample and I can check. - llogan
If I update the version of ffmpeg, is the most recent (I believe the site had 0.11) the best one to go to? A link to the raw file: reelcareer.com/_video/files/4/custom_scraping.mp4. Let me know if you need anything else. I appreciate the help. - oach

1 Answers

0
votes

Using a recent ffmpeg will provide the correct duration:

$ ffmpeg -i custom_scraping.mp4
ffmpeg version N-41105-g7a2ae76 Copyright (c) 2000-2012 the FFmpeg developers
  built on May 29 2012 21:41:27 with gcc 4.7.0 20120505 (prerelease)
  configuration: --prefix=/usr --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libutvideo --enable-libvorbis --enable-libx264 --enable-nonfree --enable-x11grab
  libavutil      51. 55.100 / 51. 55.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.101 / 54.  6.101
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'custom_scraping.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp42avc1
    creation_time   : 2011-08-17 21:14:16
  Duration: 00:00:11.11, start: 0.000000, bitrate: 1031 kb/s
    Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 2 kb/s
    Metadata:
      creation_time   : 2011-08-17 21:14:16
      handler_name    : Apple Sound Media Handler
    Stream #0:1(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 480x360, 36 kb/s, 1.04 fps, 29.97 tbr, 2997 tbn, 5994 tbc
    Metadata:
      creation_time   : 2011-08-17 21:14:16
      handler_name    : Apple Video Media Handler
At least one output file must be specified

When you encounter unexpected behavior the first thing to do is try the most recent FFmpeg. Otherwise you will possibly be wasting your time fighting a bug that has already been resolved. FFmpeg development is very active. If a bug is still occurring in a recent FFmpeg then please report it on the bug tracker.

Getting FFmpeg from Git is usually preferred for general users. The releases are targeted more for distributions who "require" a so-called release.

The FFmpeg Wiki contains compile guides for CentOS (and therefore Red Hat) and Ubuntu.