Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在OS X bash的时间码中关闭冒号_Bash_Video_Sed_Ffmpeg_Timecodes - Fatal编程技术网

如何在OS X bash的时间码中关闭冒号

如何在OS X bash的时间码中关闭冒号,bash,video,sed,ffmpeg,timecodes,Bash,Video,Sed,Ffmpeg,Timecodes,我尝试使用ffmpeg生成视频,显示源视频的老化时间码。我正在OSX中使用bash脚本。 视频1的开始时间代码为09:59:30:00 为了在ffmpeg中使用drawtext过滤器,我需要关闭冒号,因为它们用于分隔过滤器 它们需要在脚本timecode='00 \:00 \:00 \:00'中采用这种格式,并且它们最终会在实际的终端窗口中显示为这样:timecode='\''00 \:00 \:00'\'' 是否有某种方法可以使用sed或awk或类似的方法转换$timecode变量中存储的值

我尝试使用ffmpeg生成视频,显示源视频的老化时间码。我正在OSX中使用bash脚本。 视频1的开始时间代码为09:59:30:00

为了在ffmpeg中使用drawtext过滤器,我需要关闭冒号,因为它们用于分隔过滤器

它们需要在脚本
timecode='00 \:00 \:00 \:00'
中采用这种格式,并且它们最终会在实际的终端窗口中显示为这样:
timecode='\''00 \:00 \:00'\''

是否有某种方法可以使用sed或awk或类似的方法转换$timecode变量中存储的值

我正在使用ffprobe生成时间码,并将其作为变量添加

$ timecode=($(ffprobe -v error -show_entries format_tags=timecode -of default=noprint_wrappers=1:nokey=1 "$1" ))
$ echo $timecode
09:59:30:00
当我以这种方式将变量$timecode添加到脚本中时:

ffmpeg -i "$1" -c:v libx264 -crf 23 -pix_fmt yuv420p -vf drawtext="fontsize=45":"fontfile=/Library/Fonts/Arial\ Black.ttf:fontcolor=white:timecode="$timecode":rate=$framerate:boxcolor=0x000000AA:box=1:x=360-text_w/2:y=480" ""$mezzanine"/"$filenoext"_PRORES.mov"
当我使用bash-x时,时间代码显示为未关闭状态:

+ ffmpeg -i /Users/kieranoleary/Downloads/AS11_DPP_HD_OEM_SAMPLE_136_1.mxf -c:v libx264 -crf 23 -pix_fmt yuv420p -vf 'drawtext=fontsize=45:fontfile=/Library/Fonts/Arial\ Black.ttf:fontcolor=white:timecode=09:59:30:00:rate=25/1:boxcolor=0x000000AA:box=1:x=360-text_w/2:y=480' /Users/kieranoleary/Downloads/AS11_DPP_HD_OEM_SAMPLE_136_1/mezzanine/AS11_DPP_HD_OEM_SAMPLE_136_1_PRORES.mov
我得到以下错误:

[Parsed_drawtext_0 @ 0x7f9dc242e360] Both text and text file provided. Please provide only one
[AVFilterGraph @ 0x7f9dc242e4e0] Error initializing filter 'drawtext' with args 'fontsize=45:fontfile=/Library/Fonts/Arial Black.ttf:fontcolor=white:timecode=09:59:30:00:rate=25/1:boxcolor=0x000000 A:box=1:x=360-text_w/2:y=480'
Error opening filters!

我会尝试以下方法:

$ IFS=: read -a timecode < <(ffprobe -v error -show_entries format_tags=timecode -of default=noprint_wrappers=1:nokey=1 "$1" )
$ printf -v timecode '%s\:%s\:%s\:%s' "${timecode[@]}"
$ echo "$timecode"
09\:59\:30\:00
您可以使用另一个数组作为中间变量,以使命令调用更具可读性:

drawtext_options=(
    fontsize=45
    fontfile="/Library/Fonts/Arial Black.ttf"
    fontcolor=white
    timecode="$timecode"
    rate="$framerate"
    boxcolor=0x000000AA
    box=1
    x=360-text_w/2
    y=480
)

drawtext_options=$(IFS=:; echo "${drawtext_options[*]}")
ffmpeg -i "$1" -c:v libx264 -crf 23 -pix_fmt yuv420p -vf \
    drawtext="$drawtext_options" \
    "$mezzanine/${filenoext}_PRORES.mov"

感谢您提供如此详细的答案,您的数组更加可读和优雅。然而,我仍然有同样的问题。您的脚本会导致相同的错误,实际终端窗口中会显示
timecode=09 \:59 \:30 \:00
。一旦手动将脚本中的终端输出重命名为
timecode='\''09 \:59 \:30 \:00'\''
,我就可以打印时间码了。我只需要将时间码行用双引号括起来,一切都很好。非常感谢你!
drawtext_options=(
    fontsize=45
    fontfile="/Library/Fonts/Arial Black.ttf"
    fontcolor=white
    timecode="$timecode"
    rate="$framerate"
    boxcolor=0x000000AA
    box=1
    x=360-text_w/2
    y=480
)

drawtext_options=$(IFS=:; echo "${drawtext_options[*]}")
ffmpeg -i "$1" -c:v libx264 -crf 23 -pix_fmt yuv420p -vf \
    drawtext="$drawtext_options" \
    "$mezzanine/${filenoext}_PRORES.mov"