#3399 closed defect (duplicate)
Bad output framerate decision for mp4 from camera
| Reported by: | Michael Ressler | Owned by: | |
|---|---|---|---|
| Priority: | normal | Component: | avformat |
| Version: | git-master | Keywords: | fps mov |
| Cc: | Blocked By: | ||
| Blocking: | Reproduced by developer: | yes | |
| Analyzed by developer: | no |
Description
Summary of the bug:
Attempting to scale an MP4/H264 1920x1080 source video to 1024:-1 (also Mp4/H264) results in odd playback in different players. VLC shows green box artifacts, QuickTime and MPlayer both show jerky/slow playback.
How to reproduce:
(Grab source from: https://www.dropbox.com/s/thy8zxbvx1ygqru/VID_20130619_161750_449.mp4)
% ffmpeg -i VID_20130619_161750_449.mp4 -vf "scale=1024:-1" VID_scaled.mp4
VID_scaled.mp4 ends up with green artifacts in VLC and doesn't play appropriately in QuickTime or MPlayer.
Interestingly, if I clip the video first via:
% ffmpeg -i VID_20130619_161750_449.mp4 -ss 18 -t 15 -c:v copy -c:a copy clip2.mp4
And then run the scale command:
% ffmpeg -i clip2.mp4 -vf "scale=1024:-1" VID_clip_scaled.mp4
The resulting video plays fine in VLC, QuickTime, and MPlayer.
Change History (13)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
(I don't see a way to edit the description above, so here's a new description with full output.)
Summary of the bug:
Attempting to scale an MP4/H264 1920x1080 source video to 1024:-1 (also Mp4/H264) results in odd playback in different players. VLC shows green box artifacts, QuickTime? and MPlayer both show jerky/slow playback.
How to reproduce:
(Grab source from: https://www.dropbox.com/s/thy8zxbvx1ygqru/VID_20130619_161750_449.mp4)
% ffmpeg -i VID_20130619_161750_449.mp4 -vf "scale=1024:-1" VID_scaled.mp4
ffmpeg version 2.1.3 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 17 2014 12:57:49 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.1.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 48.101 / 52. 48.101
libavcodec 55. 39.101 / 55. 39.101
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libavresample 1. 1. 0 / 1. 1. 0
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID_20130619_161750_449.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2013-06-19 20:18:49
Duration: 00:00:58.05, start: 0.000000, bitrate: 15706 kb/s
Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : SoundHandle
Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 15469 kb/s, SAR 65536:65536 DAR 16:9, 29.89 fps, 1k tbr, 1k tbn, 2k tbc (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : VideoHandle
File 'VID_scaled.mp4' already exists. Overwrite ? [y/N] y
[libx264 @ 0x7fc0f2863c00] using SAR=1/1
[libx264 @ 0x7fc0f2863c00] MB rate (2304000) > level limit (2073600)
[libx264 @ 0x7fc0f2863c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0x7fc0f2863c00] profile High, level 5.2
[libx264 @ 0x7fc0f2863c00] 264 - core 125 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'VID_scaled.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
encoder : Lavf55.19.104
Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1024x576 [SAR 1:1 DAR 16:9], q=-1--1, 16k tbn, 1k tbc (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : SoundHandle
Stream mapping:
Stream #0:1 -> #0:0 (h264 -> libx264)
Stream #0:0 -> #0:1 (aac -> libfaac)
Press [q] to stop, [?] for help
frame=58016 fps=149 q=-1.0 Lsize= 47319kB time=00:00:58.01 bitrate=6681.8kbits/s dup=56281 drop=0
video:45706kB audio:890kB subtitle:0 global headers:0kB muxing overhead 1.551760%
[libx264 @ 0x7fc0f2863c00] frame I:241 Avg QP:19.11 size: 59516
[libx264 @ 0x7fc0f2863c00] frame P:15706 Avg QP:21.99 size: 1876
[libx264 @ 0x7fc0f2863c00] frame B:42069 Avg QP:32.95 size: 71
[libx264 @ 0x7fc0f2863c00] consecutive B-frames: 3.2% 0.2% 0.5% 96.1%
[libx264 @ 0x7fc0f2863c00] mb I I16..4: 5.1% 69.1% 25.8%
[libx264 @ 0x7fc0f2863c00] mb P I16..4: 0.0% 0.2% 0.1% P16..4: 7.9% 2.8% 2.1% 0.0% 0.0% skip:86.9%
[libx264 @ 0x7fc0f2863c00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 3.3% 0.0% 0.0% direct: 0.0% skip:96.7% L0:26.8% L1:73.2% BI: 0.0%
[libx264 @ 0x7fc0f2863c00] 8x8 transform intra:69.6% inter:59.9%
[libx264 @ 0x7fc0f2863c00] coded y,uvDC,uvAC intra: 92.9% 68.7% 35.0% inter: 1.4% 1.0% 0.0%
[libx264 @ 0x7fc0f2863c00] i16 v,h,dc,p: 14% 11% 5% 70%
[libx264 @ 0x7fc0f2863c00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 16% 22% 5% 8% 9% 8% 6% 8%
[libx264 @ 0x7fc0f2863c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 15% 10% 6% 10% 11% 8% 6% 7%
[libx264 @ 0x7fc0f2863c00] i8c dc,h,v,p: 51% 19% 23% 7%
[libx264 @ 0x7fc0f2863c00] Weighted P-Frames: Y:0.4% UV:0.0%
[libx264 @ 0x7fc0f2863c00] ref P L0: 81.7% 12.1% 5.9% 0.4% 0.0%
[libx264 @ 0x7fc0f2863c00] ref B L0: 95.8% 4.2% 0.0%
[libx264 @ 0x7fc0f2863c00] ref B L1: 85.4% 14.6%
[libx264 @ 0x7fc0f2863c00] kb/s:6453.67
VID_scaled.mp4 ends up with green artifacts in VLC and doesn't play appropriately in QuickTime? or MPlayer.
Interestingly, if I clip the video first via:
% ffmpeg -i VID_20130619_161750_449.mp4 -ss 18 -t 15 -c:v copy -c:a copy clip2.mp4
ffmpeg version 2.1.3 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 17 2014 12:57:49 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.1.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 48.101 / 52. 48.101
libavcodec 55. 39.101 / 55. 39.101
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libavresample 1. 1. 0 / 1. 1. 0
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID_20130619_161750_449.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2013-06-19 20:18:49
Duration: 00:00:58.05, start: 0.000000, bitrate: 15706 kb/s
Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : SoundHandle
Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 15469 kb/s, SAR 65536:65536 DAR 16:9, 29.89 fps, 1k tbr, 1k tbn, 2k tbc (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : VideoHandle
File 'clip2.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 'clip2.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
encoder : Lavf55.19.104
Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 65536:65536 DAR 16:9], q=2-31, 15469 kb/s, 29.89 fps, 16k tbn, 1k tbc (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 128 kb/s (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : SoundHandle
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 444 fps=0.0 q=-1.0 Lsize= 28323kB time=00:00:15.00 bitrate=15462.3kbits/s
video:28072kB audio:234kB subtitle:0 global headers:0kB muxing overhead 0.057352%
And then run the scale command:
% ffmpeg -i clip2.mp4 -vf "scale=1024:-1" VID_clip_scaled.mp4
ffmpeg version 2.1.3 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 17 2014 12:57:49 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.1.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 48.101 / 52. 48.101
libavcodec 55. 39.101 / 55. 39.101
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libavresample 1. 1. 0 / 1. 1. 0
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.19.104
Duration: 00:00:15.00, start: 0.005011, bitrate: 15466 kb/s
Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 15542 kb/s, 30.01 fps, 30 tbr, 16k tbn, 32k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandler
[libx264 @ 0x7ff8c48f1200] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0x7ff8c48f1200] profile High, level 3.1
[libx264 @ 0x7ff8c48f1200] 264 - core 125 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'VID_clip_scaled.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.19.104
Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1024x576, q=-1--1, 15360 tbn, 30 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> libfaac)
Press [q] to stop, [?] for help
frame= 451 fps= 56 q=-1.0 Lsize= 2622kB time=00:00:15.00 bitrate=1432.0kbits/s dup=7 drop=0
video:2370kB audio:235kB subtitle:0 global headers:0kB muxing overhead 0.674256%
[libx264 @ 0x7ff8c48f1200] frame I:2 Avg QP:21.56 size: 57176
[libx264 @ 0x7ff8c48f1200] frame P:168 Avg QP:24.62 size: 10380
[libx264 @ 0x7ff8c48f1200] frame B:281 Avg QP:27.22 size: 2020
[libx264 @ 0x7ff8c48f1200] consecutive B-frames: 0.4% 27.1% 67.2% 5.3%
[libx264 @ 0x7ff8c48f1200] mb I I16..4: 6.5% 64.9% 28.6%
[libx264 @ 0x7ff8c48f1200] mb P I16..4: 0.2% 1.5% 0.5% P16..4: 44.3% 13.9% 9.8% 0.0% 0.0% skip:29.9%
[libx264 @ 0x7ff8c48f1200] mb B I16..4: 0.0% 0.1% 0.0% B16..8: 49.8% 2.1% 0.3% direct: 0.4% skip:47.3% L0:39.9% L1:57.4% BI: 2.6%
[libx264 @ 0x7ff8c48f1200] 8x8 transform intra:66.9% inter:72.6%
[libx264 @ 0x7ff8c48f1200] coded y,uvDC,uvAC intra: 79.3% 58.4% 20.6% inter: 12.6% 5.9% 0.2%
[libx264 @ 0x7ff8c48f1200] i16 v,h,dc,p: 22% 25% 5% 48%
[libx264 @ 0x7ff8c48f1200] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 13% 20% 5% 12% 12% 11% 6% 8%
[libx264 @ 0x7ff8c48f1200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 13% 14% 5% 12% 13% 9% 6% 5%
[libx264 @ 0x7ff8c48f1200] i8c dc,h,v,p: 55% 19% 18% 8%
[libx264 @ 0x7ff8c48f1200] Weighted P-Frames: Y:5.4% UV:0.0%
[libx264 @ 0x7ff8c48f1200] ref P L0: 60.9% 17.9% 15.4% 5.7% 0.1%
[libx264 @ 0x7ff8c48f1200] ref B L0: 81.3% 16.3% 2.5%
[libx264 @ 0x7ff8c48f1200] ref B L1: 88.1% 11.9%
[libx264 @ 0x7ff8c48f1200] kb/s:1290.94
The resulting video plays fine in VLC, QuickTime?, and MPlayer.
comment:3 by , 12 years ago
Is the problem also reproducible without using an external library (using -vcodec mpeg4)?
And please test current FFmpeg git head.
comment:4 by , 12 years ago
| Reproduced by developer: | set |
|---|---|
| Status: | new → open |
| Summary: | Scaling MP4 Video results in bad output MP4 → Bad output framerate decision for mp4 from camera |
| Version: | 2.1.3 → git-master |
Unrelated to scaling, work-around is to use -r 30000/1001
$ ffmpeg -i VID_20130619_161750_449.mp4 -qscale 2 -strict -2 -vcodec mpeg4 out.mov
ffmpeg version N-60713-g1355caf Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 18 2014 16:50:43 with gcc 4.7 (SUSE Linux)
configuration: --enable-gpl --enable-gray
libavutil 52. 64.100 / 52. 64.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.102 / 4. 1.102
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID_20130619_161750_449.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2013-06-19 20:18:49
Duration: 00:00:58.05, start: 0.000000, bitrate: 15706 kb/s
Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : SoundHandle
Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 15469 kb/s, SAR 65536:65536 DAR 16:9, 29.89 fps, 1k tbr, 1k tbn, 2k tbc (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : VideoHandle
Please use -q:a or -q:v, -qscale is ambiguous
Output #0, mov, to 'out.mov':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
encoder : Lavf55.33.100
Stream #0:0(eng): Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 16k tbn, 1k tbc (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2013-06-19 20:18:49
handler_name : SoundHandle
Stream mapping:
Stream #0:1 -> #0:0 (h264 -> mpeg4)
Stream #0:0 -> #0:1 (aac -> aac)
Press [q] to stop, [?] for help
frame=58016 fps=330 q=2.0 Lsize= 1132027kB time=00:00:58.01 bitrate=159845.0kbits/s dup=56281 drop=0
video:1130841kB audio:894kB subtitle:0 data:0 global headers:0kB muxing overhead 0.025849%
comment:5 by , 12 years ago
| Keywords: | fps mov added |
|---|---|
| Resolution: | → duplicate |
| Status: | open → closed |
Looks like a duplicate of ticket #2958
follow-up: 7 comment:6 by , 12 years ago
So -r will force the framerate, but how did you know to use those values? What about the source video caused the bad decision to be made by ffmpeg? I ask so that I can detect this automatically for my users in the future.
Is it a good idea to always manually force the framerate?
The sample command you ran didn't include the -r option?
comment:7 by , 12 years ago
Replying to mressler:
The sample command you ran didn't include the -r option?
I did not want to post a working command line but an as-simple-as-possible command line that allows to reproduce the problem (and avoids using an external library). Note that I missed the issue originally because of the noisy x264 output.
The FFmpeg mov muxer only supports cfr, if your input file is vfr, frames are dropped and / or duplicated to produce cfr output. Knowing the correct frame-rate is not always easy.
follow-up: 10 comment:8 by , 12 years ago
Ah, gotcha. Thanks for the help. What's the easiest way to tell if the source video is VFR? What method did you use to determine the correct frame-rate? Any pointers here are much appreciated.
comment:10 by , 12 years ago
Replying to mressler:
What's the easiest way to tell if the source video is VFR?
I looked at FFmpeg's console output and saw that many frames were duplicated.
(Some formats are by definition vfr, other by definition cfr, but this is not what this ticket is about.)
What method did you use to determine the correct frame-rate?
I looked at FFmpeg's output and saw an actual average framerate.
comment:11 by , 12 years ago
| Component: | undetermined → avformat |
|---|
comment:12 by , 19 months ago
Can somebody explain why avg_frame_rate isn't to be always preferred to r_frame_rate?
comment:13 by , 19 months ago
There can be occasions when motion fluidity would be lost. Consider a VFR video which is mostly slideshow with one or two short live-action footage in between. The avg fps would be very low, and if used, would make the footage look like a timelapse.



To make this a valid ticket please include the complete console output for each command. Otherwise we can only make guesses.