Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this package use ffmpeg for Repackaging? #1508

Open
Saeeed-B opened this issue Feb 6, 2024 · 5 comments
Open

Does this package use ffmpeg for Repackaging? #1508

Saeeed-B opened this issue Feb 6, 2024 · 5 comments

Comments

@Saeeed-B
Copy link

Saeeed-B commented Feb 6, 2024

Does this package use ffmpeg for Repackaging?

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

@erankor
Copy link
Contributor

erankor commented Feb 6, 2024

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

@Saeeed-B
Copy link
Author

Saeeed-B commented Feb 7, 2024

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)

@erankor
Copy link
Contributor

erankor commented Feb 17, 2024

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.

@Saeeed-B
Copy link
Author

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants