【问题标题】:How to create a video from frames named using timestamp with ffmpeg如何从使用带有 ffmpeg 的时间戳命名的帧创建视频
【发布时间】:2017-12-22 02:33:06
【问题描述】:

我有一个文件夹,其中包含名称中带有时间戳的帧,格式如下

im_%H_%M_%S_%MS.png

im_08_05_09_007324.png
im_08_05_09_532857.png
im_08_05_10_059340.png
im_08_05_10_575862.png
im_08_05_11_118361.png
im_08_05_11_596814.png
im_08_05_12_148340.png
im_08_05_12_665838.png

我尝试在 Windows 中使用-pattern_type glob,但它不起作用。

ffmpeg.exe -framerate 10 -pattern_type glob -i im_*.png -c:v libx264 -r 30 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"  -pix_fmt yuv420p $videoName

我明白了

 Pattern type 'glob' was selected but globbing is not supported by this libavformat build im_*.png: Function not implemented

后来我发现这在 Windows 上不起作用:(这是我正在使用的。ffmpeg Error: Pattern type 'glob' was selected but globbing is not support ed by this libavformat build

我也试试

ffmpeg.exe -framerate 10 -pattern_type glob -i im_%02d_%02d_%02d_%06d.png -c:v libx264 -r 30 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"  -pix_fmt yuv420p $videoName

我明白了

im_%02d_%02d_%02d_%06d.png: No such file or directory

我的想法不多了。我拒绝相信在 ffmpeg 和 powershell 中没有办法做到这一点。 非常感谢任何帮助!

【问题讨论】:

    标签: powershell video ffmpeg mp4 strftime


    【解决方案1】:

    在 Mulvya 解决方案的基础上,我编写了一个 powershell 脚本,该脚本将使用建议格式的文件名创建 txt。

    1. 创建一个带有目录png内容的txt文件

      $inFolder = "C:\my_folder_with_Png_frames\"
      $inSearch = $inFolder+"*.png"
      $outFile  = $inFolder + "framenames.txt"
      Get-childitem -path $inSearch -recurse -name | Out-File $outFile -Encoding ASCII
      

    我在 Out-File cmdlet 上添加了Encoding,因为默认值为UTF-8-BOMffmpeg 不喜欢它。

    1. 将字符串“file”预先附加到 txt 文件的每一行。

      $prependVar = "file "
      $lines      = get-content $outFile
      $newlines   = $lines | ForEach-Object{ "$prependVar$_"}
      $newlines | Out-File $outFile -Encoding ASCII
      
    2. 调用 FFMPEG

       cd $inFolder
       C:/ffmpeg/bin.\ffmpeg.exe -f concat -r 10 -i $outFile -c:v libx264 -r 30  -pix_fmt yuv420p out.mp4
      

    步骤 1. 和 2. 不会​​生成具有完整路径名称的 txt 文件。只有名字。这就是为什么我们需要cd 到该文件夹​​。

    【讨论】:

    • 嘿,我正在尝试做一些类似于你在这里的事情,它正在以某种方式读取我的文件名'file myjpegfile.jpg'。我收到一个错误“无法打开文件'Dmyjpegfile.jpg”由于某种原因它附加在一个不存在的'D'上。我猜这是格式问题,但我使用的是 ASCII 编码,所以我不确定是什么原因造成的。
    【解决方案2】:

    您可以通过 concat demuxer 使用解决方法

    按顺序创建一个包含文件名列表的文本文件

    file im_08_05_09_007324.png
    file im_08_05_09_532857.png
    file im_08_05_10_059340.png
    file im_08_05_10_575862.png
    file im_08_05_11_118361.png
    

    然后运行

    ffmpeg -f concat -r 10 -i list.txt -c:v libx264 ...
    

    (这将产生有关无效 DTS 的警告,但您可以忽略它们)

    【讨论】:

    • 非常感谢!!对不起我迟到的答案。那天我很着急,决定用 Fiji imageJ 制作视频。但是,现在我需要创建很多视频,我发现创建脚本的必要性。根据您的回答,我编写了完整的解决方案。
    猜你喜欢
    • 2019-02-03
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2019-10-21
    • 2012-12-22
    • 2017-07-02
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多