Page Not Found
We could not find what you were looking for.
Please contact the owner of the site that linked you to the original URL and let them know their link is broken.
diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml deleted file mode 100644 index 5cc1b69..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ /dev/null @@ -1,97 +0,0 @@ -name: Bug report -description: Something is not working correctly. -title: "[BUG]" -labels: "bug, to be solved" - -body: - - type: checkboxes - attributes: - label: Get started - options: - - label: >- - I have read [Contributing guidelines](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CONTRIBUTING.md). - required: true - - label: >- - I have confirmed that my problem could not be solved by the [troubleshooting](https://cainmagi.github.io/FFmpeg-Encoder-Decoder-for-Python/docs/troubleshooting/installation) section in the documentation. - required: true - - label: >- - I agree to follow the [Code of Conduct](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CODE_OF_CONDUCT.md). - required: true - - label: >- - I have confirmed that my issue is not duplicated with an existing issue. - required: true - - - type: textarea - attributes: - label: Description - description: >- - A clear and concise description of what the bug is. - validations: - required: true - - - type: textarea - attributes: - label: To Reproduce - description: >- - Steps to reproduce the behavior. Instead of describing the steps, you could also provide your codes related to the error here. - value: | - 1. Get package from '...' - 2. Then run '...' - 3. An error occurs. - - - type: textarea - attributes: - label: Traceback - description: >- - The python trackback of the bug. If there is no traceback, please describe (1) The expected behaviors. (2) The actual behaviors. - render: sh-session - - - type: textarea - attributes: - label: Behaviors - description: >- - If there is no traceback, please describe (1) The expected behaviors. (2) The actual behaviors. - value: | - 1. The expected behaviors: - 2. The actual behaviors: - - - type: textarea - attributes: - label: Screenshots - description: >- - If applicable, add screenshots to help explain your problem. - - - type: input - attributes: - label: OS - description: >- - e.g. Ubuntu 20.04, Debian 10, Windows 10 21H1 - validations: - required: true - - type: input - attributes: - label: Python version - description: >- - e.g. 3.8 - validations: - required: true - - type: input - attributes: - label: numpy version - description: >- - e.g. 1.21.1 - validations: - required: true - - type: input - attributes: - label: mpegCoder version - description: >- - e.g. 3.1.0 - validations: - required: true - - - type: textarea - attributes: - label: Additional context - description: >- - Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/docs_request.yml b/.github/ISSUE_TEMPLATE/docs_request.yml deleted file mode 100644 index 6df461f..0000000 --- a/.github/ISSUE_TEMPLATE/docs_request.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Docs request -description: Report a problem or a request for the docs. -title: "[Docs]" -labels: documentation, to be solved - -body: - - type: checkboxes - attributes: - label: Get started - options: - - label: >- - I have read [Contributing guidelines](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CONTRIBUTING.md). - required: true - - label: >- - I agree to follow the [Code of Conduct](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CODE_OF_CONDUCT.md). - required: true - - label: >- - I have confirmed that my issue is not duplicated with an existing issue. - required: true - - - type: textarea - attributes: - label: Problem - description: >- - If you meet any problems with the documentation, please describe your problems here. - - - type: textarea - attributes: - label: Required feature - description: >- - If you need more explanations in the documentation, please describe your needs here. - - - type: input - attributes: - label: mpegCoder version - description: >- - e.g. 3.1.0 - validations: - required: true - - - type: textarea - attributes: - label: Additional context - description: >- - Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml deleted file mode 100644 index fdf4016..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Feature request -description: Suggest an idea for this project -title: "[Feature]" -labels: enhancement, to be solved - -body: - - type: checkboxes - attributes: - label: Get started - options: - - label: >- - I have read [Contributing guidelines](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CONTRIBUTING.md). - required: true - - label: >- - I agree to follow the [Code of Conduct](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CODE_OF_CONDUCT.md). - required: true - - label: >- - I have confirmed that my issue is not duplicated with an existing issue. - required: true - - - type: textarea - attributes: - label: Problem - description: >- - If your feature request is related to a problem, please describe the problem clearly and concisely. - - - type: textarea - attributes: - label: Required feature - description: >- - A clear and concise description of what you want to happen. - validations: - required: true - - - type: textarea - attributes: - label: Alternative solution - description: >- - A clear and concise description of any alternative solutions or features you've considered. - - - type: input - attributes: - label: mpegCoder version - description: >- - e.g. 3.1.0 - validations: - required: true - - - type: textarea - attributes: - label: Additional context - description: >- - Add any other context about the problem here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 2701a3e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,33 +0,0 @@ -# Pull request - -## Get started - -- [ ] I have read [Contributing guidelines](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CONTRIBUTING.md). -- [ ] I agree to follow the [Code of Conduct](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CODE_OF_CONDUCT.md). -- [ ] I have confirmed that my pull request (PR) is not duplicated with an existing PR. -- [ ] I have confirmed that my pull request (PR) passes the testing workflow of the project. - -## Description - -Describe what you have done with this PR. List any dependencies that are required for this change. - -If your PR is designed for an issue, please refer to the issue by the following example: - -Fixes # (issue) - -## Updated report - -Please summarize your modifications as an itemized report. - -1. Update ... -2. Add ... - -## Information - -Please provide the following information about your PR: - -- `mpegCoder` version: - -## Additional context - -Add any other context about the problem here. diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md deleted file mode 100644 index 2701a3e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ /dev/null @@ -1,33 +0,0 @@ -# Pull request - -## Get started - -- [ ] I have read [Contributing guidelines](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CONTRIBUTING.md). -- [ ] I agree to follow the [Code of Conduct](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CODE_OF_CONDUCT.md). -- [ ] I have confirmed that my pull request (PR) is not duplicated with an existing PR. -- [ ] I have confirmed that my pull request (PR) passes the testing workflow of the project. - -## Description - -Describe what you have done with this PR. List any dependencies that are required for this change. - -If your PR is designed for an issue, please refer to the issue by the following example: - -Fixes # (issue) - -## Updated report - -Please summarize your modifications as an itemized report. - -1. Update ... -2. Add ... - -## Information - -Please provide the following information about your PR: - -- `mpegCoder` version: - -## Additional context - -Add any other context about the problem here. diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.yml b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.yml deleted file mode 100644 index 8b55cb6..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Pull request -description: Send a pull request (PR) for this project. -title: "[PR]" - -body: - - type: checkboxes - attributes: - label: Get started - options: - - label: >- - I have read [Contributing guidelines](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CONTRIBUTING.md). - required: true - - label: >- - I agree to follow the [Code of Conduct](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/blob/master/CODE_OF_CONDUCT.md). - required: true - - label: >- - I have confirmed that my pull request (PR) is not duplicated with an existing PR. - required: true - - label: >- - I have confirmed that my pull request (PR) passes the testing workflow of the project. - required: true - - - type: textarea - attributes: - label: Description - description: >- - Describe what you have done with this PR. - - - type: textarea - attributes: - label: Updated report - description: >- - Summarize your modifications as itemized report. - value: | - 1. Update ... - 2. Add ... - - - type: input - attributes: - label: mpegCoder version - description: >- - e.g. 3.1.0 - validations: - required: true - - - type: textarea - attributes: - label: Additional context - description: >- - Add any other context about the problem here. diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 8c1a3d3..0000000 --- a/.gitignore +++ /dev/null @@ -1,55 +0,0 @@ -# Others -include/* -lib/* -.vs/* -*.pdb -*.pyd -*.ipdb -*.iobj -*.exp -*.log -*.tlog -*.lastbuildstate -unsuccessfulbuild -/MpegCoder/x64/ - -# Compressed files -*.tar.xz -*.tar.gz -*.tar.bz2 -*.7z -*.zip -*.rar - -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..a474d23 --- /dev/null +++ b/404.html @@ -0,0 +1,25 @@ + + +
+ + + + + + + + + + + +We could not find what you were looking for.
Please contact the owner of the site that linked you to the original URL and let them know their link is broken.
.so
not found",id:"so-not-found",level:3},{value:"numpy.core.multiarray
not found",id:"numpycoremultiarray-not-found",level:3},{value:"GLibC 2.29 not found",id:"glibc-2-29-not-found",level:3},{value:"GLibC 2.28 not found",id:"glibc-2-28-not-found",level:3},{value:"libcrypyto not found",id:"libcrypyto-not-found",level:3},{value:"Incorrect dependencies",id:"incorrect-dependencies",level:3},{value:"tqdm
has no attribute wrapattr
",id:"tqdm-has-no-attribute-wrapattr",level:3}],N={toc:g};function f(e){var t=e.components,n=(0,i.Z)(e,m);return(0,r.kt)("wrapper",(0,o.Z)({},N,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h2",{id:"introduction"},"Introduction"),(0,r.kt)("p",null,"If you could not find your problem in this page, please fire an issue:"),(0,r.kt)("p",null,(0,r.kt)(a.Z,{to:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/issues/new/choose",icon:d.Z,mdxType:"DarkButton"},"Fire an issue")),(0,r.kt)("h2",{id:"questions-and-answers"},"Questions and answers"),(0,r.kt)("h3",{id:"meet-permission-denied-and-import-failure-during-the-first-run"},"Meet permission denied and import failure during the first run"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Question"),": When I import ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," for the first time, why it fails to download something into the ",(0,r.kt)("inlineCode",{parentName:"p"},"site-pacakges")," folder?")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Answer"),": To reduce the size of the ",(0,r.kt)("inlineCode",{parentName:"p"},".whl")," package, in the newer release, I decide to not pack the ",(0,r.kt)("inlineCode",{parentName:"p"},".dll")," / ",(0,r.kt)("inlineCode",{parentName:"p"},".so")," dependencies with ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder"),". Instead, when importing ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," for the first time, it will automatically download the dependencies into the package folder. To ensure that you have the permission to fetch the dependencies, I recommend the following to solutions:"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"The first solution is to install ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder")," in a virtual environment where you own the permission."),(0,r.kt)("li",{parentName:"ul"},"The second solution is to run ",(0,r.kt)("inlineCode",{parentName:"li"},'python -c "import mpegCoder"')," in Administrator mode or ",(0,r.kt)("inlineCode",{parentName:"li"},"sudo")," mode. This command will let ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder")," start to download the dependencies.")))),(0,r.kt)("h3",{id:"dll-not-found"},"DLL not found"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Question"),": When importing the module, why meeting the following error?"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},"ImportError: DLL load failed while importing mpegCoder: The specified module could not be found.\n"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Answer"),": It seems that this error will only occurs when both the following conditions are satisfied:"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"You are using Windows."),(0,r.kt)("li",{parentName:"ul"},"You are using the maunally installed ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder"),", not the pip version.")),(0,r.kt)("p",{parentName:"li"},"This error is caused by the absent of required dependencies. It is typically caused when:"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"Your python version does not match the ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder")," module."),(0,r.kt)("li",{parentName:"ul"},"The required DLL files are neither in the same folder of ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder.pyd"),", nor in the path (environment variable ",(0,r.kt)("inlineCode",{parentName:"li"},"PATH"),")."))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Fix"),": Download the ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.2.0/dll-win-ffmpeg_5_0.tar.xz"},"dependencies",(0,r.kt)(p.Z,{icon:s.Z,mdxType:"InlineIcon"}))," and extract the DLLs in the same folder of ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder.pyd"),"."))),(0,r.kt)("h3",{id:"so-not-found"},(0,r.kt)("inlineCode",{parentName:"h3"},".so")," not found"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Question"),": When importing the module, why meeting the following error?"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},"ImportError: lib*****.so.**: cannot open shared object file: No such file or directory\n"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Answer"),": It seems that this error will only occurs when both the following conditions are satisfied:"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"You are using Linux."),(0,r.kt)("li",{parentName:"ul"},"You are using the maunally installed ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder"),", not the pip version.")),(0,r.kt)("p",{parentName:"li"},"This error is caused by the absent of required dependencies. It is typically caused when:"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"Your python version does not match the ",(0,r.kt)("inlineCode",{parentName:"li"},"mpegCoder")," module, in this case, the library name should be ",(0,r.kt)("inlineCode",{parentName:"li"},"libpython3.*.so.**"),"."),(0,r.kt)("li",{parentName:"ul"},"The required dependencies files are not in your environment variable ",(0,r.kt)("inlineCode",{parentName:"li"},"$LD_LIBRARY_PATH"),"."))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Fix"),": Download the ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.2.0/so-linux-ffmpeg_5_0.tar.xz"},"dependencies",(0,r.kt)(p.Z,{icon:s.Z,mdxType:"InlineIcon"}))," and extract the missing ",(0,r.kt)("inlineCode",{parentName:"p"},".so")," to a folder in ",(0,r.kt)("inlineCode",{parentName:"p"},"$LD_LIBRARY_PATH"),"."))),(0,r.kt)("h3",{id:"numpycoremultiarray-not-found"},(0,r.kt)("inlineCode",{parentName:"h3"},"numpy.core.multiarray")," not found"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Question"),": When importing the module, why meeting the following error?"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},"ImportError: numpy.core.multiarray failed to import\n"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Answer"),": You may not install ",(0,r.kt)("a",{parentName:"p",href:"https://numpy.org",title:"Numpy"},"Numpy",(0,r.kt)(l.Z,{mdxType:"IconExternalLink"})),", or your Numpy version is not match the pre-compiled ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder"),". In most cases, a little bit mismatch of the Numpy would not cause this error. Maybe your Numpy version is different from the requirement too much. See ",(0,r.kt)("a",{parentName:"p",href:"../installation/windows#download-mpegcoder"},"Compilation list (Win)")," or ",(0,r.kt)("a",{parentName:"p",href:"../installation/linux#download-mpegcoder"},"Compilation list (Linux)")," to find the best Numpy version.")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Fix"),": Reinstall Numpy, or compile ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," by yourself."))),(0,r.kt)("h3",{id:"glibc-2-29-not-found"},"GLibC 2.29 not found"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Question"),": When importing the module, why meeting the following error?"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},"OSError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ******/mpegCoder/lib/libsrt.so.1.4)\n"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Answer"),": Your GLibC version is not ",(0,r.kt)("inlineCode",{parentName:"p"},">=2.29"),". To verify that, you could run"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre",className:"language-shell"},"ldd --version\n")),(0,r.kt)("p",{parentName:"li"},"This problem often occurs when you are using an older Linux OS. The supported OS list could be found ",(0,r.kt)("a",{parentName:"p",href:"../installation/linux#import"},"here"),".")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"Fix"),": We recommend to compile and install GLibC ",(0,r.kt)("inlineCode",{parentName:"p"},">=2.31"),". However, if users want a faster hotfix. Please follow the follwing instructions."),(0,r.kt)("p",{parentName:"li"},"If you are using ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," from pip. You could find a folder named ",(0,r.kt)("inlineCode",{parentName:"p"},"lib-fix")," in where ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," is installed, then run the following command:"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre",className:"language-shell"},"ln -sf clear
",id:"clear",level:3},{value:"resetPath
",id:"resetpath",level:3},{value:"Requires",id:"requires",level:4},{value:"getParameter
",id:"getparameter",level:3},{value:"Requires",id:"requires",level:4},{value:"Returns",id:"returns",level:4},{value:"setParameter
",id:"setparameter",level:3},{value:"Requires",id:"requires",level:4},{value:"FFmpegSetup
",id:"ffmpegsetup",level:3},{value:"Requires",id:"requires",level:4},{value:"dumpFile
",id:"dumpfile",level:3},{value:"EncodeFrame
",id:"encodeframe",level:3},{value:"Requires",id:"requires",level:4},{value:"Returns",id:"returns",level:4},{value:"FFmpegClose
",id:"ffmpegclose",level:3},{value:"Operators",id:"operators",level:2},{value:"__str__
",id:"__str__",level:3},{value:"Returns",id:"returns",level:4},{value:"Examples",id:"examples",level:2},{value:"Optimize the video encoding",id:"optimize-the-video-encoding",level:3},{value:"Rescale and resample the video",id:"rescale-and-resample-the-video",level:3},{value:"Use the AV1 encoder",id:"use-the-av1-encoder",level:3},{value:"Use multi-thread encoding",id:"use-multi-thread-encoding",level:3}],f={toc:g};function v(e){var t=e.components,a=(0,r.Z)(e,s);return(0,i.kt)("wrapper",(0,n.Z)({},f,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,(0,i.kt)(l.Z,{icon:o.Z,mdxType:"InlineIcon"})," Class",(0,i.kt)(c.q,{mdxType:"Splitter"}),(0,i.kt)(c.A,{ver:"3.2.0",url:"MpegCoder.h#L82",mdxType:"SourceURL"},(0,i.kt)(l.Z,{icon:m.Z,mdxType:"InlineIcon"})," Source")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc = mpegCoder.MpegEncoder()\n")),(0,i.kt)("p",null,"The frame-level video encoder used for muxing a video file."),(0,i.kt)("p",null,"This encoder instance serves as a video file writer. It supports:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Encode a 3D ",(0,i.kt)("a",{parentName:"li",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"}))," as a video frame."),(0,i.kt)("li",{parentName:"ul"},"Configure the codec type and the video parameters."),(0,i.kt)("li",{parentName:"ul"},"Scaling the encoded video frames to a specific size.")),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"MpegEncoder")," requires users to initialize the encoder before writing frames, and close the video after finishing all works. If the video is not closed manually, an automatical closing would be performed when the encoder is destructed. During the distruction, hitting ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"C")," will cause the written video to break."),(0,i.kt)("h2",{id:"arguments"},"Arguments"),(0,i.kt)("p",null,"This class does not has initialization arguments."),(0,i.kt)("h2",{id:"methods"},"Methods"),(0,i.kt)("h3",{id:"clear"},(0,i.kt)("inlineCode",{parentName:"h3"},"clear")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.clear()\n")),(0,i.kt)("p",null,"Clear all configurations ",(0,i.kt)("strong",{parentName:"p"},"including")," the default video path. If a video is opened by the encoder, ",(0,i.kt)("inlineCode",{parentName:"p"},"clear()")," will close the video automatically."),(0,i.kt)("div",{className:"admonition admonition-tip alert alert--success"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"12",height:"16",viewBox:"0 0 12 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z"}))),"tip")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"We suggest that users should call ",(0,i.kt)("inlineCode",{parentName:"p"},"clear()")," manually, like using other file writers."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"resetpath"},(0,i.kt)("inlineCode",{parentName:"h3"},"resetPath")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.resetPath(videoPath)\n")),(0,i.kt)("p",null,"Reset the default video path to a specific value. Configuring this value will not cause the video to be opened. This method is merely used as a configuration."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)(l.Z,{icon:p.Z,mdxType:"InlineIcon"})),(0,i.kt)("td",{parentName:"tr",align:"left"},"The path of the video to be written.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"getparameter"},(0,i.kt)("inlineCode",{parentName:"h3"},"getParameter")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"param = enc.getParameter(paramName=None)\n")),(0,i.kt)("p",null,"Get the video parameter or configuration value. Each time ",(0,i.kt)("inlineCode",{parentName:"p"},"paramName")," only accepts one parameter name."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"paramName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the parameter to be checked. If not give, all important parameters, including some private parameters will be returned as a ",(0,i.kt)("inlineCode",{parentName:"td"},"dict"),".")))),(0,i.kt)("p",null,"Here is a list of checkable ",(0,i.kt)("inlineCode",{parentName:"p"},"paramName"),":"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Parameter"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The current path of the written video. If the video is not opened, will return the default video path.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"codecName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the encoder. See ",(0,i.kt)("a",{parentName:"td",href:"https://ffmpeg.org/ffmpeg-codecs.html#toc-Video-Encoders",title:"Video encoders of FFMpeg"},"here",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"}))," to view a list of FFMpeg encoders. Note that not all encoders could be used, the avaliable encoders depends on the current FFMpeg built libraries.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"nthread")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of encoder threads.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"bitRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The bit rate of the written video (Kb/s). This value determines the output video size directly.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"width")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the written video. This value is mainly determined by the user configurations.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"height")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the written video. This value is mainly determined by the user configurations.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"widthSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"width"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"heightSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"height"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"GOPSize")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The size of one ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/Group_of_pictures",title:"Group of pictures | Wikipedia"},"GOP",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"maxBframe")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The maximal number of consecutive B frames in a GOP. In most cases, this value could not be greater than ",(0,i.kt)("inlineCode",{parentName:"td"},"16"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"frameRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The target frame rate of the written video. The unit is FPS.")))),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"param")),(0,i.kt)("td",{parentName:"tr",align:"center"},"Determined by ",(0,i.kt)("inlineCode",{parentName:"td"},"paramName")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The returned value of the parameter. If no ",(0,i.kt)("inlineCode",{parentName:"td"},"paramName")," is given, will return all important parameters.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"setparameter"},(0,i.kt)("inlineCode",{parentName:"h3"},"setParameter")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.setParameter(\n decoder=None, configDict=None, videoPath=None, codecName=None,\n nthread=None, bitRate=None, width=None, height=None, widthSrc=None, heightSrc=None,\n GOPSize=None, maxBframe=None, frameRate=None\n)\n")),(0,i.kt)("p",null,"Set the configurations of the encoder. To make the configurations take effects, these parameters need to be configured before ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),"."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"decoder")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("a",{parentName:"td",href:"./MpegDecoder"},(0,i.kt)("inlineCode",{parentName:"a"},"MpegDecoder"))," or ",(0,i.kt)("a",{parentName:"td",href:"./MpegClient"},(0,i.kt)("inlineCode",{parentName:"a"},"MpegClient"))),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"When configure this argument, the required configurations will be copied from a decoder or a client. If users also provide duplicated arguments in the same call, these copied parameters have a lower preference than those specified by users. This argument is useful when trancoding a video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"configDict")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"dict")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"An alternative of the argument ",(0,i.kt)("inlineCode",{parentName:"td"},"decoder")," when the parameters need to be passed through different processes. Using ",(0,i.kt)("inlineCode",{parentName:"td"},"configDict=decoder.getParameter()")," is equivalent to using ",(0,i.kt)("inlineCode",{parentName:"td"},"decoder=decoder"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The current path of the written video. If the video is not opened, will return the default video path.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"codecName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the encoder. See ",(0,i.kt)("a",{parentName:"td",href:"https://ffmpeg.org/ffmpeg-codecs.html#toc-Video-Encoders",title:"Video encoders of FFMpeg"},"here",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"}))," to view a list of FFMpeg encoders. Note that not all encoders could be used, the avaliable encoders depends on the current FFMpeg built libraries.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"nthread")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of encoder threads.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"bitRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The bit rate of the written video (Kb/s). This value determines the output video size directly.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"width")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the written video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"height")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the written video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"widthSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"width"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"heightSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"height"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"GOPSize")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The size of one ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/Group_of_pictures",title:"Group of pictures | Wikipedia"},"GOP",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"maxBframe")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The maximal number of consecutive B frames in a GOP. In most cases, this value could not be greater than ",(0,i.kt)("inlineCode",{parentName:"td"},"16"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"frameRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"tuple")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The target frame rate of the written video. This value should be a tuple of two ",(0,i.kt)("inlineCode",{parentName:"td"},"int"),"s: ",(0,i.kt)("inlineCode",{parentName:"td"},"(numerator, denominator)"),". This format is consistent with ",(0,i.kt)("a",{parentName:"td",href:"https://ffmpeg.org/doxygen/trunk/structAVRational.html",title:"AVRational"},(0,i.kt)("inlineCode",{parentName:"a"},"AVRational"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),".")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"h3"},"FFmpegSetup")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.FFmpegSetup(videoPath=None)\n")),(0,i.kt)("p",null,"Open the video file, and initialize the encoder. During the encoder initialization, the codec and the video format will be configured according to the file name and the user configurations set by ",(0,i.kt)("a",{parentName:"p",href:"#setparameter"},(0,i.kt)("inlineCode",{parentName:"a"},"setParameter()")),". If an video is being opened by the encoder now, this video will be closed first, then the new video will be opened with the same configurations."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The path of the video to be written. If not given, will use the default path configured by ",(0,i.kt)("a",{parentName:"td",href:"#resetpath"},(0,i.kt)("inlineCode",{parentName:"a"},"resetPath()")),". Setting this argument will also cause the default video path to change.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"dumpfile"},(0,i.kt)("inlineCode",{parentName:"h3"},"dumpFile")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.dumpFile()\n")),(0,i.kt)("p",null,"Print out a brief preview of the video meta-data to the standard output."),(0,i.kt)("div",{className:"admonition admonition-caution alert alert--warning"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"}))),"caution")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"This method is based on C stdout. Therefore, these results could not be redirected or catched by python."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"encodeframe"},(0,i.kt)("inlineCode",{parentName:"h3"},"EncodeFrame")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"is_success = enc.EncodeFrame(PyArrayFrame)\n")),(0,i.kt)("p",null,"Encode one frame into the video. Note that in most cases, the frame will not be written to the file instantly. Instead of, the frames will be saved in a low-level buffer of the codec. Only when ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegclose"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegClose()"))," is called, the frames in the buffer will be flushed into the file."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"PyArrayFrame")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"np.ndarray")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)(l.Z,{icon:p.Z,mdxType:"InlineIcon"})),(0,i.kt)("td",{parentName:"tr",align:"left"},"An array with a shape of ",(0,i.kt)("inlineCode",{parentName:"td"},"(H, W, C)"),", where ",(0,i.kt)("inlineCode",{parentName:"td"},"(H, W)")," are the source height (",(0,i.kt)("inlineCode",{parentName:"td"},"heightSrc"),") and source width (",(0,i.kt)("inlineCode",{parentName:"td"},"widthSrc"),") respectively. ",(0,i.kt)("inlineCode",{parentName:"td"},"C")," means the 3 RGB channel.")))),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"is_success")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"bool")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The status of the frame encoding. If the given frame succeeds to be encoded, will return ",(0,i.kt)("inlineCode",{parentName:"td"},"True"),"; Otherwise, will return ",(0,i.kt)("inlineCode",{parentName:"td"},"False"),".")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"ffmpegclose"},(0,i.kt)("inlineCode",{parentName:"h3"},"FFmpegClose")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.FFmpegClose()\n")),(0,i.kt)("p",null,"Close the video file. Calling this method will flush all buffered frames into the file. Then the video tail will be writen to the file. If users does not call this method explicitly, it will be called when ",(0,i.kt)("a",{parentName:"p",href:"#clear"},(0,i.kt)("inlineCode",{parentName:"a"},"clear()"))," is called or when the encoder is destructed."),(0,i.kt)("h2",{id:"operators"},"Operators"),(0,i.kt)("h3",{id:"__str__"},(0,i.kt)("inlineCode",{parentName:"h3"},"__str__")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"info = str(enc)\n")),(0,i.kt)("p",null,"Return a brief report of the current encoder status."),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"info")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"A brief report of the encoder status, the configurations and parameters will be listed as formatted texts.")))),(0,i.kt)("h2",{id:"examples"},"Examples"),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"../examples/transcoding"},(0,i.kt)("em",{parentName:"a"},(0,i.kt)("inlineCode",{parentName:"em"},"Transcoding")))," in the tutorial. Here we also show some specific configurations:"),(0,i.kt)("h3",{id:"optimize-the-video-encoding"},"Optimize the video encoding"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\ndec = mpegCoder.MpegDecoder()\n...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(decoder=dec, codecName='libx265', videoPath='test-video-x265.mp4', GOPSize=24, maxBframe=16)\n...\n")),(0,i.kt)("h3",{id:"rescale-and-resample-the-video"},"Rescale and resample the video"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(width=1280, height=720, frameRate=(5, 1), codecName='libx265', videoPath='test-video-x265.mp4')\n...\n")),(0,i.kt)("h3",{id:"use-the-av1-encoder"},"Use the AV1 encoder"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(width=1280, height=720, codecName='libsvtav1', videoPath='test-video-av1.mp4')\n...\n")),(0,i.kt)("h3",{id:"use-multi-thread-encoding"},"Use multi-thread encoding"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(nthread=8)\n...\n")))}v.isMDXComponent=!0},2895:function(e,t){t.Z={body:'mpegCoder
",id:"download-mpegcoder",level:3},{value:"Install Numpy",id:"install-numpy",level:3},{value:"Download dependencies",id:"download-dependencies",level:3},{value:"Import",id:"import",level:3},{value:"Compile the module",id:"compile-the-module",level:2},{value:"Compile mpegCoder
",id:"compile-mpegcoder",level:3},{value:"Compile FFMpeg",id:"compile-ffmpeg",level:3}],b={toc:C};function v(e){var t=e.components,n=(0,i.Z)(e,k);return(0,r.kt)("wrapper",(0,a.Z)({},b,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This guide contains steps for installing or compiling the ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," module manually. We recommend users who need to use ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," in a project locally to install the package by this way."),(0,r.kt)("h2",{id:"install-the-pre-compiled-module"},"Install the pre-compiled module"),(0,r.kt)("h3",{id:"download-mpegcoder"},"Download ",(0,r.kt)("inlineCode",{parentName:"h3"},"mpegCoder")),(0,r.kt)("p",null,"First, users need to download the single module. We provide the downloading links in the following table. Please check the correct version according to your environment."),(0,r.kt)("table",null,(0,r.kt)("thead",{parentName:"table"},(0,r.kt)("tr",{parentName:"thead"},(0,r.kt)("th",{parentName:"tr",align:"center"},"mpegCoder"),(0,r.kt)("th",{parentName:"tr",align:"center"},"FFMpeg"),(0,r.kt)("th",{parentName:"tr",align:"center"},"Numpy"),(0,r.kt)("th",{parentName:"tr",align:"center"},"Python"),(0,r.kt)("th",{parentName:"tr",align:"center"},"GCC/G++"),(0,r.kt)("th",{parentName:"tr",align:"center"},"OS"))),(0,r.kt)("tbody",{parentName:"table"},(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("a",{parentName:"td",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/3.2.0-linux/mpegCoder_3_2_0_Linux_py310.tar.xz"},(0,r.kt)("inlineCode",{parentName:"a"},"3.2.0"),(0,r.kt)(d.Z,{icon:p.Z,mdxType:"InlineIcon"}))),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"5.0")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"1.22.3")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"3.10.4")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"10.2.1")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"Debian 11"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("a",{parentName:"td",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/3.2.0-linux/mpegCoder_3_2_0_Linux_py39.tar.xz"},(0,r.kt)("inlineCode",{parentName:"a"},"3.2.0"),(0,r.kt)(d.Z,{icon:p.Z,mdxType:"InlineIcon"}))),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"5.0")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"1.22.3")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"3.9.12")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"10.2.1")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"Debian 11"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("a",{parentName:"td",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/3.2.0-linux/mpegCoder_3_2_0_Linux_py38.tar.xz"},(0,r.kt)("inlineCode",{parentName:"a"},"3.2.0"),(0,r.kt)(d.Z,{icon:p.Z,mdxType:"InlineIcon"}))),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"5.0")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"1.22.3")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"3.8.13")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"10.2.1")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"Debian 11"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("a",{parentName:"td",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/3.2.0-linux/mpegCoder_3_2_0_Linux_py37.tar.xz"},(0,r.kt)("inlineCode",{parentName:"a"},"3.2.0"),(0,r.kt)(d.Z,{icon:p.Z,mdxType:"InlineIcon"}))),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"5.0")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"1.21.5")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"3.7.13")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"10.2.1")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"Debian 11"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("a",{parentName:"td",href:"https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/3.2.0-linux/mpegCoder_3_2_0_Linux_py36.tar.xz"},(0,r.kt)("inlineCode",{parentName:"a"},"3.2.0"),(0,r.kt)(d.Z,{icon:p.Z,mdxType:"InlineIcon"}))),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"5.0")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"1.19.5")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"3.6.15")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"10.2.1")),(0,r.kt)("td",{parentName:"tr",align:"center"},(0,r.kt)("inlineCode",{parentName:"td"},"Debian 11"))))),(0,r.kt)("p",null,"After extracting the tarball, we could get ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder.so"),"."),(0,r.kt)("div",{className:"admonition admonition-info alert alert--info"},(0,r.kt)("div",{parentName:"div",className:"admonition-heading"},(0,r.kt)("h5",{parentName:"div"},(0,r.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,r.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"},(0,r.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}))),"info")),(0,r.kt)("div",{parentName:"div",className:"admonition-content"},(0,r.kt)("p",{parentName:"div"},"Note that the above versions only show the environment when building ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder"),". It does not mean that they are the dependencies of running ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder"),". For example, users could use ",(0,r.kt)("inlineCode",{parentName:"p"},"python 3.9.5")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"numpy 1.22.0")," to run ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder"),"."))),(0,r.kt)("h3",{id:"install-numpy"},"Install Numpy"),(0,r.kt)("p",null,"To run ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder"),", you are required to install ",(0,r.kt)("a",{parentName:"p",href:"https://numpy.org",title:"Numpy"},"Numpy",(0,r.kt)(l.Z,{mdxType:"IconExternalLink"}))," with the correct version first. The best version for each ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," release has been listed before. If your Numpy version is differnt from the best version too much, ",(0,r.kt)("inlineCode",{parentName:"p"},"mpegCoder")," may not work. Here is the command for installation."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-shell"},"python -m pip install numpy==clear
",id:"clear",level:3},{value:"resetPath
",id:"resetpath",level:3},{value:"Requires",id:"requires",level:4},{value:"getParameter
",id:"getparameter",level:3},{value:"Requires",id:"requires",level:4},{value:"Returns",id:"returns",level:4},{value:"setParameter
",id:"setparameter",level:3},{value:"Requires",id:"requires",level:4},{value:"FFmpegSetup
",id:"ffmpegsetup",level:3},{value:"Requires",id:"requires",level:4},{value:"dumpFile
",id:"dumpfile",level:3},{value:"start
",id:"start",level:3},{value:"terminate
",id:"terminate",level:3},{value:"ExtractFrame
",id:"extractframe",level:3},{value:"Requires",id:"requires",level:4},{value:"Returns",id:"returns",level:4},{value:"Operators",id:"operators",level:2},{value:"__str__
",id:"__str__",level:3},{value:"Returns",id:"returns",level:4},{value:"Examples",id:"examples",level:2},{value:"Scale the decoded frame",id:"scale-the-decoded-frame",level:3},{value:"Configure the cache size",id:"configure-the-cache-size",level:3},{value:"Use multi-thread decoding",id:"use-multi-thread-decoding",level:3}],g={toc:N};function f(e){var t=e.components,a=(0,r.Z)(e,s);return(0,i.kt)("wrapper",(0,n.Z)({},g,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,(0,i.kt)(l.Z,{icon:d.Z,mdxType:"InlineIcon"})," Class",(0,i.kt)(p.q,{mdxType:"Splitter"}),(0,i.kt)(p.A,{ver:"3.1.0",url:"MpegStreamer.h#L49",mdxType:"SourceURL"},(0,i.kt)(l.Z,{icon:m.Z,mdxType:"InlineIcon"})," Source")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln = mpegCoder.MpegClient()\n")),(0,i.kt)("p",null,"The frame-level video stream client used for demuxing an online video stream."),(0,i.kt)("p",null,"This client instance is integrated with the features of ",(0,i.kt)("a",{parentName:"p",href:"./MpegDecoder"},(0,i.kt)("inlineCode",{parentName:"a"},"MpegDecoder")),". The connection to the video server is established by ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),". When the client is working, it will manage a background sub-thread for fetching the remote frames consecutively. The fetched frames are saved in a circular buffer. The method ",(0,i.kt)("a",{parentName:"p",href:"#extractframe"},(0,i.kt)("inlineCode",{parentName:"a"},"ExtractFrame()"))," always return the latest received frames. To learn more details, please review the ",(0,i.kt)("a",{parentName:"p",href:"../examples/client#introduction"},"description of the theory"),"."),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"MpegClient")," requires users to initialize the decoding before reading frames, and close the video after finishing all works. If the video is not closed manually, an automatical closing would be performed when the client is destructed. ",(0,i.kt)("inlineCode",{parentName:"p"},"MpegClient")," also supports threading control. When the client is connected to the server, users could use ",(0,i.kt)("a",{parentName:"p",href:"#start"},(0,i.kt)("inlineCode",{parentName:"a"},"start()"))," to keep the buffer synchronized with the video stream. Calling ",(0,i.kt)("a",{parentName:"p",href:"#terminate"},(0,i.kt)("inlineCode",{parentName:"a"},"terminate()"))," will force the buffer updating to stop. In this case, the method ",(0,i.kt)("a",{parentName:"p",href:"#extractframe"},(0,i.kt)("inlineCode",{parentName:"a"},"ExtractFrame()"))," will always return the same results."),(0,i.kt)("h2",{id:"arguments"},"Arguments"),(0,i.kt)("p",null,"This class does not has initialization arguments."),(0,i.kt)("h2",{id:"methods"},"Methods"),(0,i.kt)("h3",{id:"clear"},(0,i.kt)("inlineCode",{parentName:"h3"},"clear")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.clear()\n")),(0,i.kt)("p",null,"Clear all configurations ",(0,i.kt)("strong",{parentName:"p"},"except")," the default video address. If a video stream is alredy opened, ",(0,i.kt)("inlineCode",{parentName:"p"},"clear()")," will release the connection automatically."),(0,i.kt)("div",{className:"admonition admonition-tip alert alert--success"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"12",height:"16",viewBox:"0 0 12 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z"}))),"tip")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"We suggest that users should call ",(0,i.kt)("inlineCode",{parentName:"p"},"clear()")," manually, like using other file readers. No matter when ",(0,i.kt)("a",{parentName:"p",href:"#start"},(0,i.kt)("inlineCode",{parentName:"a"},"start()"))," is called, this method could be used safely without calling ",(0,i.kt)("a",{parentName:"p",href:"#terminate"},(0,i.kt)("inlineCode",{parentName:"a"},"terminate()")),"."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"resetpath"},(0,i.kt)("inlineCode",{parentName:"h3"},"resetPath")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.resetPath(videoAddress)\n")),(0,i.kt)("p",null,"Reset the default video address to a specific value. Configuring this value will not cause the video stream to be opened. This method is merely used as a configuration."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoAddress")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)(l.Z,{icon:o.Z,mdxType:"InlineIcon"})),(0,i.kt)("td",{parentName:"tr",align:"left"},"The address of the video to be read.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"getparameter"},(0,i.kt)("inlineCode",{parentName:"h3"},"getParameter")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"param = cln.getParameter(paramName=None)\n")),(0,i.kt)("p",null,"Get the video parameter or configuration value. Each time ",(0,i.kt)("inlineCode",{parentName:"p"},"paramName")," only accepts one parameter name."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"paramName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the parameter to be checked. If not give, all important parameters, including some private parameters will be returned as a ",(0,i.kt)("inlineCode",{parentName:"td"},"dict"),".")))),(0,i.kt)("p",null,"Here is a list of checkable ",(0,i.kt)("inlineCode",{parentName:"p"},"paramName"),":"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Parameter"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoAddress")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The current address of the read video. If the video stream is not opened, will return the default video address.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"width")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the read video. This value is determined by the video stream.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"height")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the read video. This value is determined by the video stream.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"frameCount")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of returned frames in the last frame extraction method.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"coderName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the codec used for decoding the video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"nthread")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of decoder threads.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"duration")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The total seconds of this video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"estFrameNum")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The estimated total frame number (may be not accurate).")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"srcFrameRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The average frame rate of the source video stream. The unit is FPS. The actual frame rate may be changed on client side.")))),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"param")),(0,i.kt)("td",{parentName:"tr",align:"center"},"Determined by ",(0,i.kt)("inlineCode",{parentName:"td"},"paramName")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The returned value of the parameter. If no ",(0,i.kt)("inlineCode",{parentName:"td"},"paramName")," is given, will return all important parameters. These parameters could serve as ",(0,i.kt)("inlineCode",{parentName:"td"},"configDict")," for ",(0,i.kt)("inlineCode",{parentName:"td"},"MpegEncoder")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"MpegServer"),".")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"setparameter"},(0,i.kt)("inlineCode",{parentName:"h3"},"setParameter")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.setParameter(widthDst=None, heightDst=None, cacheSize=None, readSize=None, dstFrameRate=None, nthread=None)\n")),(0,i.kt)("p",null,"Set the configurations of the client. To make the configurations take effects, these parameters need to be configured before ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),"."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"widthDst")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of extracted frames. Configuring both ",(0,i.kt)("inlineCode",{parentName:"td"},"widthDst")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"heightDst")," will cause the frames to be scaled. If a value ",(0,i.kt)("inlineCode",{parentName:"td"},"<=0")," is given, this value would take no effect.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"heightDst")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of extracted frames. Configuring both ",(0,i.kt)("inlineCode",{parentName:"td"},"widthDst")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"heightDst")," will cause the frames to be scaled. If a value ",(0,i.kt)("inlineCode",{parentName:"td"},"<=0")," is given, this value would take no effect.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"cacheSize")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of allocated avaliable frames in the cache. We recommend to configure this value as ",(0,i.kt)("inlineCode",{parentName:"td"},"2*readSize"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"dstFrameRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"tuple")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The destination FPS of the stream. This value should be formatted as a factor defined as ",(0,i.kt)("inlineCode",{parentName:"td"},"(numerator, denominator)"),". Configuing this value will cause the received frames to be resampled.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"nthread")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of decoder threads.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"h3"},"FFmpegSetup")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.FFmpegSetup(videoAddress=None)\n")),(0,i.kt)("p",null,"Open the online video stream, and initialize the decoder. After the client initialized, the video parameters will be loaded, the video format will be parsed and the video codec will be detected automatically. If an video stream connection is established by the client now, this connection will be released first, then the new video stream will be opened."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoAddress")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The address of the video stream to be read. If not given, will use the default path configured by ",(0,i.kt)("a",{parentName:"td",href:"#resetpath"},(0,i.kt)("inlineCode",{parentName:"a"},"resetPath()")),". Setting this argument will also cause the default video path to change.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"dumpfile"},(0,i.kt)("inlineCode",{parentName:"h3"},"dumpFile")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.dumpFile()\n")),(0,i.kt)("p",null,"Print out a brief preview of the video meta-data to the standard output."),(0,i.kt)("div",{className:"admonition admonition-caution alert alert--warning"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"}))),"caution")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"This method is based on C stdout. Therefore, these results could not be redirected or catched by python."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"start"},(0,i.kt)("inlineCode",{parentName:"h3"},"start")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.start()\n")),(0,i.kt)("p",null,"Start the demuxing thread. The started sub-thread will keep receiving remote frames to ensure the client buffer is synchronized with the online video stream."),(0,i.kt)("div",{className:"admonition admonition-caution alert alert--warning"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"}))),"caution")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"This method must be called after ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),". Once this method is called, users are not allowed to call it again until ",(0,i.kt)("a",{parentName:"p",href:"#terminate"},(0,i.kt)("inlineCode",{parentName:"a"},"terminate()"))," is called or the client is restarted by ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),"."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"terminate"},(0,i.kt)("inlineCode",{parentName:"h3"},"terminate")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"cln.terminate()\n")),(0,i.kt)("p",null,"Terminate the current demuxing thread. This method is required to be called after ",(0,i.kt)("a",{parentName:"p",href:"#start"},(0,i.kt)("inlineCode",{parentName:"a"},"start()")),'. It will stop the frame receiving, and make the played video to be "paused". In this case, the frame receiving could be started again by ',(0,i.kt)("a",{parentName:"p",href:"#start"},(0,i.kt)("inlineCode",{parentName:"a"},"start()")),"."),(0,i.kt)("div",{className:"admonition admonition-caution alert alert--warning"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"}))),"caution")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"This method must be called after ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),". Calling this method will not cause the current connection aborted. Only ",(0,i.kt)("a",{parentName:"p",href:"#clear"},(0,i.kt)("inlineCode",{parentName:"a"},"clear()"))," could release the connection explicitly."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"extractframe"},(0,i.kt)("inlineCode",{parentName:"h3"},"ExtractFrame")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"frames = cln.ExtractFrame(readSize=0)\n")),(0,i.kt)("p",null,"Read the latest several frames from the circular buffer."),(0,i.kt)("p",null,"This method is merely a reading method, and not decode frames. Instead, the decoding is managed by the sub-thread. ",(0,i.kt)("inlineCode",{parentName:"p"},"ExtractFrame()")," always fetch the several frames that are latestly decoded. Even ",(0,i.kt)("a",{parentName:"p",href:"#terminate"},(0,i.kt)("inlineCode",{parentName:"a"},"terminate()"))," is called, this method could be still used safely."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"readSize")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of the frames to be read. If configured as ",(0,i.kt)("inlineCode",{parentName:"td"},"<=0"),", will use the default ",(0,i.kt)("inlineCode",{parentName:"td"},"readSize")," configured by ",(0,i.kt)("a",{parentName:"td",href:"#setparameter"},(0,i.kt)("inlineCode",{parentName:"a"},"setParameter()")),".")))),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"frames")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"np.ndarray")),(0,i.kt)("td",{parentName:"tr",align:"left"},"An array with a shape of ",(0,i.kt)("inlineCode",{parentName:"td"},"(N, H, W, C)"),", where ",(0,i.kt)("inlineCode",{parentName:"td"},"N")," is given by ",(0,i.kt)("inlineCode",{parentName:"td"},"readSize")," (no matter whether the video reaches its end), ",(0,i.kt)("inlineCode",{parentName:"td"},"(H, W)")," are the height and width of the returned frames respectively. ",(0,i.kt)("inlineCode",{parentName:"td"},"C")," means the 3 RGB channel. If no valid frames are received, this method would return several frames that are totally black.")))),(0,i.kt)("h2",{id:"operators"},"Operators"),(0,i.kt)("h3",{id:"__str__"},(0,i.kt)("inlineCode",{parentName:"h3"},"__str__")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"info = str(cln)\n")),(0,i.kt)("p",null,"Return a brief report of the current client status."),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"info")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"A brief report of the client status, the configurations and parameters will be listed as formatted texts.")))),(0,i.kt)("h2",{id:"examples"},"Examples"),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"../examples/client"},(0,i.kt)("em",{parentName:"a"},(0,i.kt)("inlineCode",{parentName:"em"},"Client")))," in the tutorial. Here we also show some specific configurations:"),(0,i.kt)("h3",{id:"scale-the-decoded-frame"},"Scale the decoded frame"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\ncln = mpegCoder.MpegClient()\ncln.setParameter(widthDst=720, heightDst=486)\n...\n")),(0,i.kt)("h3",{id:"configure-the-cache-size"},"Configure the cache size"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\ncln = mpegCoder.MpegClient()\n# Assume that the source frame rate is 29.997\ncln.setParameter(readSize=30, cacheSize=60)\n...\n")),(0,i.kt)("h3",{id:"use-multi-thread-decoding"},"Use multi-thread decoding"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\ncln = mpegCoder.MpegClient()\ncln.setParameter(nthread=8)\n...\n")))}f.isMDXComponent=!0},2895:function(e,t){t.Z={body:'0&&(c=l.getRangeAt(0)),r.append(a),a.select(),a.selectionStart=0,a.selectionEnd=e.length;var i=!1;try{i=document.execCommand("copy")}catch(s){}a.remove(),c&&(l.removeAllRanges(),l.addRange(c)),o&&o.focus()}(t),l(!0),c.current=window.setTimeout((function(){l(!1)}),1e3)}),[t]);return(0,r.useEffect)((function(){return function(){return window.clearTimeout(c.current)}}),[]),r.createElement("button",{type:"button","aria-label":o?(0,V.I)({id:"theme.CodeBlock.copied",message:"Copied",description:"The copied button label on code blocks"}):(0,V.I)({id:"theme.CodeBlock.copyButtonAriaLabel",message:"Copy code to clipboard",description:"The ARIA label for copy code blocks button"}),title:(0,V.I)({id:"theme.CodeBlock.copy",message:"Copy",description:"The copy button label on code blocks"}),className:(0,u.Z)("clean-btn",n,F.copyButton,o&&F.copyButtonCopied),onClick:i},r.createElement("span",{className:F.copyButtonIcons,"aria-hidden":"true"},r.createElement("svg",{className:F.copyButtonIcon,viewBox:"0 0 24 24"},r.createElement("path",{d:"M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"})),r.createElement("svg",{className:F.copyButtonSuccessIcon,viewBox:"0 0 24 24"},r.createElement("path",{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}))))}var G="wordWrapButtonIcon_azs1",$="wordWrapButtonEnabled_Geot";function U(e){var t=e.className,n=e.onClick,a=e.isEnabled,o=(0,V.I)({id:"theme.CodeBlock.wordWrapToggle",message:"Toggle word wrap",description:"The title attribute for toggle word wrapping button of code block lines"});return r.createElement("button",{type:"button",onClick:n,className:(0,u.Z)("clean-btn",t,a&&$),"aria-label":o,title:o},r.createElement("svg",{className:G,viewBox:"0 0 24 24","aria-hidden":"true"},r.createElement("path",{fill:"currentColor",d:"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"})))}function Y(e){var t,n,a,l,c,i,s,m,f,v,g,y=e.children,b=e.className,k=void 0===b?"":b,N=e.metastring,L=e.title,C=e.showLineNumbers,x=e.language,j=(0,d.L)().prism,_=j.defaultLanguage,w=j.magicComments,H=null!=(t=null!=x?x:null==(n=k.split(" ").find((function(e){return e.startsWith("language-")})))?void 0:n.replace(/language-/,""))?t:_,O=p(),S=(a=(0,r.useState)(!1),l=a[0],c=a[1],i=(0,r.useState)(!1),s=i[0],m=i[1],f=(0,r.useRef)(null),v=(0,r.useCallback)((function(){var e=f.current.querySelector("code");l?e.removeAttribute("style"):e.style.whiteSpace="pre-wrap",c((function(e){return!e}))}),[f,l]),g=(0,r.useCallback)((function(){var e=f.current,t=e.scrollWidth>e.clientWidth||f.current.querySelector("code").hasAttribute("style");m(t)}),[f]),(0,r.useEffect)((function(){g()}),[l,g]),(0,r.useEffect)((function(){return window.addEventListener("resize",g,{passive:!0}),function(){window.removeEventListener("resize",g)}}),[g]),{codeBlockRef:f,isEnabled:l,isCodeScrollable:s,toggle:v}),A=function(e){var t,n;return null!=(t=null==e||null==(n=e.match(h))?void 0:n.groups.title)?t:""}(N)||L,I=E(y,{metastring:N,language:H,magicComments:w}),P=I.lineClassNames,z=I.code,R=C||function(e){return(null==e?void 0:e.includes("showLineNumbers"))||!1}(N);return r.createElement(B,{as:"div",className:(0,u.Z)(k,H&&!k.includes("language-"+H)&&"language-"+H)},A&&r.createElement("div",{className:Z.codeBlockTitle},A),r.createElement("div",{className:Z.codeBlockContent},r.createElement(M,(0,o.Z)({},T,{theme:O,code:z,language:null!=H?H:"text"}),(function(e){var t=e.className,n=e.tokens,a=e.getLineProps,o=e.getTokenProps;return r.createElement("pre",{tabIndex:0,ref:S.codeBlockRef,className:(0,u.Z)(t,Z.codeBlock,"thin-scrollbar")},r.createElement("code",{className:(0,u.Z)(Z.codeBlockLines,R&&Z.codeBlockLinesWithNumbering)},n.map((function(e,t){return r.createElement(W,{key:t,line:e,getLineProps:a,getTokenProps:o,classNames:P[t],showLineNumbers:R})}))))})),r.createElement("div",{className:Z.buttonGroup},(S.isEnabled||S.isCodeScrollable)&&r.createElement(U,{className:Z.codeButton,onClick:function(){return S.toggle()},isEnabled:S.isEnabled}),r.createElement(q,{className:Z.codeButton,code:z}))))}var Q=["children"];function X(e){var t=e.children,n=(0,l.Z)(e,Q),a=(0,s.Z)(),c=function(e){return r.Children.toArray(e).some((function(e){return(0,r.isValidElement)(e)}))?e:Array.isArray(e)?e.join(""):e}(t),i="string"==typeof c?Y:x;return r.createElement(i,(0,o.Z)({key:String(a)},n),c)}var J=n(9960);var K=n(6043),ee="details_lb9f",te="isBrowser_bmU9",ne="collapsibleContent_i85q",re=["summary","children"];function ae(e){return!!e&&("SUMMARY"===e.tagName||ae(e.parentElement))}function oe(e,t){return!!e&&(e===t||oe(e.parentElement,t))}function le(e){var t=e.summary,n=e.children,a=(0,l.Z)(e,re),o=(0,s.Z)(),c=(0,r.useRef)(null),i=(0,K.u)({initialState:!a.open}),m=i.collapsed,d=i.setCollapsed,p=(0,r.useState)(a.open),f=p[0],v=p[1];return r.createElement("details",Object.assign({},a,{ref:c,open:f,"data-collapsed":m,className:(0,u.Z)(ee,o&&te,a.className),onMouseDown:function(e){ae(e.target)&&e.detail>1&&e.preventDefault()},onClick:function(e){e.stopPropagation();var t=e.target;ae(t)&&oe(t,c.current)&&(e.preventDefault(),m?(d(!1),v(!0)):d(!0))}}),t||r.createElement("summary",null,"Details"),r.createElement(K.z,{lazy:!1,collapsed:m,disableSSRStyle:!0,onCollapseTransitionEnd:function(e){d(e),v(!e)}},r.createElement("div",{className:ne},n)))}var ce="details_BAp3";function ie(e){var t=Object.assign({},e);return r.createElement(le,(0,o.Z)({},t,{className:(0,u.Z)("alert alert--info",ce,t.className)}))}var se=n(9649);function ue(e){return r.createElement(se.Z,e)}var me="img_E7b_";var de={head:function(e){var t=r.Children.map(e.children,(function(e){return function(e){var t,n;if(null!=e&&null!=(t=e.props)&&t.mdxType&&null!=e&&null!=(n=e.props)&&n.originalType){var a=e.props,o=(a.mdxType,a.originalType,(0,l.Z)(a,i));return r.createElement(e.props.originalType,o)}return e}(e)}));return r.createElement(c.Z,e,t)},code:function(e){var t=["a","b","big","i","span","em","strong","sup","sub","small"];return r.Children.toArray(e.children).every((function(e){return"string"==typeof e&&!e.includes("\n")||(0,r.isValidElement)(e)&&t.includes(e.props.mdxType)}))?r.createElement("code",e):r.createElement(X,e)},a:function(e){return r.createElement(J.Z,e)},pre:function(e){var t;return r.createElement(X,(0,r.isValidElement)(e.children)&&"code"===e.children.props.originalType?null==(t=e.children)?void 0:t.props:Object.assign({},e))},details:function(e){var t=r.Children.toArray(e.children),n=t.find((function(e){var t;return"summary"===(null==e||null==(t=e.props)?void 0:t.mdxType)})),a=r.createElement(r.Fragment,null,t.filter((function(e){return e!==n})));return r.createElement(ie,(0,o.Z)({},e,{summary:n}),a)},ul:function(e){return r.createElement("ul",(0,o.Z)({},e,{className:(t=e.className,(0,u.Z)(t,(null==t?void 0:t.includes("contains-task-list"))&&"clean-list"))}));var t},img:function(e){return r.createElement("img",(0,o.Z)({loading:"lazy"},e,{className:(t=e.className,(0,u.Z)(t,me))}));var t},h1:function(e){return r.createElement(ue,(0,o.Z)({as:"h1"},e))},h2:function(e){return r.createElement(ue,(0,o.Z)({as:"h2"},e))},h3:function(e){return r.createElement(ue,(0,o.Z)({as:"h3"},e))},h4:function(e){return r.createElement(ue,(0,o.Z)({as:"h4"},e))},h5:function(e){return r.createElement(ue,(0,o.Z)({as:"h5"},e))},h6:function(e){return r.createElement(ue,(0,o.Z)({as:"h6"},e))}};function pe(e){var t=e.children;return r.createElement(a.Zo,{components:de},t)}},1575:function(e,t,n){"use strict";n.d(t,{Z:function(){return u}});var r=n(3117),a=n(102),o=n(7294),l=n(6010),c=n(721),i="tableOfContents_cNA8",s=["className"];function u(e){var t=e.className,n=(0,a.Z)(e,s);return o.createElement("div",{className:(0,l.Z)(i,"thin-scrollbar",t)},o.createElement(c.Z,(0,r.Z)({},n,{linkClassName:"table-of-contents__link toc-highlight",linkActiveClassName:"table-of-contents__link--active"})))}},721:function(e,t,n){"use strict";n.d(t,{Z:function(){return h}});var r=n(3117),a=n(102),o=n(7294);function l(e){var t=e.toc,n=e.className,r=e.linkClassName,a=e.isChild;return t.length?o.createElement("ul",{className:a?void 0:n},t.map((function(e){return o.createElement("li",{key:e.id},o.createElement("a",{href:"#"+e.id,className:null!=r?r:void 0,dangerouslySetInnerHTML:{__html:e.value}}),o.createElement(l,{isChild:!0,toc:e.children,className:n,linkClassName:r}))}))):null}var c=o.memo(l),i=["parentIndex"];function s(e){var t=e.map((function(e){return Object.assign({},e,{parentIndex:-1,children:[]})})),n=Array(7).fill(-1);t.forEach((function(e,t){var r=n.slice(2,e.level);e.parentIndex=Math.max.apply(Math,r),n[e.level]=t}));var r=[];return t.forEach((function(e){var n=e.parentIndex,o=(0,a.Z)(e,i);n>=0?t[n].children.push(o):r.push(o)})),r}function u(e){var t=e.toc,n=e.minHeadingLevel,r=e.maxHeadingLevel;return t.flatMap((function(e){var t=u({toc:e.children,minHeadingLevel:n,maxHeadingLevel:r});return function(e){return e.level>=n&&e.level<=r}(e)?[Object.assign({},e,{children:t})]:t}))}var m=n(6668);function d(e){var t=e.getBoundingClientRect();return t.top===t.bottom?d(e.parentNode):t}function p(e,t){var n,r,a=t.anchorTopOffset,o=e.find((function(e){return d(e).top>=a}));return o?function(e){return e.top>0&&e.bottomresetPath
",id:"resetpath",level:3},{value:"Requires",id:"requires",level:4},{value:"getParameter
",id:"getparameter",level:3},{value:"Requires",id:"requires",level:4},{value:"Returns",id:"returns",level:4},{value:"setParameter
",id:"setparameter",level:3},{value:"Requires",id:"requires",level:4},{value:"FFmpegSetup
",id:"ffmpegsetup",level:3},{value:"Requires",id:"requires",level:4},{value:"dumpFile
",id:"dumpfile",level:3},{value:"EncodeFrame
",id:"encodeframe",level:3},{value:"Requires",id:"requires",level:4},{value:"Returns",id:"returns",level:4},{value:"FFmpegClose
",id:"ffmpegclose",level:3},{value:"Operators",id:"operators",level:2},{value:"__str__
",id:"__str__",level:3},{value:"Returns",id:"returns",level:4},{value:"Examples",id:"examples",level:2},{value:"Optimize the video encoding",id:"optimize-the-video-encoding",level:3},{value:"Rescale and resample the video",id:"rescale-and-resample-the-video",level:3},{value:"Use the AV1 encoder",id:"use-the-av1-encoder",level:3},{value:"Use multi-thread encoding",id:"use-multi-thread-encoding",level:3}],f={toc:g};function v(e){var t=e.components,a=(0,r.Z)(e,s);return(0,i.kt)("wrapper",(0,n.Z)({},f,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,(0,i.kt)(l.Z,{icon:o.Z,mdxType:"InlineIcon"})," Class",(0,i.kt)(c.q,{mdxType:"Splitter"}),(0,i.kt)(c.A,{ver:"3.1.0",url:"MpegCoder.h#L82",mdxType:"SourceURL"},(0,i.kt)(l.Z,{icon:m.Z,mdxType:"InlineIcon"})," Source")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc = mpegCoder.MpegEncoder()\n")),(0,i.kt)("p",null,"The frame-level video encoder used for muxing a video file."),(0,i.kt)("p",null,"This encoder instance serves as a video file writer. It supports:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Encode a 3D ",(0,i.kt)("a",{parentName:"li",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"}))," as a video frame."),(0,i.kt)("li",{parentName:"ul"},"Configure the codec type and the video parameters."),(0,i.kt)("li",{parentName:"ul"},"Scaling the encoded video frames to a specific size.")),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"MpegEncoder")," requires users to initialize the encoder before writing frames, and close the video after finishing all works. If the video is not closed manually, an automatical closing would be performed when the encoder is destructed. During the distruction, hitting ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"C")," will cause the written video to break."),(0,i.kt)("h2",{id:"arguments"},"Arguments"),(0,i.kt)("p",null,"This class does not has initialization arguments."),(0,i.kt)("h2",{id:"methods"},"Methods"),(0,i.kt)("h3",{id:"clear"},(0,i.kt)("inlineCode",{parentName:"h3"},"clear")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.clear()\n")),(0,i.kt)("p",null,"Clear all configurations ",(0,i.kt)("strong",{parentName:"p"},"including")," the default video path. If a video is opened by the encoder, ",(0,i.kt)("inlineCode",{parentName:"p"},"clear()")," will close the video automatically."),(0,i.kt)("div",{className:"admonition admonition-tip alert alert--success"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"12",height:"16",viewBox:"0 0 12 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z"}))),"tip")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"We suggest that users should call ",(0,i.kt)("inlineCode",{parentName:"p"},"clear()")," manually, like using other file writers."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"resetpath"},(0,i.kt)("inlineCode",{parentName:"h3"},"resetPath")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.resetPath(videoPath)\n")),(0,i.kt)("p",null,"Reset the default video path to a specific value. Configuring this value will not cause the video to be opened. This method is merely used as a configuration."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)(l.Z,{icon:p.Z,mdxType:"InlineIcon"})),(0,i.kt)("td",{parentName:"tr",align:"left"},"The path of the video to be written.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"getparameter"},(0,i.kt)("inlineCode",{parentName:"h3"},"getParameter")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"param = enc.getParameter(paramName=None)\n")),(0,i.kt)("p",null,"Get the video parameter or configuration value. Each time ",(0,i.kt)("inlineCode",{parentName:"p"},"paramName")," only accepts one parameter name."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"paramName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the parameter to be checked. If not give, all important parameters, including some private parameters will be returned as a ",(0,i.kt)("inlineCode",{parentName:"td"},"dict"),".")))),(0,i.kt)("p",null,"Here is a list of checkable ",(0,i.kt)("inlineCode",{parentName:"p"},"paramName"),":"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Parameter"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The current path of the written video. If the video is not opened, will return the default video path.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"codecName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the encoder. See ",(0,i.kt)("a",{parentName:"td",href:"https://ffmpeg.org/ffmpeg-codecs.html#toc-Video-Encoders",title:"Video encoders of FFMpeg"},"here",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"}))," to view a list of FFMpeg encoders. Note that not all encoders could be used, the avaliable encoders depends on the current FFMpeg built libraries.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"nthread")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of encoder threads.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"bitRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The bit rate of the written video (Kb/s). This value determines the output video size directly.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"width")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the written video. This value is mainly determined by the user configurations.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"height")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the written video. This value is mainly determined by the user configurations.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"widthSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"width"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"heightSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"height"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"GOPSize")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The size of one ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/Group_of_pictures",title:"Group of pictures | Wikipedia"},"GOP",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"maxBframe")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The maximal number of consecutive B frames in a GOP. In most cases, this value could not be greater than ",(0,i.kt)("inlineCode",{parentName:"td"},"16"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"frameRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The target frame rate of the written video. The unit is FPS.")))),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"param")),(0,i.kt)("td",{parentName:"tr",align:"center"},"Determined by ",(0,i.kt)("inlineCode",{parentName:"td"},"paramName")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The returned value of the parameter. If no ",(0,i.kt)("inlineCode",{parentName:"td"},"paramName")," is given, will return all important parameters.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"setparameter"},(0,i.kt)("inlineCode",{parentName:"h3"},"setParameter")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.setParameter(\n decoder=None, configDict=None, videoPath=None, codecName=None,\n nthread=None, bitRate=None, width=None, height=None, widthSrc=None, heightSrc=None,\n GOPSize=None, maxBframe=None, frameRate=None\n)\n")),(0,i.kt)("p",null,"Set the configurations of the encoder. To make the configurations take effects, these parameters need to be configured before ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegSetup()")),"."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"decoder")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("a",{parentName:"td",href:"./MpegDecoder"},(0,i.kt)("inlineCode",{parentName:"a"},"MpegDecoder"))," or ",(0,i.kt)("a",{parentName:"td",href:"./MpegClient"},(0,i.kt)("inlineCode",{parentName:"a"},"MpegClient"))),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"When configure this argument, the required configurations will be copied from a decoder or a client. If users also provide duplicated arguments in the same call, these copied parameters have a lower preference than those specified by users. This argument is useful when trancoding a video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"configDict")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"dict")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"An alternative of the argument ",(0,i.kt)("inlineCode",{parentName:"td"},"decoder")," when the parameters need to be passed through different processes. Using ",(0,i.kt)("inlineCode",{parentName:"td"},"configDict=decoder.getParameter()")," is equivalent to using ",(0,i.kt)("inlineCode",{parentName:"td"},"decoder=decoder"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The current path of the written video. If the video is not opened, will return the default video path.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"codecName")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The name of the encoder. See ",(0,i.kt)("a",{parentName:"td",href:"https://ffmpeg.org/ffmpeg-codecs.html#toc-Video-Encoders",title:"Video encoders of FFMpeg"},"here",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"}))," to view a list of FFMpeg encoders. Note that not all encoders could be used, the avaliable encoders depends on the current FFMpeg built libraries.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"nthread")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The number of encoder threads.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"bitRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"float")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The bit rate of the written video (Kb/s). This value determines the output video size directly.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"width")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the written video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"height")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the written video.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"widthSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The width of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"width"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"heightSrc")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The height of the source frame. This value should be consistent with the size of the ",(0,i.kt)("a",{parentName:"td",href:"https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html",title:"np.ndarray"},(0,i.kt)("inlineCode",{parentName:"a"},"np.ndarray"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),". If not given, will use ",(0,i.kt)("inlineCode",{parentName:"td"},"height"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"GOPSize")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The size of one ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/Group_of_pictures",title:"Group of pictures | Wikipedia"},"GOP",(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"maxBframe")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"int")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The maximal number of consecutive B frames in a GOP. In most cases, this value could not be greater than ",(0,i.kt)("inlineCode",{parentName:"td"},"16"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"frameRate")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"tuple")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The target frame rate of the written video. This value should be a tuple of two ",(0,i.kt)("inlineCode",{parentName:"td"},"int"),"s: ",(0,i.kt)("inlineCode",{parentName:"td"},"(numerator, denominator)"),". This format is consistent with ",(0,i.kt)("a",{parentName:"td",href:"https://ffmpeg.org/doxygen/trunk/structAVRational.html",title:"AVRational"},(0,i.kt)("inlineCode",{parentName:"a"},"AVRational"),(0,i.kt)(d.Z,{mdxType:"IconExternalLink"})),".")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"ffmpegsetup"},(0,i.kt)("inlineCode",{parentName:"h3"},"FFmpegSetup")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.FFmpegSetup(videoPath=None)\n")),(0,i.kt)("p",null,"Open the video file, and initialize the encoder. During the encoder initialization, the codec and the video format will be configured according to the file name and the user configurations set by ",(0,i.kt)("a",{parentName:"p",href:"#setparameter"},(0,i.kt)("inlineCode",{parentName:"a"},"setParameter()")),". If an video is being opened by the encoder now, this video will be closed first, then the new video will be opened with the same configurations."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"videoPath")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"bytes")),(0,i.kt)("td",{parentName:"tr",align:"center"}),(0,i.kt)("td",{parentName:"tr",align:"left"},"The path of the video to be written. If not given, will use the default path configured by ",(0,i.kt)("a",{parentName:"td",href:"#resetpath"},(0,i.kt)("inlineCode",{parentName:"a"},"resetPath()")),". Setting this argument will also cause the default video path to change.")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"dumpfile"},(0,i.kt)("inlineCode",{parentName:"h3"},"dumpFile")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.dumpFile()\n")),(0,i.kt)("p",null,"Print out a brief preview of the video meta-data to the standard output."),(0,i.kt)("div",{className:"admonition admonition-caution alert alert--warning"},(0,i.kt)("div",{parentName:"div",className:"admonition-heading"},(0,i.kt)("h5",{parentName:"div"},(0,i.kt)("span",{parentName:"h5",className:"admonition-icon"},(0,i.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16"},(0,i.kt)("path",{parentName:"svg",fillRule:"evenodd",d:"M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"}))),"caution")),(0,i.kt)("div",{parentName:"div",className:"admonition-content"},(0,i.kt)("p",{parentName:"div"},"This method is based on C stdout. Therefore, these results could not be redirected or catched by python."))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"encodeframe"},(0,i.kt)("inlineCode",{parentName:"h3"},"EncodeFrame")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"is_success = enc.EncodeFrame(PyArrayFrame)\n")),(0,i.kt)("p",null,"Encode one frame into the video. Note that in most cases, the frame will not be written to the file instantly. Instead of, the frames will be saved in a low-level buffer of the codec. Only when ",(0,i.kt)("a",{parentName:"p",href:"#ffmpegclose"},(0,i.kt)("inlineCode",{parentName:"a"},"FFmpegClose()"))," is called, the frames in the buffer will be flushed into the file."),(0,i.kt)("h4",{id:"requires"},"Requires"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Required"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"PyArrayFrame")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"np.ndarray")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)(l.Z,{icon:p.Z,mdxType:"InlineIcon"})),(0,i.kt)("td",{parentName:"tr",align:"left"},"An array with a shape of ",(0,i.kt)("inlineCode",{parentName:"td"},"(H, W, C)"),", where ",(0,i.kt)("inlineCode",{parentName:"td"},"(H, W)")," are the source height (",(0,i.kt)("inlineCode",{parentName:"td"},"heightSrc"),") and source width (",(0,i.kt)("inlineCode",{parentName:"td"},"widthSrc"),") respectively. ",(0,i.kt)("inlineCode",{parentName:"td"},"C")," means the 3 RGB channel.")))),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"is_success")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"bool")),(0,i.kt)("td",{parentName:"tr",align:"left"},"The status of the frame encoding. If the given frame succeeds to be encoded, will return ",(0,i.kt)("inlineCode",{parentName:"td"},"True"),"; Otherwise, will return ",(0,i.kt)("inlineCode",{parentName:"td"},"False"),".")))),(0,i.kt)("hr",null),(0,i.kt)("h3",{id:"ffmpegclose"},(0,i.kt)("inlineCode",{parentName:"h3"},"FFmpegClose")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"enc.FFmpegClose()\n")),(0,i.kt)("p",null,"Close the video file. Calling this method will flush all buffered frames into the file. Then the video tail will be writen to the file. If users does not call this method explicitly, it will be called when ",(0,i.kt)("a",{parentName:"p",href:"#clear"},(0,i.kt)("inlineCode",{parentName:"a"},"clear()"))," is called or when the encoder is destructed."),(0,i.kt)("h2",{id:"operators"},"Operators"),(0,i.kt)("h3",{id:"__str__"},(0,i.kt)("inlineCode",{parentName:"h3"},"__str__")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"info = str(enc)\n")),(0,i.kt)("p",null,"Return a brief report of the current encoder status."),(0,i.kt)("h4",{id:"returns"},"Returns"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:"center"},"Argument"),(0,i.kt)("th",{parentName:"tr",align:"center"},"Type"),(0,i.kt)("th",{parentName:"tr",align:"left"},(0,i.kt)("div",{className:"center"},"Description")))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"info")),(0,i.kt)("td",{parentName:"tr",align:"center"},(0,i.kt)("inlineCode",{parentName:"td"},"str")),(0,i.kt)("td",{parentName:"tr",align:"left"},"A brief report of the encoder status, the configurations and parameters will be listed as formatted texts.")))),(0,i.kt)("h2",{id:"examples"},"Examples"),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"../examples/transcoding"},(0,i.kt)("em",{parentName:"a"},(0,i.kt)("inlineCode",{parentName:"em"},"Transcoding")))," in the tutorial. Here we also show some specific configurations:"),(0,i.kt)("h3",{id:"optimize-the-video-encoding"},"Optimize the video encoding"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\ndec = mpegCoder.MpegDecoder()\n...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(decoder=dec, codecName='libx265', videoPath='test-video-x265.mp4', GOPSize=24, maxBframe=16)\n...\n")),(0,i.kt)("h3",{id:"rescale-and-resample-the-video"},"Rescale and resample the video"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(width=1280, height=720, frameRate=(5, 1), codecName='libx265', videoPath='test-video-x265.mp4')\n...\n")),(0,i.kt)("h3",{id:"use-the-av1-encoder"},"Use the AV1 encoder"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(width=1280, height=720, codecName='libsvtav1', videoPath='test-video-av1.mp4')\n...\n")),(0,i.kt)("h3",{id:"use-multi-thread-encoding"},"Use multi-thread encoding"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-python"},"...\nenc = mpegCoder.MpegEncoder()\nenc.setParameter(nthread=8)\n...\n")))}v.isMDXComponent=!0},2895:function(e,t){t.Z={body:'