How do I convert files with ffmpeg through the command line? - command-line

I do know how to actually convert the files, I don't know if the input and output should include the path of the file or just the file itself - do I write it like this:
ffmpeg -i input.ext1 output.ext2
or like this:
ffmpeg -i C:\Path\input.ext1 C:\Path\output.ext2

Related

Flutter - How get use data in FFMPEG commands (input & output)

In Flutter, How to use data in FFMPEG commands (input & output).
Like:
ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -i 4.mp3 -filter_complex "[0:a][1:a][2:a][3:a]amerge=inputs=4[aout]" -map "[aout]" output.mp3
2 Question regarding this command:
What is the path to bring the '1.mp3', '2.mp3'... to the FFMPEG.
Where is the 'output.mp3' goes to? eventually?
Didn't find any solution, let's speak locally and after that remotely (API/SERVER).
What is the path to bring the '1.mp3', '2.mp3'... to the FFMPEG.
Your ffmpeg command in your question assumes 1.mp3 and 2.mp3 are in the current working directory that ffmpeg is being executed in.
For example, in Linux if the files are in /home/aix/music, then you would have to navigate to /home/aix/music in your terminal (such as by running cd /home/aix/music) before running the ffmpeg command shown in your question.
Or, provide the full path to the files and the current directory will not matter:
ffmpeg -i /home/aix/videos/1.mp4 -i /home/aix/videos/2.mp4 ...
Where is the 'output.mp3' goes to? eventually?
output.mp3 goes wherever you tell it to. Because no path was provided the ffmpeg command in your question it will output output.mp3 into the current directory.
Or, provide the full path to output output.mp3 in the desired directory:
ffmpeg -i input.mp3 /home/aix/music/encoded/output.mp3

How to handle similar names in wget?

I'm downloading so many images that their links are inside a file with the command:
wget -i file.txt
I suspect many of the files might have the same names. So I'm afraid they will be overwritten. is there anyway to make wget set sequential names to the file or handle similar names in any other way?
For wget 1.19.1, what you're looking for is the default behavior. Files that have the same names will be numbered when a matching file is found.
Assuming that file.txt looks like:
http://www.apple.com
http://www.apple.com
http://www.apple.com
http://www.apple.com
The output of wget -i file.txt will be four files, named:
index.html
index.html.1
index.html.2
index.html.3

FFMPEG corrupting audio data when trying to edit metadata

I'm trying to use FFMPEG to edit some metadata in Powershell. My problem is that FFMPEG simply outputs an audio file with the correct metadata, but the audio does not play. The length of the track is reduced to a fraction of a second. Here is the command I'm using in Powershell:
& $ffmpeg -y -i $flac.fullname -c copy -metadata track="$tracknumber" $flac.fullname
Previously, I tried having -map 0:0 in there too, but it didn't make a difference. Thanks for any help.
Edit: I'm not sure if this is intentional behavior or not, but if I change the output path to be a new destination (rather than saving over the old destination) it does work correctly. So as a workaround, I'm just using a temp folder as an output then moving the files back to where I want them.
FFmpeg does NOT do in-place editing. Destination has to be a new file.
ffmpeg -y -i file.flac -c copy -metadata track="$tracknumber" newfile.flac

Trim mp4 files without encoding it again

I have a .mp4 video file, I need to trim it, however no matter how I do it, trimmed video is being encoded again which results in noisy video.
What I've tried:
Open video with Matlab, read frames and write only the frames that I want to have in trimmed video, I use 'MPEG-4' option.
Trim video using Windows Movie Maker.
Trim video using VirtualDub.
In first 2 scenarios original mp4 movie is encoded again after trimming it. I couldn't get mp4 files open in VirtualDub.
So what would be the easiest way to trim a video without re-encdong it?
You can do the split and re-encode in one command.
Create a text file, list.txt,
like this
file 'in.mp4'
inpoint 48.101
outpoint 67.459
file 'in.mp4'
inpoint 76.178
outpoint 86.399
file 'in.mp4'
inpoint 112.140
outpoint 125.031
then run,
ffmpeg -f concat -i list.txt -an -crf 18 out_merged.mp4
I've solved it with the following commands:
ffmpeg.exe -ss 48.101 -t 19.358 -i in.mp4 -an out_part1.mp4
ffmpeg.exe -ss 76.178 -t 10.221 -i in.mp4 -an out_part2.mp4
ffmpeg.exe -ss 112.140 -t 12.891 -i in.mp4 -an out_part3.mp4
ffmpeg -i out_part1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt1.ts
ffmpeg -i out_part2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt2.ts
ffmpeg -i out_part3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt3.ts
ffmpeg -i "concat:intrmdt1.ts|intrmdt2.ts|intrmdt3.ts" -c copy out_merged.mp4
And some explanation:
Giving -ss (start time) and -t (duration) options before -i (input) option avoids unnecessary decoding.
Not using -c copy provides transcoding hence result more precise cut (got this from here).
I used -an because I didn't need the audio, if you need audio just omit this option.
Before concatenating the resulting trimmed videos I needed to transcode them to mpeg transport streams, to achieve lossless concatenation (for more details you can see this link).

how to use -o flag in wget with -i?

I understand that -i flag takes a file (which may contain list of URLs) and I know that -o followed by a name can be specified to rename a item being downloaded using wget.
example:
wget -i list_of_urls.txt
wget -o my_custom_name.mp3 http://example.com/some_file.mp3
I have a file that looks like this:
file name: list_of_urls.txt
http://example.com/some_file.mp3
http://example.com/another_file.mp3
http://example.com/yet_another_file.mp3
I want to use wget to download these files with the -i flag but also save each file as 1.mp3, 2.mp3 and so on.
Can this be done?
You can use any script language (PHP or Python) for generate batch file. In thin batch file each line will contains run wget with url and -O options.
Or you can try write cycle in bash script.
I ran a web search again and found https://superuser.com/questions/336669/downloading-multiple-files-and-specifying-output-filenames-with-wget
Wget can't seem to do it but Curl can with -K flag, the file supplied can contain url and output name. See http://curl.haxx.se/docs/manpage.html#-K
If you are willing to use some shell scripting then https://unix.stackexchange.com/questions/61132/how-do-i-use-wget-with-a-list-of-urls-and-their-corresponding-output-files has the answer.