Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
Merge video and overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
mgp25 committed Sep 4, 2015
1 parent ca3e6ec commit 5defada
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/snapchat.php
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,11 @@ function writeToFile($path, $data)

if($ext != null)
{
rename($path, $path . $ext);
$newFile = $path . $ext;
rename($path, $newFile);
}

return $newFile;
}

/**
Expand Down Expand Up @@ -2519,7 +2522,7 @@ public function getStory($media_id, $key, $iv, $from, $timestamp, $save = FALSE,
{
mkdir($path, 0777, true);
}
$file = $path . DIRECTORY_SEPARATOR . date("Y-m-d H-i-s", (int) ($timestamp / 1000)) . "-story-" . $media_id;
$file = $path . DIRECTORY_SEPARATOR . date("Y-m-d-H-i-s", (int) ($timestamp / 1000)) . "-story-" . $media_id;
$extensions = array(".jpg", ".png", ".mp4", "");
foreach ($extensions as $ext)
{
Expand All @@ -2546,13 +2549,27 @@ public function getStory($media_id, $key, $iv, $from, $timestamp, $save = FALSE,
{
if(is_array($result))
{
$files = array();
foreach ($result as &$value)
{
if(!file_exists($file))
{
$this->writeToFile($file, $value);
$newFile = $this->writeToFile($file, $value);
$files[] = $newFile;
}
}
$output = array();
$returnvalue = false;
exec('ffmpeg -version', $output, $returnvalue);
if ($returnvalue === 0)
{
$videoSize = shell_exec("ffprobe -v error -select_streams v:0 -show_entries stream=width,height \-of default=nokey=1:noprint_wrappers=1 $files[0]");
$videoSize = array_filter(explode("\n", $videoSize));

shell_exec("ffmpeg -y -i $files[1] -vf scale=$videoSize[0]:$videoSize[1] $files[1]");
shell_exec("ffmpeg -y -i $files[0] -i $files[1] -strict -2 -filter_complex overlay -c:a copy -flags global_header $files[0]");
unlink($files[1]);
}
}
else
{
Expand Down

1 comment on commit 5defada

@emiliobasualdo
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Please sign in to comment.