How to convert MP4 files to MPEG with avconv?

MOHAMED picture MOHAMED · Mar 20, 2013 · Viewed 18.7k times · Source

I have some video files in the MP4 format and I want to convert them to MPEG format files.

I try to convert with:

avconv -i 1.mp4 -fmp4 -target mpeg /mpeg/1.mpeg

but I get the following error

1.mp4: Invalid data found when processing input

What am I missing in my command?

Answer

slhck picture slhck · Mar 20, 2013

I encourage you to read the documentation of the tool before using it. Here's what's wrong:

  • -fmp4 isn't a valid option. Perhaps you meant -f mp4, with a space, but:
    • this is superfluous, as your input file has the suffix .mp4 and avconv should parse this just fine
    • the option is placed incorrectly, as you need to put the -f before the input file you specify with -i.
  • -target only takes the values vcd, svcd, dvd, dv, dv50, and not mpeg. If you want to encode MPEG video, you'll need to choose a video codec with -c:v. -target only should be used if you want to target any of the output formats above, in which case avconv then chooses the proper codecs on its own.

That being said we don't know what MPEG video you want. There's MPEG-1, MPEG-2, MPEG-4 Visual, and MPEG-4 AVC, each with different encoders. See avconv -codecs for a list.

Try something like this:

avconv -i 1.mp4 -c:v mpeg2video -q:v 2 -c:a libmp3lame output.mpg

I explicitly specified MPEG-2 video here, with variable quality encoding. The quality factor -q can be set from 1 to 31, with 1 being the best quality. 2–5 is a good range to try. MP3 audio is optional, but it always helps explicitly specifying the codecs you want rather than having avconv choose defaults.

Also, when asking questions about Libav or FFmpeg, please always include the full, uncut console output, not only the error messages you think are relevant. Otherwise, troubleshooting is much more complicated.