nginx-vod-module
nginx-vod-module copied to clipboard
Does this package use ffmpeg for Repackaging?
Does this package use ffmpeg for Repackaging?
And whether it is possible to make a Repackager like this with Python?
- No, this module has its own implementation of the packaging, for performance reasons. Ffmpeg is used only for encoding/decoding, in features like audio rate change and thumbnail capture.
- You can implement anything you want in python, but it's not related to this module...
I tried to cut and encode 5 seconds of video using ffmpeg in Python and return the output as a response. But it is very slow, while using all the capacity of the processor.
What do you think can improve the speed of this code?
def run(source, start, chuck):
input = os.path.join(BASE_DIR, source)
main_list = [
'ffmpeg', '-y', '-i', f'{input}',
'-ss', f'0{start}', '-t', f'00:00:05', '-async', '1',
]
main_list += [
'-c:a', 'aac',
'-c:v', 'libx264',
'-preset', 'ultrafast',
'-f', 'segment',
'-segment_time', '5',
'-segment_format', 'mpegts',
'-segment_start_number', f'{chuck}',
f'R:/1080_%03d.ts',
]
result = subprocess.run(main_list, capture_output=True, text=True)
You are transcoding the video with this command, it is expected to be slow. If -
- You only need to cut the video
- The source video is already using web-playable codecs
- The source video has keyframes in the relevant offsets
Then you can avoid the transcode, and just use -c copy
, this will run MUCH faster.
@erankor Thank you, that was a very helpful tip.
What advice can you give about cutting a part of the video without using ffmpeg (assuming that the keyframes are regular every 2 seconds)
I have read all the issues of the repository, as well as part of the code, I know that you do this by reading the atoms of a mp4 file.
But again, I didn't understand exactly how this is done, I just know that ffmpeg is very slow in doing this and it has to be done manually.
Thank you for explaining with a piece of code. Thank You.
Can we calculate how many bytes each second or each frame is and separate it into 2 seconds ?