Skip to content

[ce-oem] Implement video codec test transform resize scenario for carmel projec (New) #1746

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ def project_factory(args: argparse.Namespace) -> Any:
height_to=args.height_to,
framerate=args.framerate,
)
elif "carmel" in args.platform:
return CarmelProject(
platform=args.platform,
codec=args.encoder_plugin,
width_from=args.width_from,
height_from=args.height_from,
width_to=args.width_to,
height_to=args.height_to,
framerate=args.framerate,
)
else:
raise SystemExit(
"Error: Cannot get the implementation for '{}'".format(
Expand Down Expand Up @@ -227,6 +237,97 @@ def build_pipeline(self) -> str:
return pipeline


class CarmelProject(PipelineInterface):
"""
carmel project pipeline handle
"""

def __init__(
self,
platform: str,
codec: str,
width_from: int,
height_from: int,
width_to: int,
height_to: int,
framerate: int,
):
self._platform = platform
self._codec = codec
self._width_from = width_from
self._height_from = height_from
self._width_to = width_to
self._height_to = height_to
self._framerate = framerate
self._codec_parser_map = {
GStreamerEncodePlugins.V4L2H264ENC.value: "h264parse"
}
# This sample video file will be consumed by any gstreamer piple as
# input video.
golden_sample_file = "{}p_{}fps_h264.mp4".format(
self._height_from,
self._framerate,
)
self._golden_sample = os.path.join(
VIDEO_CODEC_TESTING_DATA, "video", golden_sample_file
)
self._artifact_file = ""

@property
def artifact_file(self) -> str:
if not self._artifact_file:
self._artifact_file = generate_artifact_name(extension="mp4")
return self._artifact_file

@property
def psnr_reference_file(self) -> str:
"""
A golden reference which has been transformed in advance. It's used to
be the compared reference file for PSNR.
"""
golden_reference = "{}p_30fps_h264.mp4".format(
self._height_to,
)

full_path = os.path.join(
VIDEO_CODEC_TESTING_DATA, "video", golden_reference
)
if not os.path.exists(full_path):
raise SystemExit(
"Error: Golden PSNR reference '{}' doesn't exist".format(
full_path
)
)

return full_path

def build_pipeline(self) -> str:
"""
Build the GStreamer commands based on the platform and codec.

Returns:
str: A GStreamer command based on the platform and
codec.
"""
pipeline = (
"{} -e filesrc location={} ! qtdemux ! queue ! "
"h264parse ! v4l2h264dec capture-io-mode=5 output-io-mode=5 ! "
"qtivtransform ! video/x-raw\\(memory:GBM\\),format=NV12,"
"width={},height={},framerate=30/1 ! "
"v4l2h264enc capture-io-mode=5 output-io-mode=5 ! "
"queue ! h264parse ! mp4mux ! queue ! "
"filesink location={}"
).format(
GST_LAUNCH_BIN,
self._golden_sample,
self._width_to,
self._height_to,
self.artifact_file,
)

return pipeline


def main() -> None:
args = register_arguments()
p = project_factory(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,54 @@
}
]
}
],
"gst_transform_resize": [
{
"encoder_plugin": "v4l2h264enc",
"resolutions": [
{
"width_from": 3840,
"height_from": 2160,
"fps": 30,
"width_to": 1920,
"height_to": 1080
},
{
"width_from": 1920,
"height_from": 1080,
"fps": 30,
"width_to": 1280,
"height_to": 720
},
{
"width_from": 1920,
"height_from": 1080,
"fps": 30,
"width_to": 640,
"height_to": 480
},
{
"width_from": 1920,
"height_from": 1080,
"fps": 30,
"width_to": 3840,
"height_to": 2160
},
{
"width_from": 1280,
"height_from": 720,
"fps": 30,
"width_to": 1920,
"height_to": 1080
},
{
"width_from": 1280,
"height_from": 720,
"fps": 30,
"width_to": 3840,
"height_to": 2160
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,26 @@ category_id: video-codec
estimated_duration: 60s
environ: GST_LAUNCH_BIN, PLAINBOX_SESSION_SHARE, VIDEO_CODEC_TESTING_DATA
command:
gst_encoder_psnr.py -p "{{ platform }}" -ep "{{ encoder_plugin }}" -wi {{ width }} -hi {{ height }} -f "{{ framerate }}"
gst_encoder_psnr.py -p "{{ platform }}" -ep "{{ encoder_plugin }}" -wi {{ width }} -hi {{ height }} -f "{{ framerate }}"

unit: template
template-engine: jinja2
template-resource: video_codec_resource
template-filter:
video_codec_resource.scenario == "gst_transform_resize"
video_codec_resource.platform == "carmel"
template-unit: job
template-id: ce-oem-video-codec/carmel-gst_transform_resize
_template-summary: Check if the resize (scale up or down) are functional
id: ce-oem-video-codec/{{ scenario }}-{{ encoder_plugin }}_from_{{ width_from }}x{{ height_from }}_to_{{ width_to }}x{{ height_to }}
_summary: Perform resize - from {{ width_from }}x{{ height_from }} to {{ width_to }}x{{ height_to }} file
plugin: shell
user: root
category_id: video-codec
estimated_duration: 60s
imports: from com.canonical.plainbox import manifest
requires: manifest.has_video_codec == 'True'
environ: GST_LAUNCH_BIN, PLAINBOX_SESSION_SHARE, VIDEO_CODEC_TESTING_DATA
command:
export XDG_RUNTIME_DIR=/run/user/1000
gst_transform_resize.py -p "{{ platform }}" -ep "{{ encoder_plugin }}" -wf "{{ width_from }}" -hf "{{ height_from }}" -wt "{{ width_to }}" -ht "{{ height_to }}" -f "{{ framerate }}"
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ include:
ce-oem-video-codec/gst_transform_rotate_and_flip
ce-oem-video-codec/genio-gst_transform_resize
ce-oem-video-codec/carmel-gst_encoder_psnr
ce-oem-video-codec/carmel-gst_transform_resize
Loading