0

I tried converting a video file to a desired format using FFmpeg through WinFF. I have specific demands about some aspects of the output file, while other aspects should be set in a way which will give the best quality on the output. To clarify - I want my output file to be:

  • 1600×900
  • in mkv container
  • using H.264 video decoder
  • using aac audio decoder
  • 16:9 ratio (obviously...)
  • same audio volume as input
  • 60 fps
  • with nothing cropped out or image losing its original proportion.

Not necessarily

  • using all 48 audio channels.

Any other aspect of the file that won't affect those listed above should give the best possible quality. Well, not literally. I don't want a file that would take half of my hard disk, or that would take a week to convert.

Anyway, this was some background of what I'm currently up to. I tried to figure everything out myself, but what I did gave me an empty .mkv file along with a log and a 234,5 mb .log.[something] file. More than that - conversion took too long. I was converting a 10 minute long Big Buck Bunny, and it took something between 1-2h (probably). I'm going to convert some 2h long files, so yeah, one day per file would be too much...

Here goes parameters I used.

1st Pass:

avconv -threads 8  -i bbb_sunflower_native_60fps_normal.mp4 \
-acodec aac -vcodec h264 -b:v 50000k  -r:v 60  -filter:v yadif,scale=1600:900 \
-aspect 16:9 -b:a 320k  -r:a 96000  -ac 48 -vol 256  -f null -an \
-passlogfile "/home/wnerw/Wideo/bbb_sunflower_native_60fps_normal.log" \
-pass 1  -y /dev/null

2nd Pass

avconv -threads 8  -y -i bbb_sunflower_native_60fps_normal.mp4 -acodec aac \
-vcodec h264 -b:v 50000k  -r:v 60  -filter:v yadif,scale=1600:900 -aspect 16:9 \
-b:a 320k  -r:a 96000  -ac 48 -vol 256 \
-passlogfile "/home/wnerw/Wideo/bbb_sunflower_native_60fps_normal.log" -pass 2 \
"/home/wnerw/Wideo/bbb_sunflower_native_60fps_normal.mkv"

I know, values like 50000k and 96000 seem crazy, but I just wanted to try that out.

At last what I'm looking for!

  1. What have I done wrong the first time?
  2. What parameters will give me desired output?

If someone would be super nice I will really appreciate two sets of parameters - one for a best-but-not-crazy output, and one for best possible I could really get. I know that the latter may burn my CPU, take a year to process or be 10× bigger than my whole disk. It's just for my curiosity.

EDIT Here goes terminal output from 1st Pass. Actually now I remembered that 2nd Pass didn't happen. I can't retrieve what was in terminal were things crashed when going for second pass. I just pressed enter and whole terminal disappeared. I can't wait for 1st pass to complete right now, it takes too much time.

Terminal output:

avconv version 9.16-6:9.16-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers
built on Aug 10 2014 18:16:02 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
/home/wnerw/Pobrane/bbb_sunflower_native_60fps_normal.mp4':
Metadata:
major_brand     : isom
minor_version   : 1
compatible_brands: isomavc1
creation_time   : 2013-12-24 11:10:47
title           : Big Buck Bunny, Sunflower version
artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
genre           : Animation
composer        : Sacha Goedegebure
Duration: 00:10:34.56, start: 0.000000, bitrate: 10487 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 4000x2250 [PAR 1:1 DAR 16:9], 10002 kb/s,
60 fps, 60 tbr, 60k tbn, 120 tbc
Metadata:
  creation_time   : 2013-12-24 11:10:47
Stream #0.1(und): Audio: mp3, 48000 Hz, stereo, s16p, 160 kb/s
Metadata:
  creation_time   : 2013-12-24 11:10:49
Stream #0.2(und): Audio: ac3, 48000 Hz, 5.1, fltp, 320 kb/s
Metadata:
  creation_time   : 2013-12-24 11:10:49
[libx264 @ 0x16a36e0] using SAR=1/1
[libx264 @ 0x16a36e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x16a36e0] profile Main, level 5.0
Output #0, null, to '/dev/null':
Metadata:
major_brand     : isom
minor_version   : 1
compatible_brands: isomavc1
creation_time   : 2013-12-24 11:10:47
title           : Big Buck Bunny, Sunflower version
artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
genre           : Animation
composer        : Sacha Goedegebure
encoder         : Lavf54.20.4
Stream #0.0(und): Video: libx264, yuv420p, 1600x900 [PAR 1:1 DAR 16:9], q=-1--1, pass 1,
50000 kb/s, 90k tbn, 60 tbc
Metadata:
  creation_time   : 2013-12-24 11:10:47
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Press ctrl-c to stop encoding
frame=    5 fps=  0 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit
frame=   13 fps= 13 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit
frame=   21 fps= 13 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit
frame=   29 fps= 14 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit
frame=   37 fps= 14 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit
frame=   45 fps= 14 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit
frame=   51 fps= 14 q=0.0 size=       0kB time=10000000000.00 bitrate=   0.0kbit

EDIT2 As suggested, I tried running with -f matroska parameter. This time I also tried doing only one pass, as I thought the second one was too time consuming.

Here is a command I used to convert:

avconv -threads 8  -y -i bbb_sunflower_native_60fps_normal.mp4
-acodec aac -vcodec h264 -f matroska -b:v 10000k  -r:v 60  
-filter:v yadif,scale=1600:900 -aspect 16:9 -b:a 320k r:a 96000
-ac 48 -vol 256  "bbb_sunflower_native_60fps_normal.mkv"

But unfortunately terminal closes as soon as I press enter to confirm avconv output. I tried the same command, just without -f matroska, but I didn't help. Same thing happened.

Here is what was avconv output:

avconv version 9.16-6:9.16-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers
built on Aug 10 2014 18:16:02 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'bbb_sunflower_native_60fps_normal.mp4':
Metadata:
major_brand     : isom
minor_version   : 1
compatible_brands: isomavc1
creation_time   : 2013-12-24 11:10:47
title           : Big Buck Bunny, Sunflower version
artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
genre           : Animation
composer        : Sacha Goedegebure
Duration: 00:10:34.56, start: 0.000000, bitrate: 10487 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 4000x2250 [PAR 1:1 DAR 16:9], 10002 kb/s,
60 fps, 60 tbr, 60k tbn, 120 tbc
Metadata:
  creation_time   : 2013-12-24 11:10:47
Stream #0.1(und): Audio: mp3, 48000 Hz, stereo, s16p, 160 kb/s
Metadata:
  creation_time   : 2013-12-24 11:10:49
Stream #0.2(und): Audio: ac3, 48000 Hz, 5.1, fltp, 320 kb/s
Metadata:
  creation_time   : 2013-12-24 11:10:49
[libx264 @ 0xe96580] using SAR=1/1
[libx264 @ 0xe96580] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0xe96580] profile High, level 4.2
[libx264 @ 0xe96580] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft
2003-2014 - 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=abr mbtree=1 bitrate=10000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69
qpstep=4 ip_ratio=1.25 aq=1:1.00
encoder 'aac' is experimental and might produce bad results.
Add '-strict experimental' if you want to use it.
Press ENTER to continue...
9
  • Please show the full, uncut command line output from both commands. 50 MBit/s is a little bit too much, but it's 60 fps vieo aufter all. Note that you don't need the yadif filter as your input is most probably not interlaced. Also, -c:a aac needs -strict experimental as far as I know (at least for ffmpeg it does). I can probably post an answer once I've seen the output. Thanks.
    – slhck
    Nov 15 '14 at 8:08
  • @slhck I added terminal output from 1st pass into my post. Also, I gave a little explanation on what might happened. I think that things crashed when going from 1st pass to 2nd pass.
    – wnerw
    Nov 15 '14 at 12:54
  • You're using -f null, which basically means, "output nothing". Try -f mp4 instead. Where did you get the first command from?
    – slhck
    Nov 15 '14 at 15:41
  • I used WinFF, as stated in the beginning. I made a preset with only aac and h264, and then I applied all other things through GUI. The program just gave me ready-to-go command... Can't I just make something like -f mkv? I want my video to use mkv container...
    – wnerw
    Nov 15 '14 at 20:16
  • Yes, you can use -f matroska for MKV output. My understanding is that -f null tells ffmpeg/avconv not to output anything, which would explain the problem. Can you try with an updated command?
    – slhck
    Nov 15 '14 at 20:28
1

TL;DR: I would use this for high quality and slow one-pass encoding:

avconv -threads 8 -i bbb_sunflower_native_60fps_normal.mp4 \
-c:a aac -strict experimental -c:v h264 -crf 16 -preset veryslow \
-filter:v scale=1600:900 -aspect 16:9 -b:a 192k -ac 48 -vol 256 output.mp4

First of all, to get any output at all:

  • Change -f null to -f mp4 or -f matroska, depending on whether you want MP4 or MKV as output. If you do a one-pass encode, you don't need this at all, since the output filename will also set the format automatically.

  • Change -acodec aac to -acodec aac -strict experimental, since the internal AAC encoder is considered unstable and needs this extra flag

Then, let's get to the command. A few things to tweak here:

Bitrate and rate control

The bitrate is extremely high. You do not need so much for 1600×900 HD video, even at 60fps. Half of that would absolutely suffice for pristine quality.

You mention that the bitrate is not constant throughout the video. This is expected, since it would be very wasteful to spend x bits on every single frame. You want to save bitrate where you can, and spend it on frames that need it. If you want constrained bitrate, you need VBV encoding (e.g. for a DVD or streaming), but it's rather complicated and normally not needed in practice. A two-pass CBR encode would deliver very good results.

Another suggestion to set the bitrate (indirectly) would be to use the CRF mode. You set it by exchanging -b:v to -crf and then setting the Constant Rate Factor between 0 and 51. 0 means lossless, 15–18 is excellent quality, and 23 is the default. Anything higher will get you visible quality degradations. Using CRF means that you cannot determine the bitrate in advance, but it will deliver the best possible quality.

The 320k audio bitrate is a little "too much" already, even for AAC-LC, and even for the internal encoder. 192k should be enough. You could choose another encoder like libfdk-aac, which delivers better results at lower bitrates. Your ffmpeg needs to be compiled with support for it, though.

Frame-/samplerate and filtering

You do not need to set the framerate explicitly. The input framerate will be kept as-is. You also don't necessarily need to set 96 kHz sampling rate for the audio—depends on how much of an audiophile you are.

You do not need the yadif filter, as it's for deinterlacing. Since Big Buck Bunny is obviously not interlaced, remove the filter.

Speed

The encoding preset has the biggest impact on speed. See the H.264 encoding guide for a list of presets. Slower means better compression efficiency (i.e. smaller file size for the same quality when using CRF, or better quality when using CBR), so choose the slowest preset you can wait for.

1
  • Thanks you again! I kept 320 kbps for audio, as I may add soundtrack to my videos from high quality mp3s or even some loseless formats. Information about presets was extremly valuable! It allows me to convert anytime I want, be it even 15 minutes for a 2h video. Links added to tabs for further research, thanks again!
    – wnerw
    Nov 17 '14 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.