python操作音視頻ffmpeg-python對比pyav選擇
ffmpeg 音視頻操作
ffmpeg 是音視頻領(lǐng)域的王者,對音視頻的操作,離不開 ffmpeg
在 python 生態(tài)下面使用 ffmpeg 有兩個著名的庫
fmpeg-python 對比 pyav
那推薦用哪個呢?
當然是后者:pyav
為什么?他兩有什么區(qū)別?
那就是調(diào)用 ffmpeg 的方式不同
ffmpeg-python 是直接調(diào)用 ffmpeg 這個可執(zhí)行程序來操作音視頻的,這就要求你本地安裝 ffmpeg。而且每次操作,都相當于是起了一個 ffmpeg進程,非常的低效。
而 pyav 是鏈接了 ffmpeg 的動態(tài)鏈接庫 libav,所以不存在每次操作都啟動一個 ffmpeg 進程的問題,更加高效優(yōu)雅
使用 ffmpeg-python,如果本地沒有安裝 ffmpeg,就會報錯如下:
In [1]: import ffmpeg
...: stream = ffmpeg.input('input.mp4')
...: stream = ffmpeg.hflip(stream)
...: stream = ffmpeg.output(stream, 'output.mp4')
...: ffmpeg.run(stream)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Cell In[1], line 5
3 stream = ffmpeg.hflip(stream)
4 stream = ffmpeg.output(stream, 'output.mp4')
----> 5 ffmpeg.run(stream)
File /usr/local/lib/python3.11/site-packages/ffmpeg/_run.py:313, in run(stream_spec, cmd, capture_stdout, capture_stderr, input, quiet, overwrite_output)
289 @output_operator()
290 def run(
291 stream_spec,
(...)
297 overwrite_output=False,
298 ):
299 """Invoke ffmpeg for the supplied node graph.
300
301 Args:
(...)
311 Returns: (out, err) tuple containing captured stdout and stderr data.
312 """
--> 313 process = run_async(
314 stream_spec,
315 cmd,
316 pipe_stdin=input is not None,
317 pipe_stdout=capture_stdout,
318 pipe_stderr=capture_stderr,
319 quiet=quiet,
320 overwrite_output=overwrite_output,
321 )
322 out, err = process.communicate(input)
323 retcode = process.poll()
File /usr/local/lib/python3.11/site-packages/ffmpeg/_run.py:284, in run_async(stream_spec, cmd, pipe_stdin, pipe_stdout, pipe_stderr, quiet, overwrite_output)
282 stdout_stream = subprocess.PIPE if pipe_stdout or quiet else None
283 stderr_stream = subprocess.PIPE if pipe_stderr or quiet else None
--> 284 return subprocess.Popen(
285 args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
286 )
File /usr/local/lib/python3.11/subprocess.py:1026, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
1022 if self.text_mode:
1023 self.stderr = io.TextIOWrapper(self.stderr,
1024 encoding=encoding, errors=errors)
-> 1026 self._execute_child(args, executable, preexec_fn, close_fds,
1027 pass_fds, cwd, env,
1028 startupinfo, creationflags, shell,
1029 p2cread, p2cwrite,
1030 c2pread, c2pwrite,
1031 errread, errwrite,
1032 restore_signals,
1033 gid, gids, uid, umask,
1034 start_new_session, process_group)
1035 except:
1036 # Cleanup if the child failed starting.
1037 for f in filter(None, (self.stdin, self.stdout, self.stderr)):
File /usr/local/lib/python3.11/subprocess.py:1950, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session, process_group)
1948 if errno_num != 0:
1949 err_msg = os.strerror(errno_num)
-> 1950 raise child_exception_type(errno_num, err_msg, err_filename)
1951 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'以上就是python 操作音視頻的選擇:ffmpeg-python 對比 pyav的詳細內(nèi)容,更多關(guān)于python mpeg-python對比pyav的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python的mysql數(shù)據(jù)庫的更新如何實現(xiàn)
這篇文章主要介紹了Python的mysql數(shù)據(jù)庫的更新如何實現(xiàn)的相關(guān)資料,這里提供實例代碼,幫助大家理解應(yīng)用這部分知識,需要的朋友可以參考下2017-07-07
Django集成Redis數(shù)據(jù)庫的操作指南
本文將詳細介紹如何在 Django 項目中集成 Redis 數(shù)據(jù)庫,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-03-03
詳解python實現(xiàn)讀取郵件數(shù)據(jù)并下載附件的實例
這篇文章主要介紹了詳解python讀取郵件數(shù)據(jù)并下載附件的實例的相關(guān)資料,這里提供實現(xiàn)實例,幫助大家學(xué)習(xí)理解這部分內(nèi)容,需要的朋友可以參考下2017-08-08
基于python+opencv調(diào)用電腦攝像頭實現(xiàn)實時人臉眼睛以及微笑識別
這篇文章主要為大家詳細介紹了基于python+opencv調(diào)用電腦攝像頭實現(xiàn)實時人臉眼睛以及微笑識別,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09
關(guān)于Python兩個列表進行全組合操作的三種方式
這篇文章主要介紹了關(guān)于Python兩個列表進行全組合操作的三種方式,兩個元組 (a, b)(c, d),則它們的組合有 a,c a,d b,c b,d,這就叫全組合,需要的朋友可以參考下2023-04-04

