【问题标题】:escape single qoute in ffmpeg filename varible php在ffmpeg文件名变量php中转义单引号
【发布时间】:2017-04-05 15:10:44
【问题描述】:

代码可以正常工作,但如果文件名只有一个 qoute,就像“Britney's video.mp4”一样,它就不起作用。

$ffmpeg = "/usb/bin/local/ffmpeg";
$videos = "/videos/*.mp4";
$ouput_path = "/videos/thumbnails/";


foreach(glob($videos) as $video_file){

$lfilename = basename($video_file);
$filename = basename($video_file, ".mp4");
$thumbnail = $ouput_path.$filename.'.jpg';
if (!file_exists($filename)) {
#$thumbnail = str_replace("'", "%27", $thumbnail);
exec("/usr/local/bin/ffmpeg -i '$video_file' -an -y -f mjpeg -ss 00:00:30 -vframes 1 '$thumbnail'");
}
echo "<a href='$lfilename'>$filename<img src='thumbnails/$filename.jpg' width='350'>";

【问题讨论】:

  • 您可以在$video_file 和$thumbnail 上使用php.net/manual/en/function.escapeshellarg.php。
  • 谢谢,我不知道如何使用或放置它。只是看起来过于复杂..
  • 是否点击了提供的链接?它解释了它的作用。 escapeshellarg() adds single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument.
  • 感谢我确实访问过它,但我不知道把它放在哪里......或如何。
  • 您了解手册页的内容/您的代码在做什么吗?你挂在哪儿了?

标签: php ffmpeg escaping


【解决方案1】:

按照 cmets 中的建议,您可以将所有 shell-command 字符串包装在 escapeshellarg() 中,如下所示。

<?php

    foreach(glob($videos) as $video_file){
        $lfilename = basename($video_file);
        $filename  = basename($video_file, ".mp4");
        $thumbnail = $ouput_path.$filename.'.jpg';

        if (!file_exists($filename)) {
            $cmd         = "/usr/local/bin/ffmpeg -i ";
            $cmd        .= $video_file . " -an -y -f mjpeg -ss 00:00:30 ";
            $cmd        .= "-vframes 1 " . $thumbnail;

            exec( escapeshellarg($cmd) );
        }

【讨论】:

  • 如果我将 escapeshellarg 删除到 exec(($cmd));它可以工作,但仍然不适用于带有 ' 的文件名,例如 Britney's Video
  • 我使用 $comd = "/usr/local/bin/ffmpeg -i \"$video_file\" -y -f mjpeg -ss 00:00:30 -vframes 1 \" 让它工作了$缩略图\" 2>&1"; shell_exec($comd);
  • 但是我怎样才能使它成为 glob mp4s,avi 而不仅仅是 mp4?谢谢
【解决方案2】:

我让它工作但没有使用过于复杂的东西。 谢谢大家

$comd = "/usr/local/bin/ffmpeg -i \"$video_file\" -y -f mjpeg -ss 00:00:30 -vframes 1 \"$thumbnail\" 2>&1"; shell_exec($comd);
shell_exec($comd);

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多