provide an ffmpeg command to split mp4 hdr h256 video into uncompressed png files. each…
- User
provide an ffmpeg command to split mp4 hdr h256 video into uncompressed png files. each png batch must be in folder named as the video
Assistant
To split an MP4 HDR H.265 (HEVC) video into uncompressed PNG files using FFmpeg, and ensure that each batch of PNG files is stored in a folder named after the video file, you can use the following command:
Command:
ffmpeg -i "input_video.mp4" -vf "fps=30" -compression_level 0 "output_folder/%04d.png"Explanation of the command:
-
-i "input_video.mp4":- Specifies the input video file (
input_video.mp4).
- Specifies the input video file (
-
-vf "fps=30":- Sets the frame rate for extraction. In this example,
fps=30extracts 30 frames per second. You can adjust this value based on your needs.
- Sets the frame rate for extraction. In this example,
-
-compression_level 0:- Ensures that the PNG files are saved with no compression (uncompressed). This is the highest quality setting for PNG output.
-
"output_folder/%04d.png":- Specifies the output file naming pattern.
%04dmeans the frames will be numbered with 4 digits (e.g.,0001.png,0002.png, etc.). Replaceoutput_folderwith the name of the folder where the PNG files will be saved.
- Specifies the output file naming pattern.
Automating Folder Creation:
To automate the creation of a folder named after the video file, you can use a shell script. Here's an example script for Linux/macOS:
#!/bin/bash # Input video file input_video="input_video.mp4" # Extract the base name of the video file (without extension) video_name=$(basename "$input_video" .mp4) # Create a folder named after the video file mkdir -p "$video_name" # Run FFmpeg to extract frames into the folder ffmpeg -i "$input_video" -vf "fps=30" -compression_level 0 "$video_name/%04d.png"Steps to Use the Script:
- Save the script to a file, e.g.,
extract_frames.sh. - Make the script executable:
chmod +x extract_frames.sh - Run the script:
./extract_frames.sh
Notes:
- Replace
input_video.mp4with the actual name of your video file. - The
fps=30option can be adjusted to match the frame rate of your video or your desired extraction rate. - If the video uses HDR (High Dynamic Range), FFmpeg will automatically preserve the color information when exporting to PNG.
Final Answer:
The FFmpeg command to split an MP4 HDR H.265 video into uncompressed PNG files, with each batch stored in a folder named after the video, is:
ffmpeg -i "input_video.mp4" -vf "fps=30" -compression_level 0 "output_folder/%04d.png"And the folder creation can be automated using the provided shell script.
-
- User
fix the error
Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 com.xiaomi.pro_video: 24 com.android.version: 15 com.android.manufacturer: Xiaomi com.android.model: 23127PN0CG com.xiaomi.product.marketname: Xiaomi 14 com.android.capture.fps: 24.000000 com.xiaomi.ai_audio: 1 com.xiaomi.real_8k: 1 com.xiaomi.preview_video_cover: 1 encoder : Lavf61.7.100 Stream #0:0(eng): Video: png, rgb24(pc, gbr/bt709/bt709, progressive), 7680x4320, q=2-31, 200 kb/s, 24 fps, 24 tbn (default) Metadata: creation_time : 2025-07-10T14:11:11.000000Z handler_name : VideoHandle vendor_id : [0][0][0][0] encoder : Lavc61.19.101 png [image2 @ 00000134bf627600] Could not open file : VID_20250710_171055_8K.mp4/0001.png [vost#0:0/png @ 00000134bf10d000] Error submitting a packet to the muxer: I/O error Last message repeated 1 times [out#0/image2 @ 00000134bf1251c0] Error muxing a packet [out#0/image2 @ 00000134bf1251c0] Task finished with error code: -5 (I/O error) [out#0/image2 @ 00000134bf1251c0] Terminating thread with return code -5 (I/O error) Assistant
The error you're encountering indicates that FFmpeg is unable to write the output PNG files to the specified directory. Specifically, the error:
Could not open file : VID_20250710_171055_8K.mp4/0001.pngsuggests that FFmpeg is trying to write the PNG files directly into a folder named after the input video file (
VID_20250710_171055_8K.mp4), but this folder does not exist or cannot be accessed.Root Cause:
- Folder Does Not Exist: The folder named after the video file (e.g.,
VID_20250710_171055_8K.mp4) was not created before running the FFmpeg command. - Incorrect Path Specification: The path for the output PNG files (
output_folder/%04d.png) may not have been correctly set to point to an existing directory.
Solution:
To fix this issue, ensure that:
- A folder named after the video file is created before running the FFmpeg command.
- The output path for the PNG files points to the correct folder.
Here’s how you can fix it:
Fixed Script:
Below is the corrected script that ensures the folder is created and the output path is correctly specified:
#!/bin/bash # Input video file input_video="VID_20250710_171055_8K.mp4" # Extract the base name of the video file (without extension) video_name=$(basename "$input_video" .mp4) # Create a folder named after the video file mkdir -p "$video_name" # Run FFmpeg to extract frames into the folder ffmpeg -i "$input_video" -vf "fps=24" -compression_level 0 "$video_name/%04d.png"
Explanation of Fixes:
-
mkdir -p "$video_name":- This creates a folder named after the video file (e.g.,
VID_20250710_171055_8K) if it does not already exist. The-pflag ensures no error is thrown if the folder already exists.
- This creates a folder named after the video file (e.g.,
-
Correct Output Path:
- The output path for the PNG files is set to
"$video_name/%04d.png", which ensures that the files are saved in the newly created folder.
- The output path for the PNG files is set to
-
Frame Rate Adjustment:
- The frame rate (
fps=24) matches the metadata of your video (com.android.capture.fps: 24.000000). You can adjust this value if needed.
- The frame rate (
Steps to Use the Fixed Script:
- Save the script to a file, e.g.,
extract_frames.sh. - Make the script executable:
chmod +x extract_frames.sh - Run the script:
./extract_frames.sh
Additional Notes:
- File Naming: Ensure that the input video file name does not contain invalid characters (e.g., spaces or special symbols) that might cause issues with folder creation. If necessary, rename the file before running the script.
- Permissions: Ensure you have write permissions for the directory where the script is executed.
- Large File Handling: Since your video resolution is 7680x4320 (8K), the resulting PNG files will be very large. Ensure you have sufficient disk space to store the extracted frames.
Final Answer:
The fixed FFmpeg command, combined with the script to create the folder, is:
ffmpeg -i "VID_20250710_171055_8K.mp4" -vf "fps=24" -compression_level 0 "VID_20250710_171055_8K/%04d.png"And the folder creation is handled by the script:
mkdir -p "$(basename "VID_20250710_171055_8K.mp4" .mp4)"- Folder Does Not Exist: The folder named after the video file (e.g.,
- User
carefully analyze the log. Need to find the root-cause and fix ffmpeg issue!
PS C:\TEMP\vid8k> ffmpeg -i "VID_20250710_171055_8K.mp4" -vf "fps=24" -compression_level 0 "VID_20250710_171055_8K/%04d.png" ffmpeg version 7.1.1-full_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers built with gcc 14.2.0 (Rev1, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-lcms2 --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-libdvdnav --enable-libdvdread --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libopenjpeg --enable-libquirc --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-libqrencode --enable-librav1e --enable-libsvtav1 --enable-libvvenc --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-liblc3 --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 59. 39.100 / 59. 39.100 libavcodec 61. 19.101 / 61. 19.101 libavformat 61. 7.100 / 61. 7.100 libavdevice 61. 3.100 / 61. 3.100 libavfilter 10. 4.100 / 10. 4.100 libswscale 8. 3.100 / 8. 3.100 libswresample 5. 3.100 / 5. 3.100 libpostproc 58. 3.100 / 58. 3.100 [mov,mp4,m4a,3gp,3g2,mj2 @ 0000018f4e9d7180] Skipping unhandled metadata com.video.file.type of type 67 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID_20250710_171055_8K.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2025-07-10T14:11:11.000000Z com.android.version: 15 com.android.manufacturer: Xiaomi com.android.model: 23127PN0CG com.xiaomi.product.marketname: Xiaomi 14 com.android.capture.fps: 24.000000 com.xiaomi.ai_audio: 1 com.xiaomi.real_8k: 1 com.xiaomi.preview_video_cover: 1 com.xiaomi.pro_video: 24 Duration: 00:00:14.81, start: 0.000000, bitrate: 75431 kb/s Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 7680x4320, 74382 kb/s, 24.03 fps, 24 tbr, 90k tbn (default) Metadata: creation_time : 2025-07-10T14:11:11.000000Z handler_name : VideoHandle vendor_id : [0][0][0][0] Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 320 kb/s (default) Metadata: creation_time : 2025-07-10T14:11:11.000000Z handler_name : SoundHandle vendor_id : [0][0][0][0] Stream mapping: Stream #0:0 -> #0:0 (hevc (native) -> png (native)) Press [q] to stop, [?] for help Output #0, image2, to 'VID_20250710_171055_8K/%04d.png': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 com.xiaomi.pro_video: 24 com.android.version: 15 com.android.manufacturer: Xiaomi com.android.model: 23127PN0CG com.xiaomi.product.marketname: Xiaomi 14 com.android.capture.fps: 24.000000 com.xiaomi.ai_audio: 1 com.xiaomi.real_8k: 1 com.xiaomi.preview_video_cover: 1 encoder : Lavf61.7.100 Stream #0:0(eng): Video: png, rgb24(pc, gbr/bt709/bt709, progressive), 7680x4320, q=2-31, 200 kb/s, 24 fps, 24 tbn (default) Metadata: creation_time : 2025-07-10T14:11:11.000000Z handler_name : VideoHandle vendor_id : [0][0][0][0] encoder : Lavc61.19.101 png [image2 @ 0000018f4eef7600] Could not open file : VID_20250710_171055_8K/0001.png [vost#0:0/png @ 0000018f4e9ed000] Error submitting a packet to the muxer: I/O error Last message repeated 1 times [out#0/image2 @ 0000018f4ea051c0] Error muxing a packet [out#0/image2 @ 0000018f4ea051c0] Task finished with error code: -5 (I/O error) [out#0/image2 @ 0000018f4ea051c0] Terminating thread with return code -5 (I/O error) [out#0/image2 @ 0000018f4ea051c0] video:97500KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown frame= 1 fps=0.4 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=0.0155x Conversion failed! Assistant
Root Cause Analysis:
The error log provides critical information about the failure. Specifically, the following line indicates the root cause:
[image2 @ 0000018f4eef7600] Could not open file : VID_20250710_171055_8K/0001.pngThis error occurs because FFmpeg is attempting to write the output PNG files into a directory (
VID_20250710_171055_8K) that does not exist or is inaccessible. Theimage2muxer in FFmpeg expects the output directory to already exist before writing files to it.Additionally, the error:
Error submitting a packet to the muxer: I/O errorconfirms that the issue is related to file I/O (input/output) and not with the video decoding process itself.
Solution:
To resolve this issue, we need to ensure that the output directory (
VID_20250710_171055_8K) exists before running the FFmpeg command. Below are the steps to fix the issue:
Fixed Command:
-
Create the Output Directory Manually: Before running the FFmpeg command, create the directory manually using your operating system's file explorer or command line. For example:
mkdir "VID_20250710_171055_8K" -
Run the FFmpeg Command: After ensuring the directory exists, run the FFmpeg command:
ffmpeg -i "VID_20250710_171055_8K.mp4" -vf "fps=24" -compression_level 0 "VID_20250710_171055_8K/%04d.png"
Automating the Process:
To avoid manually creating the directory each time, you can use a script to automate the process. Below is an example script for Windows PowerShell:
# Input video file $input_video = "VID_20250710_171055_8K.mp4" # Extract the base name of the video file (without extension) $video_name = [System.IO.Path]::GetFileNameWithoutExtension($input_video) # Create a folder named after the video file New-Item -ItemType Directory -Path $video_name -Force # Run FFmpeg to extract frames into the folder ffmpeg -i "$input_video" -vf "fps=24" -compression_level 0 "$video_name/%04d.png"
Explanation of the Script:
-
$input_video:- Specifies the input video file (
VID_20250710_171055_8K.mp4).
- Specifies the input video file (
-
$video_name:- Extracts the base name of the video file (without the
.mp4extension) using[System.IO.Path]::GetFileNameWithoutExtension().
- Extracts the base name of the video file (without the
-
New-Item -ItemType Directory -Path $video_name -Force:- Creates a new directory named after the video file. The
-Forceflag ensures that no error is thrown if the directory already exists.
- Creates a new directory named after the video file. The
-
FFmpeg Command:
- Extracts frames from the video at 24 frames per second (
fps=24) and saves them as uncompressed PNG files in the newly created directory.
- Extracts frames from the video at 24 frames per second (
Steps to Use the Script:
- Save the script to a file, e.g.,
extract_frames.ps1. - Open PowerShell and navigate to the directory containing the script.
- Run the script:
.\extract_frames.ps1
Additional Notes:
-
File Path Issues on Windows:
- Ensure that the paths do not contain invalid characters (e.g.,
\,?,*) that might cause issues with directory creation or file writing. - If the video file path contains spaces, wrap the path in double quotes (as shown in the script).
- Ensure that the paths do not contain invalid characters (e.g.,
-
Disk Space:
- Since the video resolution is 8K (7680x4320), the resulting PNG files will be very large (approximately 97 MB per frame). Ensure you have sufficient disk space to store the extracted frames.
-
Permissions:
- Ensure you have write permissions for the directory where the script is executed.
-
FFmpeg Version:
- The log indicates that you are using FFmpeg version
7.1.1. This version supports all the required features, so no upgrade is necessary.
- The log indicates that you are using FFmpeg version
Final Answer:
The root cause of the issue is that the output directory (
VID_20250710_171055_8K) does not exist. To fix this, create the directory before running the FFmpeg command. The corrected command is:ffmpeg -i "VID_20250710_171055_8K.mp4" -vf "fps=24" -compression_level 0 "VID_20250710_171055_8K/%04d.png"And the folder creation can be automated using the provided PowerShell script:
New-Item -ItemType Directory -Path "$(Split-Path -LeafBase $input_video)" -Force-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.