Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#1079 closed defect (invalid)

Crop Keep_Aspect option not working

Reported by: ramitb Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

According to the documenation section 24.6 when the keep_aspect ratio is defined and set to a non zero number it is supposed to force the output SAR to match the inputs SAR.

this is not happening and is causing ffmpeg to fail the conversion due to an invalid SAR

the inputs SAR here is 1:1 and I'm trying to force the output SAR to 1:1 also by setting this flag, but it isn't working.

2012-03-15T19:36:19 MCEBuddy.AppWrapper.FFmpeg --> Process arguments -threads 0 -async 1 -y -i "D:\Test Videos\MCEBuddyArchive\Test6.ts" -ss 3 -vf crop=1904:1072:6:6:1,scale=720:400,yadif=0:-1,hqdn3d -vcodec libxvid -b 1800000 -f avi -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -bf 2 -acodec copy -map 0:2 -map 0:1 "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working1\Test6.avi" -pass 1 -passlogfile "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working1\MCEBuddy2Pass.log"

--> ffmpeg version N-37915-g6cb2085 Copyright (c) 2000-2012 the FFmpeg developers
--> built on Feb 15 2012 20:47:20 with gcc 4.6.2
--> configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
--> libavutil 51. 39.100 / 51. 39.100
--> libavcodec 54. 3.100 / 54. 3.100
--> libavformat 54. 1.100 / 54. 1.100
--> libavdevice 53. 4.100 / 53. 4.100
--> libavfilter 2. 62.100 / 2. 62.100
--> libswscale 2. 1.100 / 2. 1.100
--> libswresample 0. 6.100 / 0. 6.100
--> libpostproc 52. 0.100 / 52. 0.100
--> [mpeg2video @ 02EA51A0] mpeg_decode_postinit() failure
--> Last message repeated 2 times
--> [mpegts @ 01CBD280] PES packet size mismatch
--> Last message repeated 1 times
--> Input #0, mpegts, from 'D:\Test Videos\MCEBuddyArchive\Test6.ts':
--> Duration: 00:29:51.92, start: 90226.333733, bitrate: 15080 kb/s
--> Video duration=1791.92
--> Program 1004
--> No Program
--> Stream #0:0[0x7c2]: Audio: ac3, 48000 Hz, stereo, s16, 96 kb/s (visual impaired)
--> Stream #0:1[0x7c0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 65000 kb/s, 30.38 fps, 29.97 tbr, 90k tbn, 59.94 tbc
--> Stream #0:2[0x7c1]: Audio: ac3, 48000 Hz, 5.1(side), s16, 384 kb/s
--> Please use -b:a or -b:v, -b is ambiguous
--> [buffer @ 0391AF20] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
--> [yadif @ 034E6740] mode:0 parity:-1 auto_enable:0
--> [hqdn3d @ 02EA6180] ls:4.000000 cs:3.000000 lt:6.000000 ct:4.500000
--> [crop @ 03395520] w:1920 h:1080 -> w:1904 h:1072
--> [scale @ 03395640] w:1904 h:1072 fmt:yuv420p -> w:720 h:400 fmt:yuv420p flags:0x4
--> Output #0, avi, to 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working1\Test6.avi':
--> Metadata:
--> ISFT : Lavf54.1.100
--> Stream #0:0: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 384 kb/s
--> Stream #0:1: Video: mpeg4 (hq) (xvid / 0x64697678), yuv420p, 720x400 [SAR 595:603 DAR 119:67], q=2-31, 1800 kb/s, 29.97 tbn, 29.97 tbc
--> Stream mapping:
--> Stream #0:2 -> #0:0 (copy)
--> Stream #0:1 -> #0:1 (mpeg2video -> libxvid)
--> Press [q] to stop, ? for help
--> frame= 0 fps= 0 q=0.0 size= 10kB time=00:00:00.00 bitrate= 0.0kbits/s
--> frame= 0 fps= 0 q=0.0 size= 10kB time=00:00:00.00 bitrate= 0.0kbits/s
--> Warning: data is not aligned! This can lead to a speedloss
--> [libxvid @ 034E6020] Invalid pixel aspect ratio 595/603
--> Video encoding failed

Change History (17)

comment:1 by ramitb, 13 years ago

I've also tried the -vf setdar=1:1 option and it has no effect on the output DAR either.
Question should the -vf be set before or after the -i <input>?

comment:2 by Carl Eugen Hoyos, 13 years ago

Resolution: invalid
Status: newclosed

Please always provide output for current git head, nearly 1000 changes have been made since the version you are using.

The documentation says

The keep_aspect parameter is optional, if specified and set to a non-zero value will force the output display aspect ratio to be the same of the input, by changing the output sample aspect ratio.

(which is quite the opposite of what you write above).

The scale filter (that you put after the crop filter) also changes the SAR, if you want a SAR of "1", add the setsar filter:
-vf crop=1904:1072:6:6:1,scale=720:400,setsar=1

For future reports: Please try to provide a minimal testcase, i.e. a command line that is as short as possible but allows to reproduce the problem. Add -an for video problems, -vn for audio problems:
In your case:
ffmpeg -i Test6.ts -an -vf crop=1904:1072:6:6:1,scale=720:400 -vcodec libxvid out.avi

Additionally, please try to avoid using third party libraries since this makes reproducing problems more difficult. Please note that some developers believe that the internal mpeg4 encoder can produce better output than libxvid and for your specific case, using the internal encoder at least does not fail encoding.

Finally, please use the button "Code block" for the command line and the complete, uncut console output to make the output more readable:

$ ffmpeg -i out.mpg -vf crop=1904:1072:6:6,scale=720:400,setsar=1 -f null -
ffmpeg version N-38811-ga04a97b Copyright (c) 2000-2012 the FFmpeg developers
  built on Mar 15 2012 14:40:16 with gcc 4.3.2
  configuration: --cc=/usr/local/gcc-4.3.2/bin/gcc --enable-gpl --enable-libspeex
  libavutil      51. 42.100 / 51. 42.100
  libavcodec     54. 10.100 / 54. 10.100
  libavformat    54.  2.100 / 54.  2.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 64.101 /  2. 64.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  7.100 /  0.  7.100
  libpostproc    52.  0.100 / 52.  0.100
[mpeg @ 0x8eb8aa0] Format mpeg detected only with low score of 25, misdetection possible!
[NULL @ 0x8ebee00] start time is not set in estimate_timings_from_pts
Input #0, mpeg, from 'out.mpg':
  Duration: N/A, bitrate: N/A
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 104857 kb/s, 25 tbr, 90k tbn, 50 tbc
[buffer @ 0x8ebf2a0] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[setsar @ 0x8ec08e0] a:1/1
[crop @ 0x8ec0920] w:1920 h:1080 -> w:1904 h:1072
[scale @ 0x8edd160] w:1904 h:1072 fmt:yuv420p -> w:720 h:400 fmt:yuv420p flags:0x4
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf54.2.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x400 [SAR 1:1 DAR 9:5], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video -> rawvideo)
Press [q] to stop, [?] for help
frame=   25 fps=0.0 q=0.0 Lsize=       0kB time=00:00:01.00 bitrate=   0.0kbits/s dup=24 drop=0
video:0kB audio:0kB global headers:0kB muxing overhead nan%
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

comment:3 by ramitb, 13 years ago

Thanks got it - will ensure the above guideslines are adhere to in future.

3 questions/points:

  1. I'm using the Feb 15th build (relatively recent) - is that still a problem
  2. I n eed to use lbxvid specifically since some users are reporting incompatability with the mpeg4 encoder despite the -tag etc etc and some divx devices
  3. Yes I misunderstood the keep_aspect ratio, it changes the SAR (and directly changesthe DAR). But if you notice in the output the SAR has not changed. I will try it with the latest git and see if it works. I'm only facing this problem with there is cropping taking place.
  4. I'll try the above with setdar also and see if that works.

EDIT:
If you notice above in your test, the output DAR is not matchiing the input DAR. Isnt that supposed to be case when the keep_aspect is set to non zero?

Last edited 13 years ago by ramitb (previous) (diff)

comment:4 by ramitb, 13 years ago

Okay this does not work at all and causes the conversion to fail. I'm using the latest version available for download.

COMMAND:

ffmpeg -i Test6.ts -an -vf crop=1904:1072:6:6:1,scale=720:400 -vcodec libxvid out.avi

OUTPUT:

ffmpeg version N-38622-g1eabd71 Copyright (c) 2000-2012 the FFmpeg developers
  built on Mar  7 2012 00:18:03 with gcc 4.6.2
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enab
le-bzlib --enable-frei0r --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --en
able-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --en
able-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-
libxvid --enable-zlib
  libavutil      51. 42.100 / 51. 42.100
  libavcodec     54. 10.100 / 54. 10.100
  libavformat    54.  2.100 / 54.  2.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 63.100 /  2. 63.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  7.100 /  0.  7.100
  libpostproc    52.  0.100 / 52.  0.100
[mpeg2video @ 02EA6AC0] mpeg_decode_postinit() failure
    Last message repeated 2 times
[mpegts @ 00329520] PES packet size mismatch
    Last message repeated 1 times
Input #0, mpegts, from 'Test6.ts':
  Duration: 00:29:51.92, start: 90226.333733, bitrate: 15080 kb/s
  Program 1004
  No Program
    Stream #0:0[0x7c2]: Audio: ac3, 48000 Hz, stereo, s16, 96 kb/s (visual impaired)
    Stream #0:1[0x7c0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 65000 kb/s, 30.38 fps, 29.97 tb
r, 90k tbn, 59.94 tbc
    Stream #0:2[0x7c1]: Audio: ac3, 48000 Hz, 5.1(side), s16, 384 kb/s
[buffer @ 0397DD40] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[crop @ 03975AE0] w:1920 h:1080 -> w:1904 h:1072
[scale @ 03975BE0] w:1904 h:1072 fmt:yuv420p -> w:720 h:400 fmt:yuv420p flags:0x4
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf54.2.100
    Stream #0:0: Video: mpeg4 (xvid / 0x64697678), yuv420p, 720x400 [SAR 595:603 DAR 119:67], q=2-31, 200 kb/s, 29.97 tb
n, 29.97 tbc
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg2video -> libxvid)
Press [q] to stop, [?] for help
[swscaler @ 03A97980] Warning: data is not aligned! This can lead to a speedloss
[libxvid @ 03975020] Invalid pixel aspect ratio 595/603
Video encoding failed

comment:5 by ramitb, 13 years ago

Something very funny I noticed when I execute the following command it FAILS

ffmpeg -y -i Test6.ts -an -vf setsar=1,crop=1904:1072:6:6:1,scale=720:400 -vcodec libxvid out.avi

ffmpeg version N-38622-g1eabd71 Copyright (c) 2000-2012 the FFmpeg developers
  built on Mar  7 2012 00:18:03 with gcc 4.6.2
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enab
le-bzlib --enable-frei0r --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --en
able-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --en
able-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-
libxvid --enable-zlib
  libavutil      51. 42.100 / 51. 42.100
  libavcodec     54. 10.100 / 54. 10.100
  libavformat    54.  2.100 / 54.  2.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 63.100 /  2. 63.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  7.100 /  0.  7.100
  libpostproc    52.  0.100 / 52.  0.100
[mpeg2video @ 02B46AC0] mpeg_decode_postinit() failure
    Last message repeated 2 times
[mpegts @ 00389580] PES packet size mismatch
    Last message repeated 1 times
Input #0, mpegts, from 'Test6.ts':
  Duration: 00:29:51.92, start: 90226.333733, bitrate: 15080 kb/s
  Program 1004
  No Program
    Stream #0:0[0x7c2]: Audio: ac3, 48000 Hz, stereo, s16, 96 kb/s (visual impaired)
    Stream #0:1[0x7c0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 65000 kb/s, 30.38 fps, 29.97 tb
r, 90k tbn, 59.94 tbc
    Stream #0:2[0x7c1]: Audio: ac3, 48000 Hz, 5.1(side), s16, 384 kb/s
[buffer @ 03A5DCE0] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[setsar @ 02B47BE0] a:1/1
[crop @ 02B47E40] w:1920 h:1080 -> w:1904 h:1072
[scale @ 03967820] w:1904 h:1072 fmt:yuv420p -> w:720 h:400 fmt:yuv420p flags:0x4
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf54.2.100
    Stream #0:0: Video: mpeg4 (xvid / 0x64697678), yuv420p, 720x400 [SAR 595:603 DAR 119:67], q=2-31, 200 kb/s, 29.97 tb
n, 29.97 tbc
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg2video -> libxvid)
Press [q] to stop, [?] for help
[swscaler @ 0359E020] Warning: data is not aligned! This can lead to a speedloss
[libxvid @ 02B45FA0] Invalid pixel aspect ratio 595/603
Video encoding failed

But when I execute this command, it WORKS

ffmpeg -y -i Test6.ts -an -vf crop=1904:1072:6:6:1,scale=720:400,setsar=1 -vcodec libxvid out.avi

ffmpeg version N-38622-g1eabd71 Copyright (c) 2000-2012 the FFmpeg developers
  built on Mar  7 2012 00:18:03 with gcc 4.6.2
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enab
le-bzlib --enable-frei0r --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --en
able-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --en
able-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-
libxvid --enable-zlib
  libavutil      51. 42.100 / 51. 42.100
  libavcodec     54. 10.100 / 54. 10.100
  libavformat    54.  2.100 / 54.  2.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 63.100 /  2. 63.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  7.100 /  0.  7.100
  libpostproc    52.  0.100 / 52.  0.100
[mpeg2video @ 02A66AC0] mpeg_decode_postinit() failure
    Last message repeated 2 times
[mpegts @ 01D59580] PES packet size mismatch
    Last message repeated 1 times
Input #0, mpegts, from 'Test6.ts':
  Duration: 00:29:51.92, start: 90226.333733, bitrate: 15080 kb/s
  Program 1004
  No Program
    Stream #0:0[0x7c2]: Audio: ac3, 48000 Hz, stereo, s16, 96 kb/s (visual impaired)
    Stream #0:1[0x7c0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 65000 kb/s, 30.38 fps, 29.97 tb
r, 90k tbn, 59.94 tbc
    Stream #0:2[0x7c1]: Audio: ac3, 48000 Hz, 5.1(side), s16, 384 kb/s
[buffer @ 039DDCE0] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[setsar @ 02A67DC0] a:1/1
[crop @ 02A67BE0] w:1920 h:1080 -> w:1904 h:1072
[scale @ 02A67E20] w:1904 h:1072 fmt:yuv420p -> w:720 h:400 fmt:yuv420p flags:0x4
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf54.2.100
    Stream #0:0: Video: mpeg4 (xvid / 0x64697678), yuv420p, 720x400 [SAR 1:1 DAR 9:5], q=2-31, 200 kb/s, 29.97 tbn, 29.9
7 tbc
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg2video -> libxvid)
Press [q] to stop, [?] for help
[swscaler @ 0348E020] Warning: data is not aligned! This can lead to a speedloss
frame=   17 fps= 16 q=19.0 size=      51kB time=00:00:00.93 bitrate= 450.5kbits/s

Does the location of setsar matter?

Last edited 13 years ago by ramitb (previous) (diff)

in reply to:  3 comment:6 by Carl Eugen Hoyos, 13 years ago

Replying to ramitbhalla:

  1. I need to use lbxvid specifically since some users are reporting incompatibility with the mpeg4 encoder despite the -tag etc etc and some divx devices

Which ticket corresponds to this problem?

comment:7 by ramitb, 13 years ago

I haven't raised any ticket for the incompatability. Will request the users for a sample video file, details of the devices being used and will create a new ticket for it.

For now I'm trying to work around with getting libxvid working.

FYI - I did a quick "quality" test with a sample video with the settings given in this ticket.
For the same settings, the output file size was roughly the same, the time taken by libxvid was 8 times the time taken by mpeg4 but there was a very noticable difference in the quality. with mpeg4 there were many more artifacts/blurring than with the libxvid codec for the same parameters (i just replaced libxvid with mpeg4 -vtag xvid).

comment:8 by ramitb, 13 years ago

According to the documentation:

Also the display aspect ratio set by this filter may be changed by later filters in the filterchain, e.g. in case of scaling or if another "setdar" or a "setsar" filter is applied.


this implies that setsar can be placed anywhere in the chain. Above if I place it anywhere except the end it fails the conversion. Maybe it's a bug that needs to be fixed.

in reply to:  8 comment:9 by Stefano Sabatini, 13 years ago

Replying to ramitbhalla:

According to the documentation:

Also the display aspect ratio set by this filter may be changed by later filters in the filterchain, e.g. in case of scaling or if another "setdar" or a "setsar" filter is applied.


this implies that setsar can be placed anywhere in the chain. Above if I place it anywhere except the end it fails the conversion. Maybe it's a bug that needs to be fixed.

Your interpretation of the documentation is backward. This means that if you place setsar anywhere *but* at the end the SAR may be changed (as it happens in your case, since the scale filter forces the output display aspect ratio to be the same as in input, by changing the output SAR).

comment:10 by ramitb, 13 years ago

Okay in that I think ffmpeg has a bug. If you look at hte output above:

  1. If setsar is put anywhere BUT the end it fails to change the sar (notice the invalid PAR and SAR value does not match the input SAR despite the setsar and scale)
  1. If the setsar is put AT the end it succeeds. The SAR is changed to match the input SAR and the video conversion succeeds.
  1. If I omit setsar and leave scale it still fails to change the SAR and the conversion fails.

Either the documentation needs to be updated or there is a bug in there. Did I read that right?

comment:11 by ramitb, 13 years ago

Didn't hear back, so is there a bug or is the documentation wrong?

in reply to:  10 comment:12 by Carl Eugen Hoyos, 13 years ago

Replying to ramitbhalla:

  1. If setsar is put anywhere BUT the end it fails to change the sar

This sounds unlikely, did you test?

comment:13 by ramitb, 13 years ago

Yes please see the output above.
I also tried putting in just before scale (after crop), in the beginning and in the end.

It only works when it's at the end.

in reply to:  10 comment:14 by Carl Eugen Hoyos, 13 years ago

Replying to ramitbhalla:

  1. If setsar is put anywhere BUT the end it fails to change the sar

I tried the following two lines, the output looks very different, I therefore assume the setsar filter also works if it is not put at the end of the filter list:

$ ./ffmpeg -i tests/lena.pnm -vf setsar=1,crop=128 out1.avi
$ ./ffmpeg -i tests/lena.pnm -vf setsar=2,crop=128 out2.avi

comment:15 by ramitb, 13 years ago

Do you think it might have anything to do with the video file? the file I'm using fails under normal conditions (invalid SAR) - could that have a play in it?
I'm putting setsar specifically to fix that problem

After all the output I've copy/pasted above shows that it isn't working under the conditions I have.

in reply to:  15 comment:16 by Carl Eugen Hoyos, 13 years ago

Replying to ramitbhalla:

Do you think it might have anything to do with the video file? the file I'm using fails under normal conditions (invalid SAR) - could that have a play in it?
I'm putting setsar specifically to fix that problem

After all the output I've copy/pasted above shows that it isn't working under the conditions I have.

I had the impression that your second example in comment #5 works fine, did I misunderstand?

comment:17 by ramitb, 13 years ago

Yes that's correct the comment #5 works but if you noticed the setsar is at the end there.

Note: See TracTickets for help on using tickets.