Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  64] [ 0]  / answers: 1 / hits: 132941  / 1 Year ago, wed, april 19, 2023, 12:45:12

I know there are a lot of questions about video encoders around here, but my question is more about workflow/efficiency.



For my day job, I need to convert videos, frequently, from many random formats (usually large AVI, M4V, and what not) and convert them and compress them down into efficient files we can use around the internet for uploading. Formats I must produce are:





I need to create common templates for a couple use cases (convert to same-as-source, 1080p, or 720p) and be able to process these quickly, and en queue.



Any ideas on how to best go about this process in Ubuntu?


More From » video

 Answers
6

If you prefer command-line you can use ffmpeg (or handbrake-cli).


MP4


Assuming you're using a recent version of ffmpeg:


ffmpeg -i input -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k 
-movflags +faststart -vf scale=-2:720,format=yuv420p output.mp4


  • -crf: Quality. Range is logarithmic 0 (lossless) to 51 (worst quality). Default is 23. Subjective sane range is ~18-28 or so. Use the highest value that still gives you an acceptable quality. If you are re-encoding impractically large inputs to upload to YouTube or similar then try a value of 17 or 18 since these video services will re-encode anyway.



  • -preset: Encoding speed. A slower preset provides better compression (quality per file size) but is slower. Use the slowest that you have patience for: ultrafast, superfast, veryfast, faster, fast, medium (the default), slow, slower, veryslow.



  • -movflags +faststart: Allows video to playback before it is completely downloaded in the case of progressive download viewing. Useful if you are hosting the video, otherwise superfluous if uploading to a video service like YouTube.



  • -vf scale=-2:720,format=yuv420p: A filtergraph using scale and format video filters. Scale to 720 pixels in height, and automatically choose width that will preserve aspect, and then make sure the pixel format is compatible with dumb players.



  • -b:a 128k: Audio bitrate. If your ffmpeg is outdated then you'll need to add -strict experimental to use -c:a aac.




MOV


Since your MOV and MP4 files probably contain the same video and audio formats you can encode the MP4 and make the MOV by re-muxing (with stream copy mode) instead of re-encoding:


ffmpeg -i input.mp4 -codec copy output.mov

WMV


FFmpeg only supports WMV 7 and 8. I am unaware of an open source encoder for version 9.


$ ffmpeg -encoders | grep -i windows
[...]
V..... = Video
A..... = Audio
------
V..... wmv1 Windows Media Video 7
V..... wmv2 Windows Media Video 8
A..... wmav1 Windows Media Audio 1
A..... wmav2 Windows Media Audio 2

As I am unfamiliar with these encoders I can only give an untested example:


ffmpeg -i input -c:v wmv2 -b:v 1024k -c:a wmav2 -b:a 192k output.wmv

Getting ffmpeg


You can download a Linux build of ffmpeg or follow a step-by-step ffmpeg compilation guide to customize your build.


Using a bash "for loop" to perform a batch encode


To encode all videos in a directory:


$ mkdir encoded
$ for f in *.avi; do ffmpeg -i "$f" -c:v libx264 -crf 23 -preset medium
-c:a aac -b:a 128k -movflags +faststart -vf scale=-2:720,format=yuv420p
"encoded/${f%.avi}.mp4"; done

Also see



[#29190] Wednesday, April 19, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
scusaper

Total Points: 335
Total Questions: 111
Total Answers: 119

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
scusaper questions
Fri, Apr 15, 22, 15:26, 2 Years ago
Wed, Mar 15, 23, 03:53, 1 Year ago
Sat, Jun 4, 22, 18:03, 2 Years ago
;