[FFmpeg-user] Transcoding foscam mkv to mp4 is resulting in larger files

Steve Boyer steveboyer85 at gmail.com
Sun Sep 13 06:37:13 CEST 2015


On Sat, Sep 12, 2015 at 11:27 PM, Steve Boyer <steveboyer85 at gmail.com>
wrote:

>
>
> On Sat, Sep 12, 2015 at 11:24 PM, Steve Boyer <steveboyer85 at gmail.com>
> wrote:
>
>>
>>
>> On Sat, Sep 12, 2015 at 11:03 PM, Kai Hendry <kai.hendry at gmail.com>
>> wrote:
>>
>>> Hi guys,
>>
>>
>>
>>>
>>
>> The Input #0, mpeg transcoding into mp4 (for iPhone playback via
>>> Safari) is resulting in up 3x larger files. Why is that?
>>>
>>> ffprobe of a typical MKV input file:
>>> http://ix.io/kLm
>>>
>>> The ffmpeg log:
>>> http://ix.io/kMw
>>>
>>> Sidenote: Found I had to put in a frame rate of 30 else things
>>> wouldn't work. Really not sure why. Maybe someone can explain?
>>>
>>> Example of the input:
>>> http://s.natalian.org/2015-09-13/MDalarm_20150911_121823.mkv
>>>
>>>
>> First off, the command you used, from start to finish would be helpful,
>> but seeing as this looks like a pretty easy one...
>>
>
> My apologies: just saw your command line in one of your files:
> " Command line:
> ffmpeg -y -i
> /srv/ftp/888/C1_00626E587B70/record/MDalarm_20150913_115258.mkv -r 30
> -movflags +faststart -pix_fmt yuv420p -c:v libx264 -vprofile baseline
> -acodec aac -strict experimental
> /srv/www/nuc.local/2015-09-13/MDalarm_20150913_115258.mp4"
>
>
After some experimenting, leaving out the pix_fmt option, leaving out the
profile, disabling the audio entirely and therefore have no need for strict
experimental, I found a CRF of 24 and preset of veryfast seem to produce
close filesizes. IF you really need to transcode it (a lossy and much more
CPU intensive conversion), take a look at:

steve at steve-laptop:~/Downloads$ ffmpeg -y -i MDalarm_20150911_121823.mkv -r
30 -movflags +faststart -c:v libx264 -an -preset veryfast -crf 24
MDalarm.mp4
ffmpeg version 2.4.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Nov 16 2014 15:41:37 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/home/steve/ffmpeg_build
--extra-cflags=-I/home/steve/ffmpeg_build/include
--extra-ldflags=-L/home/steve/ffmpeg_build/lib --bindir=/home/steve/bin
--enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype
--enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
  libavutil      54. 13.100 / 54. 13.100
  libavcodec     56. 12.101 / 56. 12.101
  libavformat    56. 13.100 / 56. 13.100
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpeg, from 'MDalarm_20150911_121823.mkv':
  Duration: 00:00:33.73, start: 48716.884478, bitrate: 266 kb/s
    Stream #0:0[0x1e0]: Video: h264 (Baseline), yuv420p, 1280x720, 90k tbr,
90k tbn
[libx264 @ 0x39b3720] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x39b3720] profile High, level 3.1
[libx264 @ 0x39b3720] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec
- Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1
ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00
mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11
fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=4
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=1 keyint=250 keyint_min=25 scenecut=40
intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=24.0 qcomp=0.60 qpmin=0
qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'MDalarm.mp4':
  Metadata:
    encoder         : Lavf56.13.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p,
1280x720, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.12.101 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  178 fps=0.0 q=30.0 size=     333kB time=00:00:05.00 bitrate=
545.0kbits/frame=  367 fps=366 q=30.0 size=     517kB time=00:00:11.30
bitrate= 375.0kbits/frame=  566 fps=372 q=30.0 size=     694kB
time=00:00:17.93 bitrate= 317.0kbits/frame=  773 fps=383 q=30.0 size=
791kB time=00:00:24.83 bitrate= 261.0kbits/frame=  969 fps=384 q=30.0 size=
    944kB time=00:00:31.36 bitrate= 246.6kbits/[mp4 @ 0x39b2660] Starting
second pass: moving the moov atom to the beginning of the file
frame= 1013 fps=378 q=-1.0 Lsize=    1048kB time=00:00:33.70 bitrate=
254.8kbits/s dup=235 drop=0
video:1036kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 1.219653%
[libx264 @ 0x39b3720] frame I:5     Avg QP:19.37  size: 60224
[libx264 @ 0x39b3720] frame P:268   Avg QP:23.39  size:  2338
[libx264 @ 0x39b3720] frame B:740   Avg QP:23.85  size:   179
[libx264 @ 0x39b3720] consecutive B-frames:  2.6%  0.0%  0.3% 97.1%
[libx264 @ 0x39b3720] mb I  I16..4: 20.1% 26.5% 53.4%
[libx264 @ 0x39b3720] mb P  I16..4:  1.2%  0.6%  0.1%  P16..4:  8.3%  2.1%
 0.7%  0.0%  0.0%    skip:87.1%
[libx264 @ 0x39b3720] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.7%  0.2%
 0.0%  direct: 0.6%  skip:98.5%  L0:52.3% L1:41.5% BI: 6.2%
[libx264 @ 0x39b3720] 8x8 transform intra:28.7% inter:14.5%
[libx264 @ 0x39b3720] coded y,uvDC,uvAC intra: 44.8% 40.1% 10.6% inter:
0.8% 1.6% 0.0%
[libx264 @ 0x39b3720] i16 v,h,dc,p: 56% 20% 16%  8%
[libx264 @ 0x39b3720] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 31% 19%  2%  2%
 2%  3%  2%  3%
[libx264 @ 0x39b3720] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41% 25%  9%  3%  3%
 5%  5%  4%  6%
[libx264 @ 0x39b3720] i8c dc,h,v,p: 43% 21% 29%  7%
[libx264 @ 0x39b3720] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x39b3720] kb/s:251.08
steve at steve-laptop:~/Downloads$ ls -l MDalarm*
-rw-r----- 1 steve steve 1122988 Sep 12 23:07 MDalarm_20150911_121823.mkv
-rw-rw-r-- 1 steve steve 1073400 Sep 12 23:34 MDalarm.mp4
steve at steve-laptop:~/Downloads$



>> I downloaded your sample file above, and did:
>>
>> steve at steve-laptop:~/Downloads$ ffmpeg -i MDalarm_20150911_121823.mkv
>> -c:a copy -c:v copy MDalarm.mp4
>> ffmpeg version 2.4.git Copyright (c) 2000-2014 the FFmpeg developers
>>   built on Nov 16 2014 15:41:37 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
>>   configuration: --prefix=/home/steve/ffmpeg_build
>> --extra-cflags=-I/home/steve/ffmpeg_build/include
>> --extra-ldflags=-L/home/steve/ffmpeg_build/lib --bindir=/home/steve/bin
>> --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype
>> --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis
>> --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
>>   libavutil      54. 13.100 / 54. 13.100
>>   libavcodec     56. 12.101 / 56. 12.101
>>   libavformat    56. 13.100 / 56. 13.100
>>   libavdevice    56.  3.100 / 56.  3.100
>>   libavfilter     5.  2.103 /  5.  2.103
>>   libswscale      3.  1.101 /  3.  1.101
>>   libswresample   1.  1.100 /  1.  1.100
>>   libpostproc    53.  3.100 / 53.  3.100
>> Input #0, mpeg, from 'MDalarm_20150911_121823.mkv':
>>   Duration: 00:00:33.73, start: 48716.884478, bitrate: 266 kb/s
>>     Stream #0:0[0x1e0]: Video: h264 (Baseline), yuv420p, 1280x720, 90k
>> tbr, 90k tbn
>> Output #0, mp4, to 'MDalarm.mp4':
>>   Metadata:
>>     encoder         : Lavf56.13.100
>>     Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720,
>> q=2-31, 90k tbn, 90k tbc
>> Stream mapping:
>>   Stream #0:0 -> #0:0 (copy)
>> Press [q] to stop, [?] for help
>> frame=  778 fps=0.0 q=-1.0 Lsize=    1081kB time=00:00:33.68 bitrate=
>> 262.8kbits/s
>> video:1071kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
>> muxing overhead: 0.909946%
>> steve at steve-laptop:~/Downloads$
>>
>> ls -l returns...
>> -rw-r----- 1 steve steve 1122988 Sep 12 23:07 MDalarm_20150911_121823.mkv
>> -rw-rw-r-- 1 steve steve 1106527 Sep 12 23:09 MDalarm.mp4
>>
>> I left out the part about "-c:a copy -c:v copy" to copy the streams and
>> it yelled at me about framerate (tries to output a funky framerate) and
>> also about the filesize was crazy.
>>
>> Put the "-c:a copy -c:v copy" to copy the streams and not transcode and
>> it worked fast (778 fps) and plays fine with ffplay and VLC. MPlayer plays
>> it at an insane FPS. Stats on the resulting file:
>>
>> steve at steve-laptop:~/Downloads$ ffprobe MDalarm.mp4
>> ffprobe version 2.4.git Copyright (c) 2007-2014 the FFmpeg developers
>>   built on Nov 16 2014 15:41:37 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
>>   configuration: --prefix=/home/steve/ffmpeg_build
>> --extra-cflags=-I/home/steve/ffmpeg_build/include
>> --extra-ldflags=-L/home/steve/ffmpeg_build/lib --bindir=/home/steve/bin
>> --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype
>> --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis
>> --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
>>   libavutil      54. 13.100 / 54. 13.100
>>   libavcodec     56. 12.101 / 56. 12.101
>>   libavformat    56. 13.100 / 56. 13.100
>>   libavdevice    56.  3.100 / 56.  3.100
>>   libavfilter     5.  2.103 /  5.  2.103
>>   libswscale      3.  1.101 /  3.  1.101
>>   libswresample   1.  1.100 /  1.  1.100
>>   libpostproc    53.  3.100 / 53.  3.100
>> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'MDalarm.mp4':
>>   Metadata:
>>     major_brand     : isom
>>     minor_version   : 512
>>     compatible_brands: isomiso2avc1mp41
>>     encoder         : Lavf56.13.100
>>   Duration: 00:00:33.73, start: 0.000000, bitrate: 262 kb/s
>>     Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661),
>> yuv420p, 1280x720, 260 kb/s, 23.06 fps, 25 tbr, 90k tbn, 180k tbc (default)
>>     Metadata:
>>       handler_name    : VideoHandler
>> steve at steve-laptop:~/Downloads$
>>
>> My version of FFmpeg (which I admit is a little older than newest
>> development) puts it in a 24000/1001 framerate H264 video stream and copies
>> it nicely into an MP4 file. iOS devices shouldn't have any problem playing
>> a 720P .MP4.
>>
>> TL;DR: use -c:a copy and -c:v copy options and give that a shot.
>>
>>
>>> Many thanks,
>>>
>>> p.s. code for the project will eventually land up in
>>> https://github.com/kaihendry/camftp2web
>>> _______________________________________________
>>> ffmpeg-user mailing list
>>> ffmpeg-user at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>>
>>
>>
>


More information about the ffmpeg-user mailing list