How to prevent nvvidconv from scaling during cropping?

Hi,

Whenever I try to use nvvidconv to crop, it crops the video, but also scales the cropped video back to the resolution of the original video. Is there any flags or way to prevent this from happening?

Please share pipeline to reproduce the issue. Are you on r28.1? What is the video resolution?

I tried on my tx1 and tx2, both have r28.1. The camera records in 4k, 3840x2160.

I use this command to preview crop:
gst-launch-1.0 filesrc location=/media/ssd/test.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=1000 ! autovideosink

On my TX2 when I save the file it crops the video, scales the height, and saves it as 3840x2160. On my tx1 it runs for 0.6 seconds and then an error is thrown. You can ignore the tx1 issue for now, error below. How do I save the cropped region without scaling back to the original resolution?

Save file:
gst-launch-1.0 filesrc location=/media/ssd/test.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3839 top=0 bottom=1000 ! omxh264enc control-rate=2 bitrate=20000000 profile=8 ! ‘video/x-h264,stream-format=(string)byte-stream’ ! h264parse ! qtmux ! filesink location=/media/ssd/test_hardware_crop.mp4 -e

Please let me know if any other information is needed.

Error thrown by tx1:
gst-launch-1.0 filesrc location=/media/ssd/test.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=1000 ! autovideosink
Setting pipeline to PAUSED …
Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and MjstreamingPipeline is PREROLLING …
NvMMLiteOpen : Block : BlockType = 261
TVMR: NvMMLiteTVMRDecBlockOpen: 7580: NvMMLiteBlockOpen
NvMMLiteBlockCreate : Block : BlockType = 261
TVMR: cbBeginSequence: 1166: BeginSequence 3840x2160, bVPR = 0, fFrameRate = 0.000000
TVMR: LowCorner Frequency = 345000
TVMR: cbBeginSequence: 1545: DecodeBuffers = 4, pnvsi->eCodec = 4, codec = 0
TVMR: cbBeginSequence: 1606: Display Resolution : (3840x2160)
TVMR: cbBeginSequence: 1607: Display Aspect Ratio : (3840x2160)
TVMR: cbBeginSequence: 1649: ColorFormat : 5
TVMR: cbBeginSequence:1660 ColorSpace = NvColorSpace_YCbCr709
TVMR: cbBeginSequence: 1790: SurfaceLayout = 3
TVMR: cbBeginSequence: 1868: NumOfSurfaces = 8, InteraceStream = 0, InterlaceEnabled = 0, bSecure = 0, MVC = 0 Semiplanar = 1, bReinit = 1, BitDepthForSurface = 8 LumaBitDepth = 8, ChromaBitDepth = 8, ChromaFormat = 5
Allocating new output: 3840x2160 (x 10), ThumbnailMode = 0
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstSystemClock
TVMR: FrameRate = 54
TVMR: NVDEC LowCorner Freq = (576000 * 1024)
TVMR: NvMMLiteTVMRDecDoWork: 6466: NVMMLITE_TVMR: EOS detected
TVMR: TVMRBufferProcessing: 5444: Processing of EOS
TVMR: TVMRBufferProcessing: 5519: Processing of EOS Done
Got EOS from element “pipeline0”.
Execution ended after 0:00:00.629899948
Setting pipeline to PAUSED …
Setting pipeline to READY …
TVMR: TVMRFrameStatusReporting: 6067: Closing TVMR Frame Status Thread -------------
TVMR: TVMRVPRFloorSizeSettingThread: 5885: Closing TVMRVPRFloorSizeSettingThread -------------
TVMR: TVMRFrameDelivery: 5917: Closing TVMR Frame Delivery Thread -------------
TVMR: NvMMLiteTVMRDecBlockClose: 7740: Done
Setting pipeline to NULL …
Freeing pipeline …

Please try the below command on TX2:

gst-launch-1.0 filesrc location= Foreman_H264.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=1000 ! 'video/x-raw(memoryNVMM),width=3840,height=1000' ! omxh264enc ! qtmux ! filesink location=/tmp/a1.mp4

I tried the command on the tx1 and just recently on the tx2, it didn’t work on either of them. The command changes the metadata to say 3840x1000, but the output video is still 3480x2160.

The original problem persists.

Please check the dumped YUV via

gst-launch-1.0 filesrc location= Foreman_H264.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=1000 ! 'video/x-raw,width=3840,height=1000,format=I420' ! multifilesink location=I420-%05d.yuv
-rw-rw-r--  1 nvidia nvidia  5760000 Sep 22 05:23 I420-00155.yuv
-rw-rw-r--  1 nvidia nvidia  5760000 Sep 22 05:23 I420-00156.yuv
-rw-rw-r--  1 nvidia nvidia  5760000 Sep 22 05:23 I420-00157.yuv
-rw-rw-r--  1 nvidia nvidia  5760000 Sep 22 05:23 I420-00158.yuv
-rw-rw-r--  1 nvidia nvidia  5760000 Sep 22 05:23 I420-00159.yuv
-rw-rw-r--  1 nvidia nvidia  5760000 Sep 22 05:23 I420-00160.yuv

5760000=3840x1000x1.5
The output of nvvidconv is 3840x1000 YUV. The above is verified on r28.1/TX2.

I am getting the same results as you for this test.

-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:46 I420-00000.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:46 I420-00001.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:46 I420-00002.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:46 I420-00003.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:46 I420-00004.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:46 I420-00005.yuv
...
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:47 I420-00678.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:47 I420-00679.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:47 I420-00680.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:47 I420-00681.yuv
-rw-rw-r-- 1 ubuntu ubuntu    5760000 Sep 21 06:47 I420-00682.yuv

Can you please run these commands and visually inspect the playback? The aspect ratios for both are the same for me.

gst-launch-1.0 filesrc location= Foreman_H264.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=500 ! 'video/x-raw(memoryNVMM),width=3840,height=500' ! omxh264enc ! qtmux ! filesink location=/tmp/cropped.mp4
gst-launch-1.0 filesrc location= Foreman_H264.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=2160 ! 'video/x-raw(memoryNVMM),width=3840,height=2160' ! omxh264enc ! qtmux ! filesink location=/tmp/full.mp4

I can see correct AR in playing cropped.mp4

It works! Both vlc player and the default video player in Ubuntu distorted the aspect ratio to make it 16:9. Uploaded to youtube and they also distorted the aspect ratio to 16:9.

Uploaded to aws and their video player showed the video using its true aspect ratio.

Can view properly using vlc if I manually set the aspect ratio in preferences.

Looks like the default aspect ratio is incorrect in the metadata: “SAR 25:108 DAR 16:9”

Is there a way to set it to correspond to the cropped video’s resolution?

avprobe of cropped.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cropped.mp4':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2017-09-22 08:53:50
  Duration: 00:00:14.00, start: 0.000000, bitrate: 4012 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 3840x500, 4008 kb/s, SAR 25:108 DAR 16:9, 30.14 fps, 30 tbr, 3k tbn, 6k tbc (default)
    Metadata:
      creation_time   : 2017-09-22 08:53:50
      handler_name    : VideoHandler

You may try
gst-launch-1.0 filesrc location= Foreman_H264.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv left=0 right=3840 top=0 bottom=500 ! ‘video/x-raw(memoryNVMM),width=3840,height=500,pixel-aspect-ratio=1/1’ ! omxh264enc ! qtmux ! filesink location=/tmp/cropped.mp4

The command worked perfectly, thank you so much DaneLLL!