abhiTronix / vidgear

A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features :fire:
https://abhitronix.github.io/vidgear
Apache License 2.0
3.39k stars 255 forks source link

[Proposal]: -vcodec copy HLS #396

Closed juniorcines closed 5 months ago

juniorcines commented 6 months ago

Issue guidelines

Issue Checklist

Describe your Idea

Hello, I would like the option that if the original quality is used, one can specify if they want to do:

-vcodec: copy

I say this because most of us could have the video in H264 and we just want to use the original quality and have it in HLS.

So with this option it would be faster to convert the videos to HLS.

Use Cases

-vcodec: copy

transfer the video to HLS faster if the original quality is used without the option of multiple qualities

Any other Relevant Information?

No response

welcome[bot] commented 6 months ago

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

abhiTronix commented 6 months ago

@juniorcines Thank you for the suggestion. Adding an option to copy the existing video codec (vcodec copy) when transcoding to HLS (or DASH) can be a useful optimization, especially when the input video is already encoded in a already compatible format like H.264. It's a great quality-of-life improvement that can make the transcoding workflow in StreamGear more efficient for many users. 👍🏼

juniorcines commented 6 months ago

Thanks to you, and if when we only want to use the default quality to pass it to HLS, if it is already in H264, using copy is good to pass it quickly without consuming a lot of resources.

I use it in Nodejs, but I would like to have this in Python with your library.

abhiTronix commented 5 months ago

Stream copy successfully introduced for Single Source mode in StreamGear API in commit https://github.com/abhiTronix/vidgear/commit/d4243ab164ed00020ba66c825a7b920ebd5c44ca

abhiTronix commented 5 months ago

:warning: It is incompatible with Real-time Frames Mode as it requires re-encoding of incoming frames.

juniorcines commented 5 months ago

⚠️ It is incompatible with Real-time Frames Mode as it requires re-encoding of incoming frames.

In this code could you tell me how it could be used? What about copy?

`# import required libraries from vidgear.gears import StreamGear

activate Single-Source Mode with valid video input

stream_params = {"-video_source": "foo.mp4"}

describe a suitable master playlist location/name and assign params

streamer = StreamGear(output="hls_out.m3u8", format = "hls", **stream_params)

trancode source

streamer.transcode_source()

terminate

streamer.terminate() `

juniorcines commented 5 months ago

code python

My code is in Spanish.

But what my code does is create an array with the list of multiple qualities downgrade + the original quality since your system always adds the original quality.

so I made it so that if there are multiple qualities it is used:

stream_params["-vcodec"] = "h264_nvenc"
stream_params["-streams"] = streams

and if not multiple qualities, then only the original quality that is used:

stream_params["-vcodec"] = "copy"

which would be to move to HLS faster, the video is in H264.

but I get the following error with the video regardless of whether it is original quality or multiple quality

error python

abhiTronix commented 5 months ago

⚠️ It is incompatible with Real-time Frames Mode as it requires re-encoding of incoming frames.

In this code could you tell me how it could be used? What about copy?

`# import required libraries from vidgear.gears import StreamGear

activate Single-Source Mode with valid video input

stream_params = {"-video_source": "foo.mp4"}

describe a suitable master playlist location/name and assign params

streamer = StreamGear(output="hls_out.m3u8", format = "hls", **stream_params)

trancode source

streamer.transcode_source()

terminate

streamer.terminate() `

@juniorcines Yeah sure. Please wait.

abhiTronix commented 5 months ago

My code is in Spanish.

But what my code does is create an array with the list of multiple qualities downgrade + the original quality since your system always adds the original quality.

so I made it so that if there are multiple qualities it is used:

stream_params["-vcodec"] = "h264_nvenc" stream_params["-streams"] = streams and if not multiple qualities, then only the original quality that is used:

stream_params["-vcodec"] = "copy"

which would be to move to HLS faster, the video is in H264.

but I get the following error with the video regardless of whether it is original quality or multiple quality

@juniorcines The changes hasn't been released yet, and you're using old version of vidgear. The v0.3.3 will be released in few day, for using it right now, you need to clone and install our testing branch from source as follows:

# clone the repository and get inside
git clone https://github.com/abhiTronix/vidgear.git && cd vidgear

# checkout the latest testing branch
git checkout testing

# Install latest stable release with all Core dependencies
pip install -U .[core]

# Or Install latest stable release with all Core & Asyncio dependencies
pip install -U .[asyncio]

Then you could use stream copy as follows:

# import required libraries
from vidgear.gears import StreamGear

# activate Single-Source Mode
stream_params = {
    "-video_source": "foo.mp4",
    "-vcodec": "copy",
}
# describe a suitable master playlist location/name and assign params
streamer = StreamGear(output="hls_out.m3u8", format = "hls", **stream_params)
# trancode source
streamer.transcode_source()
# terminate
streamer.terminate()

Or with multiple streams:

# import required libraries
from vidgear.gears import StreamGear

# activate Single-Source Mode and also define various streams
stream_params = {
    "-video_source": "foo.mp4",
    "-vcodec": "copy",
    "-streams": [
        {"-resolution": "1280x720", "-framerate": 30.0},  # Stream2: 1280x720 at 30fps framerate
        {"-resolution": "640x360", "-framerate": 60.0},  # Stream3: 640x360 at 60fps framerate
        {"-resolution": "320x240", "-video_bitrate": "500k"},  # Stream3: 320x240 at 500kbs bitrate
    ],
}
# describe a suitable master playlist location/name and assign params
streamer = StreamGear(output="hls_out.m3u8", format = "hls", **stream_params)
# trancode source
streamer.transcode_source()
# terminate
streamer.terminate()
abhiTronix commented 5 months ago

@juniorcines If you still encounter any errors, do let me know. goodluck!

juniorcines commented 5 months ago

I have a question, when using:

"-vcodec": "copy",

When using it in multiple streams, in the end the video would have the same quality, and video bitrate wouldn't it?

since it is being used:

"-vcodec": "copy",

I thought that "-vcodec": "copy", It was only used without multiple streams.

abhiTronix commented 5 months ago

I thought that "-vcodec": "copy", It was only used without multiple streams.

@juniorcines True, I'll update that.

abhiTronix commented 5 months ago

I thought that "-vcodec": "copy", It was only used without multiple streams.

@juniorcines This is fixed in https://github.com/abhiTronix/vidgear/commit/e533553214b1b931dbf211679abd56b2acfba215

juniorcines commented 5 months ago

Hi, when will this version be released?

abhiTronix commented 5 months ago

Hi, when will this version be released?

@juniorcines The vidgear v0.3.3 is now released: https://pypi.org/project/vidgear/