Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active March 17, 2024 16:37
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save vielhuber/cf918eed2b5cc9eaa63f to your computer and use it in GitHub Desktop.
Save vielhuber/cf918eed2b5cc9eaa63f to your computer and use it in GitHub Desktop.
ffmpeg: Video convert m2ts to mp4, mp4 to webm, mp4 to ogv #tools
MP4 TO MP4 (MEDIUM)
ffmpeg -i input.mp4 -b 1000000 output.mp4
M2TS TO MP4
ffmpeg -i input.m2ts -vcodec libx264 -crf 20 -acodec ac3 -vf "yadif" output.mp4
MP4 TO WEBM (HIGH)
ffmpeg -i input.mp4 -aq 5 -ac 2 -qmax 25 -threads 2 output.webm
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus output.webm
MP4 TO WEBM (MEDIUM)
ffmpeg -i input.mp4 -aq 5 -ac 2 -qmax 35 -threads 2 output.webm
MP4 TO OGV (HIGH)
ffmpeg -i input.mp4 -vcodec libtheora -acodec libvorbis -q:v 6 -q:a 5 output.ogv
MP4 TO OGV (MEDIUM)
ffmpeg -i input.mp4 -vcodec libtheora -acodec libvorbis -q:v 2 -q:a 4 output.ogv
@guy-teube
Copy link

Hello,

MP4 TO MP4 (MEDIUM)
ffmpeg -i input.mp4 -b 1000000 output.mp4

M2TS TO MP4
ffmpeg -i input.m2ts -vcodec libx264 -crf 20 -acodec ac3 -vf "yadif" output.mp4

I don'y understand what is -b 1000000 format.
ffmpeg documentation is exhaustive, but quite difficult to understand, especially for non fluent englidh people.

My goal is to convert m2ts files in mp4 format, keeping the quality as good as possible.
I always use:
ffmpeg -i input.m2ts output.mp4
I get mp4 files with size 2x smaller than the m2ts file, and sometimes I see some "aliasing" (not sure it's the good word) when the animation of the video goes fast.
So I'm searching the good parameters to have mp4 in good quaity.
In the 2 examples above, which is the best way to my expected result?
Maybe it's others parameters?
Thank you for your advice.

@hmooly
Copy link

hmooly commented Feb 25, 2024

Hello,

MP4 TO MP4 (MEDIUM)
ffmpeg -i input.mp4 -b 1000000 output.mp4

M2TS TO MP4
ffmpeg -i input.m2ts -vcodec libx264 -crf 20 -acodec ac3 -vf "yadif" output.mp4

I don'y understand what is -b 1000000 format. ffmpeg documentation is exhaustive, but quite difficult to understand, especially for non fluent englidh people.

My goal is to convert m2ts files in mp4 format, keeping the quality as good as possible. I always use: ffmpeg -i input.m2ts output.mp4 I get mp4 files with size 2x smaller than the m2ts file, and sometimes I see some "aliasing" (not sure it's the good word) when the animation of the video goes fast. So I'm searching the good parameters to have mp4 in good quaity. In the 2 examples above, which is the best way to my expected result? Maybe it's others parameters? Thank you for your advice.

I would use "-c:v copy -c:a copy", it will not re-encode the video/audio and will copy them into mp4 container.

ffmpeg -i input.m2ts -c:v copy -c:a copy output.mp4

Most of the time it works for me but I had issues with frame rates before.

@guy-teube
Copy link

Yes, this is what I usually use:

ffmpeg -i input.m2ts -c copy output.mp4 

But I have issues too with frame rates, and some mp4 (not all) have the aliasing I'm talking about in the first message. I have less when I remove the copy argument, to reencode the video, but it's a pain in the ass when I have multiple videos to convert (it takes time and CPU power).
I don't know if the cause is the convertion, or ffmpeg itself.
Thanks for the confirmation anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment