0

So, I have a bunch of .mp4 files and I need to change the video and audio codecs in order to be able to play them on my device.

The video codec is currently h264 and I need mpeg4. The audio codec is aac and I need mp3.

I'm trying to convert them via this ffmpeg command:

ffmpeg -y -i input -s:v 800x480 -c:v mpeg4 -c:a mp3 output

It works fine, except for the quality because ffmpeg is using a very low bitrate.

My question now is if I need to specify a quality/bitrate or if it is possible to tell ffmpeg to use the original bitrate somehow.

-vcodec copy is not an option because the video codec stays the same.

  • Keeping the bitrate would only make sense of you were using the same codec. Instead, you must use a higher bitrate, because mpeg4 is less efficient. – Daniel B Jul 27 '17 at 13:30
  • Default bitrate is 200 kbps. Instead of specifying a bitrate, set a quality factor: -q:v 5 – Gyan Jul 27 '17 at 13:33
  • Thanks. I thought I could save processing power if I somehow kept the bitrate. – GreenSmurf Jul 27 '17 at 13:50
  • No, absolutely not. The video stream will be first decompressed (using H264) and then compressed (using MPEG4 or whatever) again. These processes run completely independent from each other. – Daniel B Jul 27 '17 at 18:57
2

It works fine, except for the quality because ffmpeg is using a very low bitrate.

The defaults for mpeg4 are not well chosen, so the target bitrate is quite low. Specify your own target with -b:v 2M (depending on your resolution) or even better, use constant quality with -q:v 5 (as suggested by Mulvya in the comments). In the latter case, lower values mean better quality.

My question now is if I need to specify a quality/bitrate or if it is possible to tell ffmpeg to use the original bitrate somehow.

No – it wouldn't even make sense to do that. If you are going from one codec to another, they might be less or more efficient. Each codec offers different quality at different bitrates – for example, H.264 is much more efficient than MPEG-4 Part II. H.265 is 30–50% more efficient than H.264, etc. The same goes for the actual encoders implementing the codecs: x264 is more efficient than the reference H.264 encoder, etc.

Therefore, taking the original bitrate may not work well. And even keeping the same codec, if you re-compress, you might want to use an even higher bitrate to avoid generation loss.

  • 1
    Also different encoder implementations for the same format vary in encoding efficiency (x264 vs openh264 vs AME vs QuickTime vs H.264 hardware encoders, etc). Then there is the effect of re-encoding noisy compression artifacts. And of course there is the human factor: who knows if they person making the original video knew what they were doing in the first place. – llogan Jul 27 '17 at 22:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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