How to create a video from frames named using timestamp with ffmpeg

a 夏天 提交于 2021-01-28 08:22:11

问题


I have a folder filled with frames that have the timestamp in the name in the folowing format

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

I try to use -pattern_type glob in windows but it does not work.

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

I get

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

later I found that this do not work on windows :( which is what I am using. ffmpeg Error: Pattern type 'glob' was selected but globbing is not support ed by this libavformat build

I also try

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

I got

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

I am running out of ideas. I refuse to believe that there is no way to do this in ffmpeg and powershell. I really appreciate any help!


回答1:


You can use a workaround, via the concat demuxer

Create a text file with the list of filenames in order

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

and then run

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

(this will produce warnings about invalid DTS but you can ignore them)




回答2:


Building on Mulvya solution I wrote a powershell script that will create the txt with filename in the suggested format.

  1. Create a txt file with directory png content

    $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
    

I added the Encoding on the Out-File cmdlet, since the default is UTF-8-BOM and ffmpeg does not like it.

  1. Pre-append the string "file " to each line of the txt file.

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

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

Steps 1. and 2. will not produce a txt file with fullpath names. Only the names. This is why we need to cd to the folder.



来源:https://stackoverflow.com/questions/47935195/how-to-create-a-video-from-frames-named-using-timestamp-with-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!