While converting files HEVC to mp4 using python the error is comming by ffmpeg. I have used moviepy to convert video to mp4 formate.
Used moviepy Package to convert but throwing error
import os
from moviepy.editor import VideoFileClip
def convert_to_mp4(input_file, output_file):
try:
clip = VideoFileClip(input_file)
codec = 'libx264' # Default codec is libx264
if clip.reader.codec_name == 'hevc':
codec = 'libx265'
clip.write_videofile(output_file, codec=codec, audio_codec='aac')
return True
except Exception as e:
print(f"Error converting video: {str(e)}")
return False
def upload_and_convert(input_file_path, output_folder):
if os.path.exists(input_file_path):
# Convert to MP4
mp4_file_path = os.path.join(output_folder, 'converted2.mp4')
success = convert_to_mp4(input_file_path, mp4_file_path)
if success:
print(f"Conversion successful. MP4 saved at {mp4_file_path}")
return mp4_file_path # Return the path of the converted MP4 file
else:
print("Failed to convert the video.")
return None
else:
print("Input file not found.")
return None
input_file_path = '/Downloads/sample-hevc-file.hevc'
output_folder = '/Downloads'
download_link = upload_and_convert(input_file_path, output_folder)
if download_link:
print(f"Download the converted MP4 file here: {download_link}")
Error
rror converting video: MoviePy error: failed to read the duration of file C:/Users/kjrah/Downloads/sample-hevc-file.hevc.
Here are the file infos returned by ffmpeg:
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, hevc, from 'C:/Users/kjrah/Downloads/sample-hevc-file.hevc':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 320x240 [SAR 1:1 DAR 4:3], 15 fps, 15 tbr, 1200k tbn, 15 tbc
At least one output file must be specified
Failed to convert the video.
Throwing this error except HEVC mostly files are working fine.