{"id":100,"date":"2024-03-28T22:07:56","date_gmt":"2024-03-28T14:07:56","guid":{"rendered":"https:\/\/aixiu.shop\/?p=100"},"modified":"2024-03-28T22:08:33","modified_gmt":"2024-03-28T14:08:33","slug":"%e5%85%b3%e4%ba%8eopen-sora-plan%e6%95%b0%e6%8d%ae%e9%9b%86-%e6%b8%85%e6%b4%97%e7%af%87","status":"publish","type":"post","link":"https:\/\/aixiu.shop\/?p=100","title":{"rendered":"\u5173\u4e8eopen sora plan\u6570\u636e\u96c6\u2013\u6e05\u6d17\u7bc7"},"content":{"rendered":"<h1>\u5173\u4e8eopen sora plan\u6570\u636e\u96c6\u2013\u6e05\u6d17\u7bc7<\/h1>\n<h2>\u5220\u9664\u4e0d\u5408\u683c\u5206\u8fa8\u7387\u7684\u89c6\u9891<\/h2>\n<pre><code>import os\nimport subprocess\nimport shlex\n\n# \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u6587\u4ef6\u5b8c\u6574\u6027\ndef is_file_complete(filepath):\n    # \u68c0\u67e5\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u786e\u4fdd\u5b83\u4e0d\u662f\u7a7a\u7684\n    try:\n        return os.path.getsize(filepath) &gt; 0\n    except OSError as e:\n        print(f&quot;Error checking file size: {e}&quot;)\n        return False\n\ndef get_video_resolution(file_path):\n    cmd = (\n        f&quot;ffprobe -v error -select_streams v:0 &quot;\n        f&quot;-show_entries stream=width,height -of csv=s=x:p=0 &#039;{file_path}&#039;&quot;\n    )\n    try:\n        result = subprocess.run(\n            shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True\n        )\n        if result.returncode == 0:\n            output = result.stdout.decode(&#039;utf-8&#039;).strip()\n            # \u5206\u522b\u8d4b\u503c\n            try:\n                parts = output.split(&#039;x&#039;)\n                width = int(parts[0])\n                height = int(parts[1])\n                return width, height\n            except:\n                return 0, 0\n        else:\n            return None\n    except subprocess.CalledProcessError:\n        return None\n\ndef delete_low_resolution_videos(folder_path, min_resolution=720):\n    count_ = 0\n    for root, dirs, files in os.walk(folder_path):\n        for filename in files:\n\n            count_ += 1\n            file_path = os.path.join(root, filename)\n\n            if not is_file_complete(file_path):\n                # \u5982\u679c\u4e0d\u5b8c\u6574\uff0c\u5220\u9664\u89c6\u9891\u6587\u4ef6\u548c\u5bf9\u5e94\u7684\u6587\u672c\u6587\u4ef6\uff08\u5982\u679c\u5b58\u5728\uff09\n                os.remove(file_path)\n\n            #print(f&quot;Checking resolution of {file_path}&quot;)\n            resolution = get_video_resolution(file_path)\n            if resolution:\n                width, height = resolution\n                if (width &lt; min_resolution and height &lt; min_resolution):\n                    print(f&quot;{count_} Deleting low-resolution video file: {file_path}&quot;)\n                    os.remove(file_path)\n            else:\n                print(f&quot;{count_} Skipping non-video file or error reading file: {file_path}&quot;)\n                os.remove(file_path)\n\nif __name__ == &#039;__main__&#039;:\n  # \u6307\u5b9a\u4f60\u7684\u6587\u4ef6\u5939\u8def\u5f84\n  folder_path = r&#039;&#039;\n  delete_low_resolution_videos(folder_path)\n<\/code><\/pre>\n<h2>\u89c6\u9891\u8d28\u91cf\u8bc4\u5206<\/h2>\n<ul>\n<li>\u6e05\u6d17\u6570\u636e<\/li>\n<li>\u53c2\u8003 <a href=\"https:\/\/github.com\/shaodong233\/open-sora-Dataset\">https:\/\/github.com\/shaodong233\/open-sora-Dataset<\/a><\/li>\n<\/ul>\n<h2>\u91cd\u65b0\u5206\u914d\u6587\u4ef6\u5939<\/h2>\n<ul>\n<li>\u5c06\u89c6\u9891\u6587\u4ef6\u5206\u6210\u6bcf5000\u4e2a\u89c6\u9891\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u9632\u6b62\u68c0\u67e5\u89c6\u9891\u5047\u6b7b<\/li>\n<\/ul>\n<pre><code>import os\nimport shutil\nfrom tqdm import tqdm\n\n# \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u6587\u4ef6\u5b8c\u6574\u6027\ndef is_file_complete(filepath):\n    # \u68c0\u67e5\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u786e\u4fdd\u5b83\u4e0d\u662f\u7a7a\u7684\n    try:\n        return os.path.getsize(filepath) &gt; 0\n    except OSError as e:\n        print(f&quot;Error checking file size: {e}&quot;)\n        return False\n\n# \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u6574\u7406\u6587\u4ef6\ndef organize_files(src_folder, dest_folder, files_per_folder=5000):\n    # \u83b7\u53d6\u6e90\u6587\u4ef6\u5939\u4e2d\u6240\u6709\u89c6\u9891\u6587\u4ef6\u7684\u6570\u76ee\n    video_file_count = sum([len(files) for r, d, files in os.walk(src_folder) if any(file.lower().endswith((&#039;.mp4&#039;, &#039;.mov&#039;, &#039;.avi&#039;, &#039;.mkv&#039;, &#039;.wmv&#039;, &#039;.flv&#039;)) for file in files)])\n\n    # \u5982\u679c\u76ee\u6807\u6587\u4ef6\u5939\u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa\u5b83\n    if not os.path.exists(dest_folder):\n        os.makedirs(dest_folder)\n\n    # \u521d\u59cb\u5316\u6587\u4ef6\u5939\u7d22\u5f15\u548c\u6587\u4ef6\u8ba1\u6570\u5668\n    folder_index = 4\n    file_count = 0\n\n    # \u521b\u5efa\u7b2c\u4e00\u4e2a\u76ee\u6807\u5b50\u6587\u4ef6\u5939\n    current_subfolder = os.path.join(dest_folder, f&#039;5000-{folder_index}&#039;)\n    os.makedirs(current_subfolder, exist_ok=True)\n\n    # \u4f7f\u7528tqdm\u521b\u5efa\u8fdb\u5ea6\u6761\n    progress_bar = tqdm(total=video_file_count, unit=&#039;file&#039;)\n\n    # \u5b9a\u4e49\u6709\u6548\u7684\u89c6\u9891\u6587\u4ef6\u6269\u5c55\u540d\n    video_extensions = (&#039;.mp4&#039;, &#039;.mov&#039;, &#039;.avi&#039;, &#039;.mkv&#039;, &#039;.wmv&#039;, &#039;.flv&#039;, &#039;.webm&#039;)\n\n    # \u904d\u5386\u6e90\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u548c\u6587\u4ef6\u5939\n    for root, dirs, files in os.walk(src_folder):\n        for file in files:\n            # \u68c0\u67e5\u5f53\u524d\u6587\u4ef6\u662f\u5426\u4e3a\u89c6\u9891\u6587\u4ef6\n            if file.lower().endswith(video_extensions):\n                try:\n                    # \u83b7\u53d6\u4e0d\u5e26\u6269\u5c55\u540d\u7684\u6587\u4ef6\u540d\n                    base_name = os.path.splitext(file)[0]\n                    # \u6784\u5efa\u89c6\u9891\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\n                    video_path = os.path.join(root, file)\n                    # \u6784\u5efa\u76f8\u5e94\u7684\u6587\u672c\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\n                    txt_path = os.path.join(root, f&#039;{base_name}.txt&#039;)\n\n                    # \u68c0\u67e5\u89c6\u9891\u6587\u4ef6\u662f\u5426\u5b8c\u6574\n                    if not is_file_complete(video_path):\n                        # \u5982\u679c\u4e0d\u5b8c\u6574\uff0c\u5220\u9664\u89c6\u9891\u6587\u4ef6\u548c\u5bf9\u5e94\u7684\u6587\u672c\u6587\u4ef6\uff08\u5982\u679c\u5b58\u5728\uff09\n                        os.remove(video_path)\n                        if os.path.exists(txt_path):\n                            os.remove(txt_path)\n                        print(f&#039;Removed incomplete files: {video_path} and corresponding txt file&#039;)\n                        continue  # \u8df3\u8fc7\u5f53\u524d\u5faa\u73af\uff0c\u5904\u7406\u4e0b\u4e00\u4e2a\u6587\u4ef6\n\n                    # \u5982\u679c\u5f53\u524d\u6587\u4ef6\u5939\u5185\u7684\u6587\u4ef6\u6570\u91cf\u5df2\u8fbe\u5230\u4e0a\u9650\uff0c\u5219\u521b\u5efa\u65b0\u7684\u5b50\u6587\u4ef6\u5939\n                    if file_count &gt;= files_per_folder:\n                        folder_index += 1\n                        current_subfolder = os.path.join(dest_folder, f&#039;5000-{folder_index}&#039;)\n                        os.makedirs(current_subfolder, exist_ok=True)\n                        file_count = 0  # \u4e3a\u65b0\u6587\u4ef6\u5939\u91cd\u7f6e\u6587\u4ef6\u8ba1\u6570\u5668\n\n                    # \u79fb\u52a8\u89c6\u9891\u6587\u4ef6\u5230\u5f53\u524d\u5b50\u6587\u4ef6\u5939\n                    dest_video_path = os.path.join(current_subfolder, file)\n                    shutil.move(video_path, dest_video_path)\n                    file_count += 1  # \u66f4\u65b0\u6587\u4ef6\u8ba1\u6570\u5668\n\n                    # \u5982\u679c\u76f8\u5e94\u7684\u6587\u672c\u6587\u4ef6\u5b58\u5728\uff0c\u5219\u4e00\u5e76\u79fb\u52a8\n                    if os.path.exists(txt_path):\n                        dest_txt_path = os.path.join(current_subfolder, f&#039;{base_name}.txt&#039;)\n                        shutil.move(txt_path, dest_txt_path)\n\n                    # \u66f4\u65b0\u8fdb\u5ea6\u6761\n                    progress_bar.update(1)\n\n                except Exception as e:\n                    print(f&quot;Error processing file {file}: {e}&quot;)\n\n    # \u5173\u95ed\u8fdb\u5ea6\u6761\n    progress_bar.close()\n\nif __name__ == &#039;__main__&#039;:\n    # \u6307\u5b9a\u6e90\u76ee\u5f55\uff0c\u5305\u542b\u539f\u59cb\u6587\u4ef6\n    source_directory = r&#039;&#039;\n    # \u6307\u5b9a\u76ee\u6807\u76ee\u5f55\uff0c\u6574\u7406\u540e\u7684\u6587\u4ef6\u5c06\u88ab\u653e\u7f6e\u5728\u8fd9\u91cc\n    destination_directory = r&#039;&#039;\n\n    # \u8c03\u7528\u51fd\u6570\uff0c\u5f00\u59cb\u6587\u4ef6\u6574\u7406\u8fc7\u7a0b\n    organize_files(source_directory, destination_directory)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8eopen sora plan\u6570\u636e\u96c6\u2013\u6e05\u6d17\u7bc7 \u5220\u9664\u4e0d\u5408\u683c\u5206\u8fa8\u7387\u7684\u89c6\u9891 import os import su [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"topic":[],"_links":{"self":[{"href":"https:\/\/aixiu.shop\/index.php?rest_route=\/wp\/v2\/posts\/100"}],"collection":[{"href":"https:\/\/aixiu.shop\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aixiu.shop\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aixiu.shop\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aixiu.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":2,"href":"https:\/\/aixiu.shop\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/aixiu.shop\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/aixiu.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aixiu.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aixiu.shop\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/aixiu.shop\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}