{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import json\n", "import torch\n", "import os\n", "import imageio" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "# path = \"/data3/guanjunwu/project_scp/TiNeuVox/logs/interp_data/interp/chicken/render_test_fine_last\"\n", "path = \"output/hypernerf4/interp/americano/test/ours_14000/renders\"\n", "# \n", "# path = \"output/dynamic3dgs/dynamic3dgs/basketball/test/ours_30000/renders\"\n", "image_list = os.listdir(path)\n", "len_image = len(image_list)\n", "tile = image_list[0].split('.')[-1]" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "import re\n", "def sort_numeric_filenames(filenames):\n", " \"\"\"\n", " Sort a list of filenames based on the numeric part of the filename.\n", " Assumes filenames have a format like '0000.png', '0001.png', etc.\n", " \"\"\"\n", " def extract_number(filename):\n", " # 使用正则表达式提取文件名中的数字\n", " match = re.search(r'\\d+', filename)\n", " return int(match.group()) if match else 0\n", "\n", " # 使用提取的数字进行排序\n", " return sorted(filenames, key=extract_number)\n", "\n", "# 示例文件名列表\n", "filenames = image_list\n", "\n", "# 进行排序\n", "sorted_filenames = sort_numeric_filenames(filenames)\n", "sorted_filenames = [i for i in sorted_filenames if 'png' in i]" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['000.png',\n", " '001.png',\n", " '002.png',\n", " '003.png',\n", " '004.png',\n", " '005.png',\n", " '006.png',\n", " '007.png',\n", " '008.png',\n", " '009.png',\n", " '010.png',\n", " '011.png',\n", " '012.png',\n", " '013.png',\n", " '014.png',\n", " '015.png',\n", " '016.png',\n", " '017.png',\n", " '018.png',\n", " '019.png',\n", " '020.png',\n", " '021.png',\n", " '022.png',\n", " '023.png',\n", " '024.png',\n", " '025.png',\n", " '026.png',\n", " '027.png',\n", " '028.png',\n", " '029.png',\n", " '030.png',\n", " '031.png',\n", " '032.png',\n", " '033.png',\n", " '034.png',\n", " '035.png',\n", " '036.png',\n", " '037.png',\n", " '038.png',\n", " '039.png',\n", " '040.png',\n", " '041.png',\n", " '042.png',\n", " '043.png',\n", " '044.png',\n", " '045.png',\n", " '046.png',\n", " '047.png',\n", " '048.png',\n", " '049.png',\n", " '050.png',\n", " '051.png',\n", " '052.png',\n", " '053.png',\n", " '054.png',\n", " '055.png',\n", " '056.png',\n", " '057.png',\n", " '058.png',\n", " '059.png',\n", " '060.png',\n", " '061.png',\n", " '062.png',\n", " '063.png',\n", " '064.png',\n", " '065.png',\n", " '066.png',\n", " '067.png',\n", " '068.png',\n", " '069.png',\n", " '070.png',\n", " '071.png',\n", " '072.png',\n", " '073.png',\n", " '074.png',\n", " '075.png',\n", " '076.png',\n", " '077.png',\n", " '078.png',\n", " '079.png',\n", " '080.png',\n", " '081.png',\n", " '082.png',\n", " '083.png',\n", " '084.png',\n", " '085.png',\n", " '086.png',\n", " '087.png',\n", " '088.png',\n", " '089.png',\n", " '090.png',\n", " '091.png',\n", " '092.png',\n", " '093.png',\n", " '094.png',\n", " '095.png',\n", " '096.png',\n", " '097.png',\n", " '098.png',\n", " '099.png',\n", " '100.png',\n", " '101.png',\n", " '102.png',\n", " '103.png',\n", " '104.png',\n", " '105.png',\n", " '106.png',\n", " '107.png',\n", " '108.png',\n", " '109.png',\n", " '110.png',\n", " '111.png',\n", " '112.png']" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sorted_filenames" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/data/guanjunwu/disk2/miniconda3/envs/Gaussians4D/lib/python3.7/site-packages/ipykernel_launcher.py:6: DeprecationWarning: Starting with ImageIO v3 the behavior of this function will switch to that of iio.v3.imread. To keep the current behavior (and make this warning disappear) use `import imageio.v2 as imageio` or call `imageio.v2.imread` directly.\n", " \n", "IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (536, 960) to (544, 960) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).\n", "[swscaler @ 0x67a2580] Warning: data is not aligned! This can lead to a speed loss\n" ] } ], "source": [ "writer = imageio.get_writer(os.path.join(path,\"video111.mp4\"),fps=10)\n", "video_num = 1\n", "video_list = [[] for i in range(video_num)]\n", "for i, image in enumerate(sorted_filenames):\n", " if i % video_num == 0:\n", " image = imageio.imread(os.path.join(path,image))\n", " writer.append_data(image)\n", "writer.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install imageio[ffmpeg]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.16" } }, "nbformat": 4, "nbformat_minor": 2 }