Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Converting .ts to .mp4 or .mkv using ffmpeg in Linux



Introduction

If you are working with video files, you may come across the .ts (Transport Stream) format, which is commonly used for digital television broadcasting. However, this format is not widely supported by media players and devices, so you may need to convert it to a more widely recognized format such as .mp4 or .mkv. In this article, we will show you how to use ffmpeg in Linux to convert .ts files to .mp4 or .mkv.



Step 1: Install ffmpeg First, you need to install ffmpeg on your Linux machine. You can do this by running the following command:

sudo apt-get install ffmpeg

on Arch

sudo pacman -S ffmpeg

    FFmepg Github: https://github.com/FFmpeg/FFmpeg


Step 2: Convert a single .ts file to .mp4 or .mkv To convert a single .ts file to .mp4 or .mkv, you can use the following command:


ffmpeg -i input_file.ts -c:v libx264 -preset medium -crf 23 -c:a copy output_file.mp4


This command uses the libx264 video codec to encode the video with a medium preset and a CRF (Constant Rate Factor) value of 23, which determines the video quality. The audio stream is copied without re-encoding using the -c:a copy option.

To convert to .mkv instead of .mp4, simply change the output file extension to .mkv.

Step 3: Convert multiple .ts files using a for loop If you have multiple .ts files that you want to convert, you can use a for loop to automate the process. Here's an example:


for file in *.ts; do ffmpeg -i "$file" -c:v libx264 -preset medium -crf 23 -c:a copy "${file%.*}.mp4" done

This for loop iterates through all the .ts files in the current directory and converts each one to .mp4 using the same ffmpeg command as in Step 2. The "${file%.*}.mp4" syntax is used to generate the output file name based on the input file name.


Quickly Convert:


for file in *.ts; do
ffmpeg -i "$file" -c copy "${file%.ts}.mp4"
done

Conclusion

Converting .ts files to .mp4 or .mkv is a simple process using ffmpeg in Linux. With the commands provided in this article, you can convert a single file or multiple files using a for loop. Whether you are working with digital television broadcasting or just have some .ts files that you want to watch on your media player, ffmpeg makes it easy to convert to a more widely recognized format.

Share:

The Ultimate Guide to unrar Command in Linux: All Possible Use Cases


In the world of Linux, there are numerous commands that make it easier to navigate and manipulate files and directories. One such command is 'unrar,' which is used to extract files from a RAR archive. RAR stands for 'Roshal Archive,' and is a file format used to compress and archive files. In this blog, we will explore the different use cases of the 'unrar' command in Linux.


1. Extracting RAR archives


The most common use case of the 'unrar' command is to extract files from a RAR archive. To extract a file using 'unrar,' simply type the following command in the terminal:


unrar x filename.rar


where 'filename.rar' is the name of the RAR archive you want to extract. This command will extract all the files in the archive to the current directory.


2. Extracting files from password-protected RAR archives


If the RAR archive is password-protected, you will need to provide the password while extracting the files. To do this, use the following command:


unrar x -pPASSWORD filename.rar


where 'PASSWORD' is the password for the RAR archive. This command will extract all the files in the archive to the current directory.


3. Extracting specific files from a RAR archive


Sometimes, you may only need to extract specific files from a RAR archive. In this case, you can use the following command:


unrar e filename.rar file1 file2 file3


where 'filename.rar' is the name of the RAR archive, and 'file1', 'file2', and 'file3' are the names of the files you want to extract. This command will extract only the specified files from the archive to the current directory.


4. Listing the contents of a RAR archive


To view the contents of a RAR archive before extracting it, you can use the following command:


unrar l filename.rar


where 'filename.rar' is the name of the RAR archive. This command will display a list of all the files in the archive, along with their sizes, dates, and other information.


5. Testing a RAR archive for errors


Before extracting files from a RAR archive, it's a good idea to test it for errors. To do this, use the following command:


unrar t filename.rar


where 'filename.rar' is the name of the RAR archive. This command will test the archive for errors and display a message indicating whether the archive is intact or not. If there are errors in the archive, the command will display an error message.


6. Creating RAR archives


Apart from extracting files from RAR archives, the 'unrar' command can also be used to create RAR archives. To create a RAR archive, use the following command:


unrar a archive.rar file1 file2 file3


where 'archive.rar' is the name of the new RAR archive you want to create, and 'file1', 'file2', and 'file3' are the names of the files you want to add to the archive. This command will create a new RAR archive containing the specified files.


In conclusion, the 'unrar' command is a useful utility for extracting files from RAR archives in Linux. It also has several other use cases, including creating RAR archives, testing archives for errors, and listing the contents of archives. By mastering the different use cases of the 'unrar' command, you can efficiently manage and manipulate RAR archives in Linux.

Share: