コード例 #1
0
ファイル: locallib.php プロジェクト: e-lang/moodle-mod_elang
/**
 * Detect and transcode encoding of a string into UTF-8 or another given encoding (using iconv instead the less reliable mb_convert_encoding)
 *
 * @param   string  $contents      the string to be analysed and to be converted (as reference)
 * @param   string  $encoding_to   the target encoding
 * @param   string  $detect_order  the list of encodings in a specicific order
 *
 * @return  string  the new content
 *
 * @since  1.1.0
 *
 * @author  Ralf Erlebach
 */
function transcodeSubtitle($contents, $encoding_to = 'UTF-8', $detect_order = null)
{
    // $encoding_to is explicitely given as null, there is nothing to do
    if (!$encoding_to) {
        return $contents;
    }
    // Get the detect order
    if ($detect_order == null) {
        $detect_order = getEncodings();
    }
    if (function_exists('mb_detect_encoding')) {
        $encoding = mb_detect_encoding($contents, $detect_order, true);
    } else {
        // Set the assumed encoding of the string as false
        $encoding = false;
        // Detect bom for different encodings and strip it from the string
        $bom_encoding = array('UTF-32BE' => pack("CCCC", 0x0, 0x0, 0xfe, 0xff), 'UTF-32LE' => pack("CCCC", 0xff, 0xfe, 0x0, 0x0), 'GB-18030' => pack("CCCC", 0x84, 0x31, 0x95, 0x33), 'UTF-8' => pack("CCC", 0xef, 0xbb, 0xbf), 'UTF-16BE' => pack("CC", 0xfe, 0xff), 'UTF-16LE' => pack("CC", 0xff, 0xfe));
        foreach ($bom_encoding as $enc => $bom) {
            if (0 == strncmp($contents, $bom, strlen($bom))) {
                $contents = substr($contents, strlen($bom));
                $encoding = $enc;
                break;
            }
        }
        if (!$encoding) {
            // Convert to md5 for fast comparison
            $md5 = md5($contents);
            // Try to detect concurrent encoding and convert into UTF-8
            foreach ($detect_order as $enc) {
                if ($md5 === md5(@iconv($enc, $enc, $contents))) {
                    $encoding = $enc;
                    break;
                }
            }
        }
    }
    // Convert the encoding
    if ($encoding) {
        return iconv($encoding, $encoding_to . '//IGNORE', $contents);
    } else {
        return false;
    }
}
コード例 #2
0
ファイル: convert_videos.php プロジェクト: humor-zo/chaofan
    $vinfo['Video_FrameRate'] = 29.97;
}
// Assign $ofps Value
$ofps = " -ofps " . $vinfo['Video_FrameRate'];
// Assign $keyint Value
$keyint = round($vinfo['Video_FrameRate'] * 8);
// Assign $demuxer Value
if ($vinfo['General_Format'] == "MPEG-4") {
    $demuxer = " -demuxer lavf";
}
// Display Details
echo "\n" . $nl . "Encoder Details\n" . $nl;
echo "\$video_type = {$video_type}\n";
echo "\$aspect = {$aspect}\n";
echo "\$vinfo['Original_Width'] = " . $vinfo['Original_Width'] . "{$original_width}\n";
echo "\$vinfo['Video_Width'] = " . $vinfo['Video_Width'] . "\n";
echo "\$mc = {$mc}\n";
echo "\$lavfopts = {$lavfopts}\n";
echo "\$ofps = {$ofps}\n";
echo "\$demuxer = {$demuxer}\n";
echo "\$keyint = {$keyint}\n\n";
// Get Encoder
$encodings = getEncodings($video_type, $aspect, $vinfo, $hd_overwrite);
foreach ($encodings as $encoding) {
    convert($encoding, $vinfo, $vid, $vdo_path, $vdoname, $keyint, $lavfopts, $ofps, $mc, $demuxer, $aspect);
}
postThumbs($vid, $vdo_path);
postConversion($vid, $vdo_path);
// Display :: Encoder Core End
echo "\n<-- End of Script -->\n\n";
exit;