Code Duplication    Length = 24-24 lines in 2 locations

src/PlaygroundCore/Service/Ffmpeg.php 2 locations

@@ 67-90 (lines=24) @@
64
     * This method create a video from still images (jpg or png).
65
     * ffmpeg -framerate 1/5 -i etape%01d.jpg -c:v libx264 -vf "fps=25,format=yuv420p" out.mp4
66
     */
67
    public function createVideoFromImages($path = 'data/etape*.jpg', $target = false, $framerate = '25', $fps = 25)
68
    {
69
        try {
70
            // don't want this service to be a singleton. I have to reset the ffmpeg parameters for each call.
71
            $this->serviceLocator->setShared('playgroundcore_phpvideotoolkit', false);
72
73
            $this->serviceLocator->get('playgroundcore_phpvideotoolkit')
74
            ->addPreInputCommand('-y')
75
            ->addPreInputCommand('-framerate', $framerate)
76
            ->addPreInputCommand('-pattern_type', 'glob')
77
            ->addCommand('-i', $path)
78
            ->addCommand('-c:v', 'libx264')
79
            ->addCommand('-vf', 'fps='. $fps)
80
            ->addCommand('-pix_fmt', 'yuv420p')
81
            ->setOutputPath($target)
82
            ->execute();
83
        } catch (FfmpegProcessOutputException $e) {
84
            throw new \PHPVideoToolkit\InvalidArgumentException('Error when merging videos');
85
        } catch (\PHPVideoToolkit\Exception $e) {
86
            throw new \PHPVideoToolkit\InvalidArgumentException('Error when merging videos');
87
        }
88
89
        return $target;
90
    }
91
92
    /**
93
     * This method create a video from still images (jpg or png).
@@ 97-120 (lines=24) @@
94
     * ffmpeg -framerate 1/5 -i etape%01d.jpg -c:v libx264 -vf "fps=25,format=yuv420p" out.mp4
95
     * ffmpeg -framerate 1/5 -i etape%01d.jpg '-vcodec' 'qtrle' out.mov
96
     */
97
    public function createMovFromAlphaImages($path = 'data/etape*.jpg', $target = false, $framerate = '25', $fps = 25)
98
    {
99
        try {
100
            // don't want this service to be a singleton. I have to reset the ffmpeg parameters for each call.
101
            $this->serviceLocator->setShared('playgroundcore_phpvideotoolkit', false);
102
103
            $this->serviceLocator->get('playgroundcore_phpvideotoolkit')
104
            ->addPreInputCommand('-y')
105
            ->addPreInputCommand('-framerate', $framerate)
106
            //->addPreInputCommand('-start_number', '00154')
107
            ->addPreInputCommand('-pattern_type', 'glob')
108
            ->addCommand('-i', $path)
109
            ->addCommand('-vcodec', 'qtrle')
110
            ->addCommand('-vf', 'fps='. $fps)
111
            ->setOutputPath($target)
112
            ->execute();
113
        } catch (FfmpegProcessOutputException $e) {
114
            throw new \PHPVideoToolkit\InvalidArgumentException('Error when merging videos');
115
        } catch (\PHPVideoToolkit\Exception $e) {
116
            throw new \PHPVideoToolkit\InvalidArgumentException('Error when merging videos');
117
        }
118
119
        return $target;
120
    }
121
122
    /**
123
     * This method takes a mp4 source and transform it to Mpeg (with .ts as extension)