簡體   English   中英

如何將批量圖像實時轉換和壓縮為 mp4 視頻文件?

[英]How can i convert and compress in real time batch of images to mp4 video file?

在我的硬盤目錄中,我有很多圖像: screenshot000001.bmp 、 screenshot000002.bmp ....screenshot001200.bmp

我想做兩件事:

  1. 用於使用 cmd(命令提示符)進行測試並將圖像壓縮並轉換為 mp4 視頻文件。

  2. 在我的程序中,我的程序實時截取屏幕截圖並將它們保存到硬盤中以壓縮它們並實時構建 mp4 視頻文件。

對於第一部分,我嘗試輸入 cmd :

ffmpeg -f image2 -i screenshot%d.bmp -vcodec libx264 -b 800k video.avi

但我得到的是兩個錯誤:

[image2 @ 0000000004766380] 找不到路徑為“screenshot%d.bmp”且索引范圍為 0-4 screenshot%d.bmp 的文件:沒有這樣的文件或目錄

我將 ffmpeg.exe 復制到圖像所在的目錄中。 E:\\screenshots

對於第二部分,我是如何實時截取屏幕截圖的:

啟動計時器的按鈕單擊事件:

private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

然后在滴答事件中:

    ScreenShot shot = new ScreenShot();
    public static int counter = 0;
    private void timer1_Tick(object sender, EventArgs e)
    {
        counter++;
        shot.GetScreenShot(@"e:\screenshots\", "screenshot");
        if (counter == 1200)
        {
            timer1.Stop();
        }
    }

這一行 shot.GetScreenShot(@"e:\\screenshots\\", "screenshot"); 將屏幕截圖保存到硬盤。 在每個屏幕截圖保存后,我想實時壓縮和構建 mp4 視頻文件。

我試過這個並得到錯誤:

ffmpeg -f image2 -i screenshot%06d.bmp -vcodec libx264 -b 800k video.avi

錯誤信息:

ffmpeg version N-73165-gf1e1730 Copyright (
  built with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-vers
isynth --enable-bzlib --enable-fontconfig -
le-iconv --enable-libass --enable-libbluray
enable-libdcadec --enable-libfreetype --ena
ibilbc --enable-libmodplug --enable-libmp3l
le-libopencore-amrwb --enable-libopenjpeg -
able-libschroedinger --enable-libsoxr --ena
ble-libtwolame --enable-libvidstab --enable
 --enable-libvorbis --enable-libvpx --enabl
e-libx264 --enable-libx265 --enable-libxavs
ble-decklink --enable-zlib
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 45.100 / 56. 45.100
  libavformat    56. 38.102 / 56. 38.102
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 18.100 /  5. 18.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
[bmp @ 0000000002f77ce0] bad magic number
    Last message repeated 3 times
[image2 @ 0000000002f76380] decoding for st
[image2 @ 0000000002f76380] Could not find
 bmp, none): unspecified size
Consider increasing the value for the 'anal
screenshot%06d.bmp: could not find codec pa
Input #0, image2, from 'screenshot%06d.bmp'
  Duration: 00:00:02.88, start: 0.000000, b
    Stream #0:0: Video: bmp, none, 25 fps,
Please use -b:a or -b:v, -b is ambiguous
Codec AVOption b (set bitrate (in bits/s))
vi) has not been used for any stream. The m
e (e.g. a video option with no video stream
some encoder which was not actually used fo
Output #0, avi, to 'video.avi':
Output file #0 does not contain any stream

嘗試將screenshot%d.bmp更改為screenshot%06d.bmp

我注意到,您使用的是 Windows 和 .NET,但是如果您不介意安裝 node.js,它有出色的實用程序可以處理轉換過程,node-fluent-ffmpeg 可以為您處理許多輸出選項。

更新:

好的,這是使用視頻編碼器的可悲現實 - 現在有更多問題,大多數問題都在錯誤消息中描述,例如:

嘗試使用-b:v代替-b來指示視頻比特率。

[bmp @ 0000000002f77ce0] bad magic number

很難說這到底意味着什么,但我注意到 ffmpeg 在圖像格式方面非常挑剔。 如果您可以嘗試對圖像運行 convert (ImageMagic) 並將格式更改為 PNG 或 JPEG,它可能會更好地工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM