PHP-FFMpeg and multiple outputs

Created on 20 Jul 2015  Â·  21Comments  Â·  Source: PHP-FFMpeg/PHP-FFMpeg

According to here, ffmpeg supports transcoding to multiple output files given a single input file in one command:

ffmpeg -i input \
    -s 1280x720 -acodec … -vcodec … output1 \
    -s 640x480  -acodec … -vcodec … output2 \
    -s 320x240  -acodec … -vcodec … output3

Is this functionality available or on any roadmap for this project? As far as I can tell, $video->save() only takes a single input format / output path.

Feature help wanted

All 21 comments

@jeffsrepoaccount Do you know if this has any speed or performance improvements instead of calling $video->save() multiple times?

@patkar The issue I was facing at the time was attempting to transcode a few thousand videos on an oversized EC2 instance. Using php FFMpeg was failing to saturate all of the cores, yet running the command line version above would. If I remember correctly, there were also issues with different codecs not being able to be multithreaded anyway, so they would block all other encoding outputs until that output was complete regardless of whether I was using php ffmpeg and $video->save() or command line options.

I think this could be implemented like the following, if only the formats would differ.

$video->enableMultipleOutput()
    ->save($format1, ..)
    ->save($format2, ..)
    ->save($format3, ..)
    ->doSave()
;

But in your example the size differs, which means a separate filter and thus not solveable with the current filter implementation. May you take a look at #141 if such filter chains could be a step forward to this?

Yeah, I imagine that PR is probably a step forward. As a consumer, ideally I would think that a single invocation should be able to somehow coalesce to any number of outputs, each with their own size/format combination, or any possible set of options that command-line ffmpeg allows. That said, I also appreciate the esoteric nature ffmpeg command-line options, so it may be hard to design a way to be able to tell ffmpeg how to do it.

Here's at least a look at how I could envision a calling context utilizing both:

$twelveEighty = new Dimension(1280, 720);
$sixForty = new Dimension(640, 480);

$x264 = new X264();
$x264
    ->addSize($twelveEighty, 'out-1280-720.mp4')
    ->addSize($sixForty, 'out-640-480.mp4');

$ogg = new Ogg();
$ogg
    ->addSize($twelveEighty, 'out-1280-720.ogg')
    ->addSize($sixForty, 'out-640-480.ogg');

$video
    ->options()
    ->filter($filters)  // The filter graph
    // Now add the formats?
    ->addFormat($x264)
    ->addFormat($ogg)
    ->synchronize()
    ->save()
;

I'm not sure if that actually helps you any or not.

So you define the format as a complete output line in this example. Maybe a BC break ^^ But looks reasonable :+1:

Must analyse the current code more deeply to take decisions for such new features, but any 1.0 release in the future has BC breaks, for sure :grimacing:

I think it should be fairly easy to support BC, at least in this feature thread (not really sure about filter graphs).

->save() with no arguments: Build command-line options through filter graph and added formats
->save() with arguments: "BC Mode"

The point is not only the save() method. Adding methods to a interface like format is a BC too, it breaks implementors, which are not using the abstract DefaultVideo and DefaultAudio classes. But I think this is not the biggest problem, as long it's properly documented.

Any updates on this request? I think this feature would be useful for my project.

@jens1o I don't think that there is anything new here.
Could you create a PR with a new method allowing the user to save the file into multiple outputs in one request?

I'll do it on the weekend. @Romain

Thanks @jens1o

@jens1o Any progress? I think this feature would be useful for my project too. Saving to different formats from one input is common in many cases.

@shtse8
It's on my list and (nearly) finished. But I'm waiting so the others pr's can be resolved first. Thanks for the ping. At the moment, this may include a bc break, but I would look after other possibilities.

@jens1o i want save multiple outputs with different sizes could you please help me i want this feature waiting for reponse thank you

Unfortunately, I'm on a different pc now, and I didn't pushed it. I'll do as soon as I can, but I wan't to make sure it works properly and does not cause any side effects. Also, it's the end of the school year, and I have to learn for class exams... :/

Thank you for the hard work @jens1o, hopefully, your exams went well!

This would definitely be a wonderful feature to have in the library, especially when pairing it with MP4box for MPEG-DASH

To be honest, I totally forgot that issue here, but the exams went quite well. Apologize.. :/

I should have pushed my changes, then at least I'd have something to work with...

Hey man no worries, I am glad the exams went well, and you don't have to apologise at all, it's open source, anyone can contribute, it doesn't have to be you, I had just hoped you had something that was already in the making.

@jens1o Hi, What news about this issue PR?

@airani I'm lacking of time, I'm in the middle of the Christmas exam phase, but I'd be happy to see another PR. :)

So in case somebody wants to help, a pr would be appreciated. :)

Although this would require a massive rewrite of the existing codebase. We would need to check whether we can do this with as less api changes as possible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aminyazdanpanah picture aminyazdanpanah  Â·  6Comments

datangkang123 picture datangkang123  Â·  7Comments

jenky picture jenky  Â·  3Comments

sheikhasadmuneer picture sheikhasadmuneer  Â·  4Comments

totomtornado picture totomtornado  Â·  6Comments