nginx-vod-module icon indicating copy to clipboard operation
nginx-vod-module copied to clipboard

Does this package use ffmpeg for Repackaging?

Open Saeeed-B opened this issue 1 year ago • 5 comments

Does this package use ffmpeg for Repackaging?

And whether it is possible to make a Repackager like this with Python?

Saeeed-B avatar Feb 06 '24 15:02 Saeeed-B

  1. 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.
  2. You can implement anything you want in python, but it's not related to this module...

erankor avatar Feb 06 '24 22:02 erankor

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)

Saeeed-B avatar Feb 07 '24 04:02 Saeeed-B

You are transcoding the video with this command, it is expected to be slow. If -

  1. You only need to cut the video
  2. The source video is already using web-playable codecs
  3. 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 avatar Feb 17 '24 08:02 erankor

@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.

Saeeed-B avatar Feb 17 '24 19:02 Saeeed-B

Can we calculate how many bytes each second or each frame is and separate it into 2 seconds ?

Saeeed-B avatar Feb 17 '24 19:02 Saeeed-B