[英]How to create a video from frames named using timestamp with ffmpeg
我有一個文件夾,里面裝滿了名稱中帶有時間戳的幀,格式如下
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 錯誤:選擇了模式類型“glob”但此 libavformat 版本不支持 globbing
我也試試
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 中沒有辦法做到這一點。 我真的很感激任何幫助!
您可以通過 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 的警告,但您可以忽略它們)
基於 Mulvya 解決方案,我編寫了一個 powershell 腳本,它將以建議的格式創建帶有文件名的 txt。
用目錄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-BOM
而ffmpeg
不喜歡它。
將字符串“file”預先附加到 txt 文件的每一行。
$prependVar = "file " $lines = get-content $outFile $newlines = $lines | ForEach-Object{ "$prependVar$_"} $newlines | Out-File $outFile -Encoding ASCII
調用 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
到文件夾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.