Archive

Posts Tagged ‘ffmpeg’

simplescreenrecorder

September 24, 2017 Leave a comment

Problem
Under Linux you want to do some screen capturing. For instance, you want to do some tutorial videos.

Solution
I used gtk-RecordMyDesktop for a long time, but my current favorite is simplescreenrecorder. With gtk-RecordMyDesktop I could only save in .ogv format that I had to convert to .mp4 with ffmpeg. simplescreenrecorder can save directly in mp4 format.

Adobe Premiere Pro CS6
For editing my videos, I started to use Adobe Premiere Pro CS6. First, I asked my friends, and most of them suggested this. Second, I found some good and detailed tutorial videos for this software. I’m a newbie in video editing, so I needed some tutorials that showed everything step by step.

However, in Premiere Pro I ran into a problem. You need to import a video file and pull it to the timeline if you want to edit it. However, when I pulled an mp4 file, the audio track didn’t appear on the timeline. I had a workaround solution: from my .mp4 I extracted the audio in .wav format (with ffmpeg), and pulled it to the audio track. Strangely, the audio track was often a little bit shorter than the video track. But it was just annoying, it didn’t cause a problem.

So I tried some other screen capturing tools next to gtk-RecordMyDesktop, and that’s how I found simplescreenrecorder. After several trial and errors, I figured out why the audio track was missing. Whether the audio track appears or not depends on the audio codec! If you save the audio in AAC format, then Premiere Pro will like it and the audio track will appear when you pull such an .mp4 on the timeline. The good news is that you can select in simplescreenrecorder what audio codec you want to use!

Screenshots
Here are some screenshots of my simplescreenrecorder setup:

Alternatives
For some more screen capturing tools, see this post: 5 Best Screen Capture Tools for Linux.

Advertisements

convert mp4 to webm and ogv

November 5, 2016 1 comment

Problem
I wanted to share an .mp4 file on my webserver but Firefox didn’t play it. It turned out Firefox prefers the .webm and .ogv formats, while Chrome can play .mp4.

Solution

Convert mp4 then:

.mp4 to .webm

ffmpeg -i input.mp4 -vcodec libvpx -acodec libvorbis -b:v 600k -cpu-used 4 -threads 8 output.webm

To change the quality, play with the “600k” value (bitrate).

.mp4 to .ogv

ffmpeg -i final.mp4 -vcodec libtheora -acodec libvorbis -b:v 600k -cpu-used 4 -threads 8 final.ogv

Here the difference is the codec (libtheora instead of libvpx).

Maybe I missed something, but the .webm file seemed to me to have better quality than .ogv. So I think it’s enough to support two formats only: .mp4 for Chrome and .webm for Firefox. By the way, in my test the input file (.mp4) had the best quality and smallest filesize, but again, I may miss something.

And here is an HTML5 code that can play your video:

<video controls preload="metadata" width="1024" height="768" poster="images/front.jpg">
    <source src="video.mp4" type="video/mp4">
    <source src="video.webm" type="video/webm">
    <p>Please use a modern browser to view this video.</p>
</video>
Categories: firefox Tags: , , , , , ,

resize an .mkv file

December 5, 2015 Leave a comment

Problem
I wanted to play a 720p .mkv file on an old laptop but it was painfully slow. How to reduce the quality of an .mkv file?

Solution
I found the solution here. The following worked for me:

$ ffmpeg -i Movie.mkv -vf scale=-1:360 -c:v libx264 -crf 18 -preset veryslow -c:a copy MyMovie_360p.mkv

Visit the link above for an explanation of the parameters.

Categories: bash Tags: , , , ,

convert .wmv to .mp4

ffmpeg -i input.wmv -c:v libx264 -crf 23 -profile:v high -r 30 -c:a libfaac -q:a 100 -ar 48000 output.mp4

More info here.

Categories: bash Tags: , , , ,

Replace the audio track in a video

Problem
You have a video with an audio track (call it video.mp4). You have an audio file (e.g. audio.mp3) that you want to put on the video, replacing the original audio of the video file.

Solution
With Audacity, you can open both video.mp4 and audio.mp3 and you can synchronize the mp3 to match the original audio. Important points: speech/music should start at the same time, and its length should be the same or a little bit less than the original audio.

Once you have a good audio.mp3 file, do the replacement with the following command:

ffmpeg -i audio.mp3 -i video.mp4 -c copy final_video.mp4

Solution #2
Before the previous solution, I used Avidemux, but it tends to crash sometimes :) When I have such videos where Avidemux crashes, I use ffmpeg from the command-line.

Compile your own FFmpeg

March 5, 2013 Leave a comment

Problem
There are some great audio codecs for FFmpeg which are open source but not completely compatible with GPL, thus they are not included in the FFmpeg package that you can install from the official repositories.

Solution
If you want these codecs, you must compile your own FFmpeg.

Here you can find a nice description of the available audio codecs. Which one should you use? In short, they come in this order: libfdk_aac > libfaac > Native FFmpeg AAC ≥ libvo_aacenc, i.e. libfdk_aac provides the best quality.

You can download static builds from here but they don’t include libfdk_aac and libfaac either :(

Compiling FFmpeg
Fortunately, compiling FFmpeg under Ubuntu is quite easy. You just need to follow this guide.

I have an installer script for Ubuntu called jabbatron. The new version of this script includes (1) compiling FFmpeg, and (2) updating FFmpeg. They are available under the menu point “(170) install from source (mc, tesseract3, ffmpeg)…”. This script automates all the steps that are described in the aforementioned guide.

Categories: ubuntu Tags: , ,

Resize movies for Android/iOS with ffmpeg

February 26, 2013 Leave a comment

Update (20130227): I made a resizer script. See the end of the post.

Problem
You have an Android/iOS phone and you want to watch movies on it. However, if you transfer a movie to the phone, the media player may stop playing it or it may even freeze. Apparently, the movie is too big for your phone. What to do?

Solution
If the media player has problems playing the movie, then it’s too big, thus you should resize it. Then the phone will be able to play it nicely.

Under Windows there is a nice video converter called AVS Video Converter. But if we are under Linux, what can we do?

Well, ffmpeg can do the job for us. But the question is: how to parameterize ffmpeg? :) Here it is:

ffmpeg -i INPUT -codec:v libx264 -quality good -cpu-used 0 -b:v BITRATE -profile:v baseline -level 30 -y -maxrate 2000k -bufsize 2000k -vf scale=WIDTH:HEIGHT -threads THREADS -codec:a libvo_aacenc -b:a 128k OUTPUT.mp4

Let’s see a concrete example. I have a Huawei Ascend Y200 whose resolution is 480×320 pixels. As for the bitrate, 600 kb/s is enough IMO. I want ffmpeg to use 2 cores of the CPU. So:

time ffmpeg -i input.avi -codec:v libx264 -quality good -cpu-used 0 -b:v 600k -profile:v baseline -level 30 -y -maxrate 2000k -bufsize 2000k -vf scale=480:320 -threads 2 -codec:a libvo_aacenc -b:a 128k output.mp4

I like to see how much time the conversion takes, that’s why I added the “time” command.

Another advantage of this approach is that you can launch the conversion in batch mode. Say you want to convert all the episodes of your favorite TV show. No problem, just write a little script.

ffmpeg
I use Ubuntu and it comes with an old ffmpeg that fails for instance with the parameters above. So I downloaded a static ffmpeg build from http://ffmpeg.gusari.org/static/. FFmpeg exists under Windows too, so the method presented above should work on Windows (though I didn’t try it).

Credits
I’ve read about this solution in this article. You can find more examples with ffmpeg in this source.

Related Work
If you prefer GUI applications, you can take a look at HandBrake.

Script
I made a script that can process movies in batch mode. Available here.

Categories: ubuntu Tags: , , ,