PHP and FFMPEG - Performing intelligent video conversion

前端 未结 3 1812
北海茫月
北海茫月 2020-12-24 00:14

I have an oddly difficult task to perform. I thought it would be easy, but all my efforts have been fruitless.

I\'m converting videos uploaded to a php script from

3条回答
  •  眼角桃花
    2020-12-24 00:31

    I'm not familiar with PHP, but I wrote a utility to work with ffmpeg in C# several months ago. I used regular expressions to do this. There are some regular expressions which may help you from there:

    // this is for version detection
    "FFmpeg version (?(\w|\d|\.|-)+)"
    // this is for duration parsing
    "Duration: (?\d{1,3}):(?\d{2}):(?\d{2})(.(?\d{1,3}))?"
    
    // these are connected:
    // 0) this is base for getting stream info
    "Stream #(?\d+?\.\d+?)(\((?\w+)\))?: (?.+): (?.+)"
    // 1) if the type is audio:
    "(?\w+), (?[\d]+) (?[MK]?Hz), (?\w+), (?\w+)(, (?\d+) (?[\w/]+))?"
    // 2) if the type is video:
    "(?\w+), (?\w+), (?\d+)x(?\d+), (?\d+(\.\d+)?) (?[\w\(\)]+)"
    

    So getting width and height you can calculate an aspect ratio.

    Note: I know that in some cases there expressions may fail.

提交回复
热议问题