Skip to content

Instantly share code, notes, and snippets.

@radist2s
Last active February 22, 2021 15:59
Show Gist options
  • Save radist2s/830e4a222842a97fbe4b to your computer and use it in GitHub Desktop.
Save radist2s/830e4a222842a97fbe4b to your computer and use it in GitHub Desktop.
Jaksta youtube WEBM video encoding fix (Bash and PHP versions of script)
Yoy should use only one of above files.
Scripts writen in different languages, but do the same work. Of course, for using ffmpeg.php you must have instlalled php.
Go to Jaksta ffmpeg dir:
# cd /Applications/Jaksta.app/Contents/Frameworks/ShedConverter.framework/Versions/A/Resources/
Rename original ffmpeg. Just store it. It never be used.
# mv ffmpeg ffmpeg-jaksta-origin
Download last release of ffmpeg http://ffmpegmac.net/ and unpack it. For example new ffmpeg binary will be in ~/Downloads/ffmpeg
Copy new ffmpeg bynary to Jaksta directory as ffmpeg-bin(we still in Jaksta ffmpeg directory)
# cp ~/Downloads/ffmpeg ffmpeg-bin
Copy on of above files to /Applications/Jaksta.app/Contents/Frameworks/ShedConverter.framework/Versions/A/Resources/. For example, file in ~/Downloads/ffmpeg.sh
# cp ~/Downloads/ffmpeg.sh /Applications/Jaksta.app/Contents/Frameworks/ShedConverter.framework/Versions/A/Resources/ffmpeg
So, we must have files:
/Applications/Jaksta.app/Contents/Frameworks/ShedConverter.framework/Versions/A/Resources/ffmpeg
/Applications/Jaksta.app/Contents/Frameworks/ShedConverter.framework/Versions/A/Resources/ffmpeg-bin
When Jaksta run task to join splitted sources, our ffmpeg transfer fixed arguments to ffmpeg bynary.
#!/usr/bin/php
<?
// Rename this file to ffmpeg (without extention)
$dir = __DIR__;
$ffmpeg_bin = 'ffmpeg-bin';
setlocale(LC_CTYPE, 'ru_RU.UTF-8');
/*
Array
(
[0] => ./filter
[1] => -y
[2] => -i
[3] => stream_video.webm
[4] => -i
[5] => steam_audio.webm
[6] => -map
[7] => 0:v:0
[8] => -map
[9] => 1:a:0
[10] => -c:0
[11] => copy
[12] => -c:1
[13] => copy
[14] => output.webm
)
*/
$args = $argv;
$args[0] = false;
if ($args AND preg_match('~.webm$~iu', $args[count($args) - 1]))
{
if (isset($args[12]) AND $args[12] === '-c:1' AND isset($args[13]) AND $args[13] === 'copy')
{
$args[12] = false;
$args[13] = false;
$args = array_filter($args);
}
}
$args = array_filter($args, function(&$arg) {
return $arg ? $arg = escapeshellarg($arg) : null;
});
array_unshift($args, escapeshellcmd($dir . '/' . $ffmpeg_bin));
$argulments = implode($args, ' ');
exec($argulments);
if (is_file('ff.log'))
{
unlink('ff.log');
}
// Log
// file_put_contents(__DIR__ . '/ff.log', $argulments . PHP_EOL . $exec_result . PHP_EOL, FILE_APPEND);
echo $exec_result;
#!/bin/sh
# Rename this file to ffmpeg (without extention)
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
FFMPEG_BIN="$DIR/ffmpeg-bin"
for LAST; do true; done
OUT_FILE_IS_WEBM=$(echo $LAST | grep -e [.]webm$)
if [ ! -n "$OUT_FILE_IS_WEBM" ]
then
# echo NOT WEBM
$FFMPEG_BIN "${@}"
exit 0
fi
index=1
args=()
for arg in "$@"
do
if [[ "$index" -eq "12" && "$arg" == "-c:1" ]] || [[ "$index" -eq "13" && "$arg" == "copy" ]];
then
args=$args
else
args+=("$arg")
fi
let "index+=1"
done
$FFMPEG_BIN "${args[@]}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment