Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@symfonyaml
Copy link
Contributor

@symfonyaml symfonyaml commented Nov 29, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Purpose

Inspired by the Image constraint, I've added a new feature to the Validator component for validating Video files using the PHP-FFMpeg library.

This constraint use exactly the same concept as the Image one, with the same options except for the corrupted options (detectcorrupted, corruptedmessage)
I think we can definitely apply more options for video files, but first I just want to check if everyone is okay with this constraint.

Example

namespace App\Entity;

use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;

class Tutorial
{
    #[Video(maxWidth: 1920, maxHeight: 1080)]
    private File $video;
}

@OskarStark OskarStark changed the title [Validator] Add the Video constraint for validating video files [Validator] Add Video constraint for validating video files Jan 9, 2025
@nicolas-grekas
Copy link
Member

Looks like a PR should be contributed upstream to fix this:

  1x: Method "Alchemy\BinaryDriver\AbstractBinary::getName()" might add "string" as a native return type declaration in the future. Do the same in child class "FFMpeg\Driver\FFProbeDriver" now to avoid errors or add an explicit @return annotation to suppress this message.

Can you submit it?

@symfonyaml
Copy link
Contributor Author

Looks like a PR should be contributed upstream to fix this:

  1x: Method "Alchemy\BinaryDriver\AbstractBinary::getName()" might add "string" as a native return type declaration in the future. Do the same in child class "FFMpeg\Driver\FFProbeDriver" now to avoid errors or add an explicit @return annotation to suppress this message.

Can you submit it?

@nicolas-grekas PR created in the PHP-FFMpeg/PHP-FFMpeg repo PHP-FFMpeg/PHP-FFMpeg#940

@symfonyaml symfonyaml force-pushed the video-validator branch 2 times, most recently from df0ce8c to cf56118 Compare January 12, 2025 17:54
@mindaugasvcs
Copy link
Contributor

mindaugasvcs commented Feb 27, 2025

I have done this a long time ago. Just why use classes instead of ffprobe directly?

$json = shell_exec('ffprobe -hide_banner -loglevel quiet -show_error -show_format -show_streams -print_format json '.$value);
if (!$json) {
    throw new LogicException('This validator requires ffprobe installed and enabled in the PATH system variable.');
}

@mindaugasvcs
Copy link
Contributor

mindaugasvcs commented Feb 27, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Purpose

Inspired by the Image constraint, I've added a new feature to the Validator component for validating Video files using the PHP-FFMpeg library.

This constraint use exactly the same concept as the Image one, with the same options except for the corrupted options (detectcorrupted, corruptedmessage) I think we can definitely apply more options for video files, but first I just want to check if everyone is okay with this constraint.

Example

namespace App\Entity;

use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;

class Tutorial
{
    #[Video(maxWidth: 1920, maxHeight: 1080)]
    private File $video;
}

Tell me you are not promoter of this useless ffmpeg wrapper.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Feb 27, 2025

@mindaugasvcs please express yourself in a more friendly manner. You might be right that the wrapper is not needed, but calling the wrapper "useless" or suggesting bad intentions as a hidden "promoter" is detrimental to having a constructive discussion. Open source requires respectful discussions.

@symfonyaml
Copy link
Contributor Author

@mindaugasvcs I agree that using ffmpeg is not fantastic, I am totally open for better suggestions and good intentions ;)

@mindaugasvcs
Copy link
Contributor

@mindaugasvcs please express yourself in a more friendly manner. You might be right that the wrapper is not needed, but calling the wrapper "useless" or suggesting bad intentions as a hidden "promoter" is detrimental to having a constructive discussion. Open source requires respectful discussions.

First of all, you should not have accepted this PR in the first place as we now both agree the wrapper is not needed. I believe this PR should not be a part of the framework. I asked you long time before about such validator, you gave me no answer back then. And now? WTF?! May I ask to explain yourself?

@nicolas-grekas
Copy link
Member

@mindaugasvcs Let's keep the discussion constructive. If you raised this idea earlier, I understand your frustration. That said, decisions in open source evolve based on contributions. Discussions are only a first step. Here, we have a patch, and that's how things happen.

If you have strong technical reasons why this validator should not be part of the framework, let's focus on those. Do you see specific downsides beyond just the existence of the wrapper?

@mindaugasvcs
Copy link
Contributor

mindaugasvcs commented Feb 27, 2025

@mindaugasvcs Let's keep the discussion constructive. If you raised this idea earlier, I understand your frustration. That said, decisions in open source evolve based on contributions. Discussions are only a first step. Here, we have a patch, and that's how things happen.

If you have strong technical reasons why this validator should not be part of the framework, let's focus on those. Do you see specific downsides beyond just the existence of the wrapper?

Reasons why including such a basic video validator is bad idea:

  1. Working with videos isn't so straightforward as working with images: videos can have multiple video streams, multiple audio streams, multiple text streams, videos can even be 3D aka stereo ones. Not every Symfony web site / web app needs a validator of videos, even if they needed one, they would most probably find this implementation too basic.
  2. Validation of videos should be left for a custom implementation at application level because it's very dependent of business needs. Other reasons why: SOLID and ease of configuration: possibility to pass constraint values via DI, system admins sometimes aren't programmers.
  3. No other major web framework provides support for video files out of box (most probably because of reasons I just outlined).

Reasons why this wrapper is bad as implementation of such idea:

  1. One more layer of complexity and maintenance: when this project dies the implementation will automatically turn into technical debt.
  2. It's not supported by PHP nor PHP community.
  3. Enormous amount of time spent just to learn how to use it, even for basic stuff.

Copy link
Contributor

@Spomky Spomky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor remarks. Overall it looks good.

@mindaugasvcs
Copy link
Contributor

?

@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
@nicolas-grekas nicolas-grekas force-pushed the video-validator branch 2 times, most recently from 8398f3c to 5a2ee0a Compare September 2, 2025 14:51
@nicolas-grekas nicolas-grekas force-pushed the video-validator branch 4 times, most recently from 7eded7f to 97dfcf8 Compare September 2, 2025 15:12
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR to remove any dependency on external libs.
I also added checks to reject videos with several streams and checks for the video codec + container format.

@mindaugasvcs
Copy link
Contributor

Is Symfony framework still community project?

@nicolas-grekas
Copy link
Member

What does this mean @mindaugasvcs ?

@symfonyaml
Copy link
Contributor Author

I updated the PR to remove any dependency on external libs. I also added checks to reject videos with several streams and checks for the video codec + container format.

@nicolas-grekas thank you so much for taking over on this PR, so much appreciated, I was very busy sorry.

And yes Symfony is the best community project ❤️

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at the code, it's clear that this is a complex subject. Glad you created this validator with excellent test coverage.

@nicolas-grekas
Copy link
Member

Thank you @symfonyaml.

@nicolas-grekas nicolas-grekas merged commit 95f0098 into symfony:7.4 Sep 3, 2025
9 of 12 checks passed
nicolas-grekas added a commit that referenced this pull request Sep 3, 2025
…(nicolas-grekas)

This PR was merged into the 6.4 branch.

Discussion
----------

[Validator] Update translation for the Video constraint

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Add translations for messages added to #59042 + a few other missing ones.

Commits
-------

59b201d [Validator] Update translation for the Video constraint
@mindaugasvcs
Copy link
Contributor

I updated the PR to remove any dependency on external libs. I also added checks to reject videos with several streams and checks for the video codec + container format.

@nicolas-grekas thank you so much for taking over on this PR, so much appreciated, I was very busy sorry.

And yes Symfony is the best community project ❤️

How many community members were involved in decision making of this PR? And why that downvote? It kind of shows that asking questions around here just isn’t welcome. So yea, the question is more than valid.

$streams = $meta['streams'] ?? [];
$formats = explode(',', strtolower($meta['format']['format_name'] ?? 'unknown'));

if (!($streams[0]['width'] ?? false) || !($streams[0]['height'] ?? false)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge error here, $streams[0] is allowed to not be the default video stream, you must check the default flag at $stream['disposition']['default'] or calcule it yourself if its not present.

Copy link
Member

@GromNaN GromNaN Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, if you found a bug and know the fix, could you please open a PR targeting the oldest maintained branch that has this bug (7.4), with the fix and a non-regression test.

Copy link
Contributor

@mindaugasvcs mindaugasvcs Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you read this conversation from the beginning, you could see that I did mention that video files may contain multiple video streams and that I don't support including such a basic and buggy validator into Symfony. The first stream may not be always the default stream. No body care what I say or write. Now I let the original author to fix his own mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you read the code below, you'll see that we reject videos that have multiple streams.
This means we don't have to care about the default stream.
No bug here.

I appreciate that you care about us providing a video validator that makes sense. But I don't think the rage that your messages express is deserved. Both on your side - it must be stressful to have so much energy to yell at others - and for the others, which don't have to be the recipient of your anger.

Please keep a respectful tone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants