0

I installed FFmpeg (mplayer, mencoder, flvtool2, libogg, libvorbis, lame, ffmpeg-devel) on CentOs 7 Linux (plesk). No issues during installation.

The absolute path: /usr/bin/ contains the binaries ffmpeg, ffprobe, ffplay and ffserver plus other directories and files. However, the website ONLY plays videos from youtube or MP4 format.

Why can I not play videos with AVI, MOV and WEBm formats?

[root@server ~]# ffplay
ffplay version 3.4.7 Copyright (c) 2003-2019 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100

class Video extends Upload
{
    const SUPPORTED_TYPES = [
        'mov' => 'video/mov',
        'avi' => 'video/avi',
        'flv' => 'video/flv',
        'mp4' => 'video/mp4',
        'mpg' => 'video/mpg',
        'mpeg' => 'video/mpeg',
        'wmv' => 'video/wmv',
        'ogg' => 'video/ogg',
        'ogv' => 'video/ogv',
        'webm' => 'video/webm',
        'mkv' => 'video/mkv'
    ];

    const MP4_TYPE = 'mp4';

    /** @var File */
    private $oFile;

    /** @var string */
    private $sType;

    /** @var string */
    private $sFfmpegPath;

    /** @var array */
    private $aFile;

    /**
     * @param array $aFile Example: $_FILES['video']
     *
     * @throws MissingProgramException If FFmpeg is not installed.
     */
    public function __construct($aFile)
    {
        $this->oFile = new File;
        $this->sFfmpegPath = Config::getInstance()->values['video']['handle.ffmpeg_path'];

        if (!file_exists($this->sFfmpegPath)) {
            $sMsg = t('FFmpeg is not installed on the server or the path cannot be found. Please install and configure the path in "~/YOUR-PROTECTED-FOLDER/app/configs/config.ini" or contact the administrator of the site/server or web hosting by saying the problem.');
            throw new MissingProgramException($sMsg);
        }

        $this->aFile = $aFile;
        $this->sType = $this->aFile['type'];

        /** Attributes from "Upload" abstract class **/
        $this->sMaxSize = Config::getInstance()->values['video']['upload.max_size'];
        $this->iFileSize = (int)$this->aFile['size'];
    }

    /**
     * @return bool
     *
     * @throws TooLargeException If the video file is not found.
     */
    public function validate()
    {
        if (!is_uploaded_file($this->aFile['tmp_name'])) {
            if (!isDebug()) {
                return false;
            } else {
                throw new TooLargeException('Video file could not be uploaded. Possibly too large.');
            }
        } else {
            return in_array($this->sType, self::SUPPORTED_TYPES, true);
        }
    }

    /**
     * @param string $sFile
     *
     * @return bool
     */
    public function save($sFile)
    {
        return move_uploaded_file($this->aFile['tmp_name'], $sFile);
    }

    /**
     * @return string
     */
    public function getFileName()
    {
        return $this->aFile['name'];
    }

    /**
     * Convert video file and the extension video type.
     *
     * @param string $sFile New renamed file name.
     *
     * @return string The new name that you entered in the parameter of this method.
     */
    public function rename($sFile)
    {
        $sParams = ''; // By default, we don't use parameter

        $sType = $this->oFile->getFileExt($sFile); // Get the new format
        if ($sType === self::MP4_TYPE) {
            $sParams = '-c copy -copyts';
        }

        $this->executeCommand('-i', "{$this->aFile['tmp_name']} $sParams $sFile");

        return $sFile;
    }

    /**
     * Generate a thumbnail with FFmpeg.
     *
     * @param string $sPicturePath
     * @param int $iSeconds
     * @param int $iWidth
     * @param int $iHeight
     *
     * @return string The thumbnail file that you entered in the parameter of this method.
     */
    public function thumbnail($sPicturePath, $iSeconds, $iWidth, $iHeight)
    {
        $this->executeCommand(
            '-itsoffset',
            "-$iSeconds -i {$this->aFile['tmp_name']} -vcodec mjpeg -vframes 1 -an -f rawvideo -s {$iWidth}x{$iHeight} $sPicturePath"
        );

        return $sPicturePath;
    }

    /**
     * Gets video duration.
     *
     * @return int Seconds.
     */
    public function getDuration()
    {
        $sTime = $this->executeCommand(
            '-i ',
            "{$this->aFile['tmp_name']} 2>&1 | grep -i 'duration' | cut -d ' ' -f 4 | sed s/,//"
        );

        return Various::timeToSec($sTime);
    }

    /**
     * Get Type Video File.
     *
     * @return string The extension of the video without the dot.
     */
    public function getExt()
    {
        return $this->sType;
    }

    /**
     * Execute a FFmpeg command.
     *
     * @param string $sFlag
     * @param string $sArgument
     *
     * @return void
     */
    private function executeCommand($sFlag, $sArgument)
    {
        exec(
            sprintf(
                '%s %s %s',
                $this->sFfmpegPath,
                $sFlag,
                $sArgument
            )
        );
    }

    /**
     * Remove temporary file.
     */
    public function __destruct()
    {
        // If it exists, delete the temporary video file
        $this->oFile->deleteFile($this->aFile['tmp_name']);
    }
}
4
  • 1
    What does ffplay output to the console? Also ffmpeg does not depend on either of mplayer, mencoder, flvtool2, or lame.
    – Hermann
    Mar 14, 2020 at 23:11
  • The output in the website reads:"The following error was found: The file type is incompatible or too large. The accepted file types are: .mov, .avi, .flv, .mp4, .mpg/.mpeg, .wmv, .ogg, .ogv, .webm or .mkv". We checked the php scrip, the size is compatible.
    – Andressa
    Mar 15, 2020 at 18:42
  • Please elaborate on how a website and a php script is involved. What happens if you supply an MP4's filename to ffplay. A remote file should work, too e.g. ffplay https://ssl.hehoe.de/bilder/reaktionen/iloveit.mp4.
    – Hermann
    Mar 15, 2020 at 22:45
  • Herman, I agree with you, but I am still unable to see the problem limiting the uploading to MP4 on the website.
    – Andressa
    Mar 16, 2020 at 19:56

1 Answer 1

0

Try ffmpeg -codecs to list all the codecs your build implements.

The output is in the following format:

Codecs:
 D..... = Decoding supported
 .E.... = Encoding supported
 ..V... = Video codec
 ..A... = Audio codec
 ..S... = Subtitle codec
 ...I.. = Intra frame-only codec
 ....L. = Lossy compression
 .....S = Lossless compression
 -------
 D.VI.S 012v                 Uncompressed 4:2:2 10-bit
 D.V.L. 4xm                  4X Movie
 D.VI.S 8bps                 QuickTime 8BPS video
 .EVIL. a64_multi            Multicolor charset for Commodore 64 (encoders: a64multi )

If some are missing, its probably because of a bad compilation process.

1
  • Hi binarym, thanks for your advice. Unfortunately, I've got the same output. But, I will proceed with a new compilation.
    – Andressa
    Mar 16, 2020 at 22:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .