5

I have used the command

ffmpeg -i input.webm -q:v 10 -c:a copy out.mp4

I also tried using avconv instead of ffmpeg.

The conversion is successful but the quality is bad. Also it takes a lot of time. It also does not play with Windows Media Player. (The reason for this is the mpegv1 to which the file is converted.) How do I add an option to convert it to mpegv2?

Following is the command line output:

avconv version 0.8.16-4:0.8.16-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Sep 16 2014 18:33:49 with gcc 4.6.3 
[matroska,webm @ 0xe737a0] Estimating duration from bitrate, this may be inaccurate
Input #0, matroska,webm, from 'test.webm':
  Duration: 00:00:08.57, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: vp8, yuv420p, 1536x768, PAR 1:1 DAR 2:1, 1k fps, 1k tbr, 1k tbn, 1k tbc (default) 
    Stream #0.1: Audio: vorbis, 44100 Hz, stereo, s16 (default)
[buffer @ 0xee38e0] w:1536 h:768 pixfmt:yuv420p
Output #0, mp4, to 'c2.mp4':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: mpeg4, yuv420p, 1536x768 [PAR 1:1 DAR 2:1], q=2-31, 200 kb/s, 1k tbn, 1k tbc (default)
    Stream #0.1: Audio: libvorbis, 44100 Hz, stereo (default)
Stream mapping:
  Stream #0:0 -> #0:0 (vp8 -> mpeg4)
  Stream #0:1 -> #0:1 (copy)
Press ctrl-c to stop encoding
frame= 8572 fps=342 q=10.0 Lsize=   90902kB time=8.56 bitrate=86984.0kbits/s dup=8438 drop=0    
video:90823kB audio:0kB global headers:0kB muxing overhead 0.086778%
slhck
  • 223,558
  • 70
  • 607
  • 592
dfordevy
  • 137
  • 1
  • 2
  • 9

3 Answers3

8

Several problems here:

  • You are using an old version of avconv from the Ubuntu 12.04 repos.
  • This version does not have an H.264 encoder (libx264) compiled into it.
  • That's why it chooses MPEG-4 Part II video instead, using the mpeg4 encoder. While it still uses the same .MP4 container, MPEG-4 Part II is not as efficient as H.264.
  • Your command uses -q:v 10, which is quite low quality. The range is from 1–31, where 1 is the best, and ideally you want something around 2–5.
  • You cannot copy Vorbis audio to MP4 containers, so -c:a copy will not work.

So, to fix this, I'd recommend one of two options:

  1. Keep using avconv. Install apt-get install libavcodec-extra-53 on Ubuntu 12.04 and libavcodec-extra-54 on Ubuntu 14.04 to get x264 support for avconv.
  2. Use a recent ffmpeg instead. Download a recent ffmpeg build (click on the Linux Static Builds link). Extract the ffmpeg binary somewhere and use this.

Then run the following command (and replace ffmpeg with avconv depending on what your choice is):

ffmpeg -i input.webm -c:v libx264 -crf 20 -c:a aac -strict experimental out.mp4

The CRF controls the quality, where 18–28 are sensible choices. Lower is better, and 23 is default. You may set the audio bitrate with -b:a 128k or similar to your liking.

If you want to speed up the conversion you can use -preset and set it to one of ultrafast, superfast, veryfast, faster, fast, e.g. -preset fast. Note that setting this will increase your file size.

The H.264 encoding guide for ffmpeg is pretty helpful and should also apply to avconv (but no guarantees on that).

As for MPEG-2, have a look at this question: How to make an MPEG2 video file with the highest quality possible using FFMPEG? — and don't forget to choose -c:a libmp3lame as audio instead.

slhck
  • 223,558
  • 70
  • 607
  • 592
  • What do we do to use it in Ubuntu 14.04? – dfordevy Feb 07 '15 at 13:18
  • You can do exactly the same thing in Ubuntu 14.04 but with `libavcodec-extra-54`. As for the file being "still MP4v1", you need to tell me what exactly you did and upload the full command line output somewhere (e.g. http://pastebin.com/). – slhck Feb 07 '15 at 13:21
  • I have pasted the output of: avconv -i input.webm -c:v libx264 -crf 20 -c:a aac -strict experimental test_1min_no_preset.mp4 here: http://pastebin.com/SQdbvM0Y. when I do file test_1min_no_preset.mp4, test_1min_no_preset.mp4: ISO Media, MPEG v4 system, version 1 – dfordevy Feb 09 '15 at 05:27
  • I don't think avconv or ffmpeg can write `mp42` tags. Why do you actually need it? Is MP4v1 not good enough? – slhck Feb 09 '15 at 07:30
  • Any tag is ok for me but I just need that to play them using Windows Media Player. – dfordevy Feb 09 '15 at 07:33
  • That solely depends on the version of Windows Media Player and Windows: http://support.microsoft.com/kb/316992?wa=wsignin1.0 — only the newest WMP can play H.264/AAC at all. For older WMP versions you need additional codecs. – slhck Feb 09 '15 at 07:42
  • I need those codecs too, I need it to be supported on old Windows Media Players. What do I need to do for that? – dfordevy Feb 09 '15 at 11:16
  • See http://superuser.com/questions/314694/how-do-i-tell-ffmpeg-to-transcode-to-a-video-codec-supported-by-windows-media-pl and http://superuser.com/questions/435941/which-codecs-are-most-suitable-for-playback-with-windows-media-player-on-windows and http://superuser.com/questions/418945/convert-video-into-format-which-is-most-likely-playable-on-a-windows-system – slhck Feb 09 '15 at 11:18
  • http://pastebin.com/MR2gkNjA this is what the output looks like on my trusty machine where converted file is showing me black video. With the same command as above. The only change is that I have tried to just copy the audio. – dfordevy Feb 09 '15 at 11:27
  • You haven't told me what command you're using though. Also, I would recommend you ask a new question (as this comment thread really should not be used as a substitute for chat), including the command, the command line output, and what player you're trying to view the video in. Thanks! – slhck Feb 09 '15 at 11:32
6

ffmpeg version 1.2.6-7:1.2.6-1~trusty1

ffmpeg -i one.webm -r 10 -cpu-used 5 -c:v libx264 -crf 20 -c:a aac -strict experimental -loglevel error /tmp/one.mp4

This works very well. Converted 1 hour video in 10 minutes.

dfordevy
  • 137
  • 1
  • 2
  • 9
-2

Try ffmpeg -i input.webm -sameq out.mp4

As alternatives, you can try FFMC: http://www.noobslab.com/2013/04/latest-ff-multi-converter-for-ubuntu.html or pre-compiled Miro: http://www.getmiro.com/download/for-ubuntu/

Overmind
  • 9,924
  • 4
  • 25
  • 38
  • it says unrecognised option sameq – dfordevy Feb 05 '15 at 09:39
  • also ffmulticonverter did not do the conversion – dfordevy Feb 05 '15 at 09:45
  • Do not use sameq: http://superuser.com/questions/478549/what-is-the-sameq-or-same-quant-option-in-ffmpeg-does-it-mean-same-quality. It does not mean same quality, and recent versions of ffmpeg do not even have this option anymore (for good reasons). – slhck Feb 05 '15 at 11:04
  • @Overmind - It would be nice if you formatted your post. You have more then enough reputation to use hot links in your answers. This is only a suggestion to avoid additional downvotes. – Ramhound Feb 05 '15 at 13:06
  • I encounter several problems regarding this matter.Sometimes the code function does not work properly (specially when using special characters). Also, in the comment screen area if I press enter the comment is posted instead of getting to a new line. I didn't try to test special characters like the end-of-line one. Anyway, I'm trying to get more familiar with this UI. – Overmind Feb 05 '15 at 13:39
  • 1
    http://superuser.com/help/formatting – slhck Feb 05 '15 at 16:02
  • They seem ok, however they do not seem to work on comments. Is there a different thing for comments ? – Overmind Feb 06 '15 at 07:51
  • 1
    @Overmind Comments use restricted formatting. Click the `Help` link next to the commenting window. Don't forget you have to @-ping users for them to receive a notification. – slhck Feb 06 '15 at 09:33