3

I got the following code from some forum. I'm a beiginner, so please bear with my questions ...

I need to convert a video from MTS to AVI in very good quality. Currently I'm using the following code for conversion.

for %%a in ("*.mts") do ffmpeg.exe -i "%%a" -vcodec libxvid -vtag XVID -aspect 16:9 -maxrate 1800k -b 1500k -qmin 10 -qmax 42 -bufsize 5120  -acodec libmp3lame -ac 2 -ab 160k -y "%%~na_xvid.avi" 
for %%a in ("*.m2ts") do ffmpeg.exe -i "%%a" -vcodec libxvid -vtag XVID -aspect 16:9 -maxrate 1800k -b 1500k -qmin 10 -qmax 42 -bufsize 5120 -acodec libmp3lame -ac 2 -ab 160k -y "%%~na_xvid.avi" 

But I'm expecting better quality than the above. How do I get that?

2 Answers2

4

MPEG-4 Part 2 video

When encoding to MPEG-4 Part 2 video using the encoders mpeg4 or libxvid use -qscale:v (or the alias -q:v).

ffmpeg -i input -c:v libxvid -qscale:v 2 -c:a libmp3lame -ac 2 -q:a 4 output.avi
  • Adjust -qscale:v for video quality and -q:a (similar to lame -V) for audio quality.

  • A lower value is a higher quality for both options. You may not be able to tell the difference between the input and output with -qscale:v 2.

Also see:

H.264 & H.265/HEVC video

MPEG-4 Part 2 video is outdated. Using a more modern format will provide better quality at lower bitrates.

Simple example assuming your ffmpeg has support for libx264/libx265 (it probably does):

ffmpeg -i input output.mp4

The above example will use the default setting which is the same as below:

ffmpeg -i input -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
  • Avoid AVI if possible with these encoders.
  • Use AAC instead of MP3.

Also see:

llogan
  • 63,280
0

Being an amateur myself, on Linux I use ffmpeg -i video.MTS -acodec copy -vcodec rawvideo -y video.avi to keep the raw video and original audio data. The flags plus options are

-i: input file
-acodec copy: copy audio codec
-vcodec rawvideo: keep raw data for video codec
-y: silently overwrite output files

For a bunch of .mts files in one directory, run

for f in *.MTS; do ffmpeg -i $f -acodec copy -vcodec rawvideo -y  ${f%.*}.avi; done

This retains the quality of the video, although resulting in quite huge .avi files.