[SOLVED] Slicing video with wrong aspect ratio at keyframes without re-encoding?

Started by yetanotherlogin, October 08, 2020, 10:07:30 PM

Previous topic - Next topic

yetanotherlogin

Hello,

When I open the following video, the aspect ratio is wrong (I guess it's shown as 4:3 instead of 16:9):

c:\>ffprobe -i merged.mts
Input #0, mpegts, from 'merged.mts':
  Duration: 01:54:05.95, start: 1.440000, bitrate: 9188 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(top first), 1440x1080 [SAR 4:3 DAR 16:9], 2
5 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s

Is there no way to slice a video at keyframes and get the right aspect ratio without re-encoding thusly?
Video Output: re-encode > Video filters > swsResize
Source PAR : PAL 720:576 DAR 16:9 PAR 64:45
Destination PAR : 1:1

Thank you.

eumagga0x2a

If you mean the display of this video in Avidemux, the pixel aspect ratio in the video preview window is always 1:1 (square pixels), so all anamorphic videos look wrong. This is by design.

Not all (or more precisely, quite few) video players respect display aspect ratio specified via video codec settings, but all (or almost all) respect the display size / display aspect ratio (DAR)  specified at the level of container. This means that you should use an output format which supports storing this information – MP4 and MKV – and force the desired 16:9 DAR in the configuration of the respective muxer.


yetanotherlogin

Thanks. I used the following ffmpeg command to convert the MTS to MP4, but the video still looks wrong when read in AviDemux :

ffmpeg -i merged.mts -c copy merged.mp4
If possible, I'd like to avoid re-encoding to slice at keyframes in AviDemux.

xyzzy

I think eumagga0x2a is saying that since your video is anamorphic, it's always going to display incorrectly in avidemux.  Unless you re-encode it to not be anamorphic (i.e., swresize).

But if you set the DAR to 16:9 in the container, the edited video will play back correctly at 16:9 in a player that does support anamorphic video.  avidmux will split, remux, reencode, etc. the video fine, it just can't play it for you at the correct aspect.

You should be able to add a resize filter to resize to 1:1 SAR 16:19 DAR and turn on play filtered to make the video look ok in avidmux itself.  Then remove the filter before you save/encode.

yetanotherlogin

Thanks for the info.

I didn't know what "anamorphic video" was:
https://en.wikipedia.org/wiki/Anamorphic_format

I'll experiment with my Sony camcorder to see if it can shoot in 16:9 so I can slice at keyframes without re-encoding.

eumagga0x2a

Quote from: yetanotherlogin on October 09, 2020, 08:42:13 AMI'll experiment with my Sony camcorder to see if it can shoot in 16:9 so I can slice at keyframes without re-encoding.

No, no, no, there is nothing wrong with the camcorder and the video. You still haven't got it.

Don't get confused by the way how the proportions of the picture look in Avidemux, just select the MP4 muxer and enable "force aspect ratio" set to "16:9".

yetanotherlogin

Because I'm just Joe shooting a video and trying to cut it only to find that it looks strange when doing so for some reason.

Why does my camcorder handle the video in two different ratios at the same time (1440/1080 = 4/3; DAR 16:9)? What's the point?

General
Format                                   : MPEG-TS

Video
Format/Info                              : Advanced Video Codec
Width                                    : 1 440 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9

Quote from: xyzzy on October 09, 2020, 06:27:20 AMYou should be able to add a resize filter to resize to 1:1 SAR 16:19 DAR and turn on play filtered to make the video look ok in avidmux itself.  Then remove the filter before you save/encode.

How?

yetanotherlogin

Through trial and error, found how to do it:

1. Main window: "Video output", change from "Copy" to "MPEG4-AVC"

2.Video > Filters > Transform > swsResize:
Source PAR : PAL 720:576 DAR 16:9 PAR 64:45
Destination PAR : 1:1

3. Video > Play Filtered

4. Play video in AviDemux to check that the aspect ratio was fixed.

5. Select part at keyframes through A/B, remove video filter (ie. back to "Copy"), export selected part, play in VLC to check.

Thank you!

eumagga0x2a

Quote from: yetanotherlogin on October 09, 2020, 09:56:52 AMWhy does my camcorder handle the video in two different ratios at the same time (1440/1080 = 4/3; DAR 16:9)?

This is a valid Blu-ray resolution. Anamorphic digital video was very handy when normal and wide screen programs needed to be transmitted over the same channel. All SD material is anamorphic.

Quote from: undefinedWhat's the point?

Reducing required bandwidth and storage space?

Quote from: yetanotherlogin on October 09, 2020, 10:11:44 AM4. Play video in AviDemux to check that the aspect ratio was fixed.

What does it solve? The display is still back to the original aspect of the video (with square pixels) when paused.


yetanotherlogin

Thanks for the infos.

Yes, it's one thing that's still annoying: When I stop (there's no "pause" button) playing the video in AviDemux, it goes back to the 4:3 ("streched") mode.

Is there no work-around?

For the next shooting: To solve this issue, is there nothing I can do in the camcorder, or before editing the file in AviDemux?

eumagga0x2a

Quote from: yetanotherlogin on October 09, 2020, 10:28:15 AMWhen I stop (there's no "pause" button) playing the video in AviDemux, it goes back to the 4:3 ("streched") mode.

It is not "stretched", it is real. I recommend to get used to the square-pixel display of anamorphic video in Avidemux. Avidemux is not a video player, it needs to convey the real dimensions and real orientation of the video the user is editing because all filters and encoders operate on the real dimensions.

Quote from: yetanotherlogin on October 09, 2020, 10:28:15 AMFor the next shooting: To solve this issue, is there nothing I can do in the camcorder, or before editing the file in AviDemux?

There is no issue, there is nothing wrong with the camcorder (however, I do prefer cameras doing real FullHD 1920x1080 or 4K), just a technical misunderstanding, IMHO.

Edit: I looks like this camcorder is also capable of recording at 1920x1080. You might consider switching to this mode. However, this increases the size of video stream per time unit by factor two at least, compared to the anamorphic mode.

yetanotherlogin

Yes, I'll experiment with the different mode it supports.

For other newbies' benefit who might happen on this thread while struggling with the same issue... either just accept that AviDemux will display the video with that odd look (which doesn't affect how it'll look after a part is sliced and exported), or make the following change so that it looks normal while AviDemux plays it (but it'll go back to the odd look every time you hit the stop button):

1. Main window: "Video output", change from "Copy" to "MPEG4-AVC"
2. Video > Filters > Transform > swsResize:
   
    Source PAR : PAL 720:576 DAR 16:9 PAR 64:45
    Destination PAR : 1:1
   
    Note: 64/45 = 1,4222, so different from 4:3 (= 1,3333)
     
3. Video > Play Filtered
4. Play the video in AviDemux.
5. To slice at keyframes (ie. without re-encoding), go back to Copy mode, slice video at keyframes, export, play in VLC to check.