Convert (numerically ordered) bitmap files to video file using avconv - linux

I am attempting to convert a directory full of .bmp files into a .mp4 file (or similar format).
The bitmap files have the following name scheme:
output_N_1024.bmp
Where N is an integer in the range 0 to 1023. (No zero padding / fixed width.)
The command I am using is:
avconv -r 25 -i output_{0..1023}_1024.bmp outputfile.mp4
This appears to run okay, and takes about a minute to convert all 1024, 1024 by 1024 resolution - (confusing?) bitmap images into a new file, outputfile.mp4.
However, when I attempt to open this file with VLC, a black window briefly flashes up and then closes. VLC then goes back to its mode where it waits for you to tell it which file to open next. No error or warning messages appear from VLC, which seems kind of strange since it seems to be refusing to play.
What can I do to fix this? Perhaps my converting command is incorrect?

The problem most likely is that you haven't actually passed the command to encode these files to avconv. This has happened because your shell has expanded the filenames already.
The command i have just managed to get to work on my machine is:
avconv -r 2 -i "%d.bmp" -s 600x400 -an out.ogv
Also for whatever reason it didn't want to work without explicitely giving it the size, but i don't think this is your problem.
In here quotes tell your shell not to touch this string. %d means digits from 1 to whatever the last file is (if you would want them to be 0-padded this would look like %000d to have maximum of three naughts in front).
VLC has then opened and ran my file just fine.

Related

Chopping audio files with ffmpeg get None duration python 3

I have a long list of audio files, and some of them are longer than an hour. I am using Python 3.6, Jupyter notebook by connecting to a remote machine and using TinyTag library to get a duration of audio. Ffmpeg version is 2.8.14-0ubuntu0.16.04.1.
My code below goes over the files and if a file is longer than an hour, it splits the file into one-hour long pieces, and a leftover piece less than an hour, and copies the pieces as fname_0, fname_1,fname_2, etc. Before chopped, each file is .m4a but during chopping, they are converted to a .wav file. However, after this chopping process, when reading the duration of pieces, I realized that all the pieces have 'None' duration. Something must be wrong in the command line but I can`t see what that is. Thanks in advance.
# fpaths is the list of filepaths
for i in range(0,len(fpaths)):
fpath=fpaths[i]
fname=os.path.basename(fpath)
fname0=os.path.splitext(fname)[0] #name without extension
tag = TinyTag.get(fname)
if tag.duration > 3600:
cmd2 = "ffmpeg -i %s -f segment -segment_time 3600 -c copy %s" %(fpath, fname0) + "_%d.wav"
os.system(cmd2)
os.remove(fpath)
When I change to the extension from .wav to .m4a in the cmd2 command line, it works. Writing here just in case if someone has the same problem.

Removing / Overlaying logo on mp4 video format with ffmpeg on linux

I'm trying to remove a logo from an .mp4 video file with ffmpeg on linux machine without re-encoding (for preserving the same quality) with the following command:
ffmpeg -i input.mp4 -vf delogo=x=270:y=190:w=40:h=40 -c:a copy output.mp4
and it gives me the following errors:
Unrecognized option 'vf'
then a new error came up:
Unable to find a suitable output format for 'delogo=x=270:y=190:w=40:h=40'
ffmpeg is always updating and it seems that they change command line arguments a lot so any material or tutorial I find online seems to get outdated quickly ...
I reviewed the documentation but can't get it to work, I think I'm missing something...?
So: What is the correct command line in linux shell? Also, how to view or find out the exact coordinates of the area to be removed before actually removing the logo? And how can I overlay a solid color in a certain area instead of removing the logo transparently?
Unrecognized option 'vf'
What version of ffmpeg? (You should be able to tell from the output of running just "ffmpeg" without arguments.) My guess is that you have a terribly old version, "-vf" is still current syntax.
put the delogo phrase in quotation marks: "delogo=x=270:y=190:w=40:h=40"

Sox batch process under Debian

I want to resample a bunch of wav files that I got on a folder.
My script is this:
for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done
The console give me this error: "sox FAIL formats: can't open input file `“90.wav”': No such file or directory" and so on with the 300 files that are placed on that folder.
How can I batch processing right this files? Why is it giving me this error?
Thanks a lot!
Solution:
for i in *wav; do echo $i; sox $i -r 48000 ${i%%.wav}r.wav; done
Summary: It is the quote symbols
The problem is with the double-quotes:
for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done
The double-quotes above are non-standard. For them to be properly processed by the shell, the standard ASCII quote symbol must be used:
for f in ./*.wav; do sox "$f" -r 48000 "${f%%%.wav}.wav"; done
As an aside, note that ${f%%%.wav} removes any occurrences of %.wav from the end of the input file name. ${f%%%.wav}.wav adds one .wav back on to the end after removing any %.wav suffixes. You likely want something else here.
Verification
Using the bad quote characters, as per the question, observe the error message:
$ for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done
sox FAIL formats: can't open input file `“90.wav”': No such file or directory
Note the file name in the error message is shown with two-sets of quotes around the file name. This is what you saw as per the error message that in the question. The outer single-quotes are supplied by sox. The inner double-quotes are the funny quote characters provided on the command line. Because they are non-standard characters, the shell left them in place and passed them to the sox command.
While the file 90.wav exists, no file by the name of “90.wav” exists. Hence, the error.
Conclusion
Stick to standard ASCII characters for shell commands.
This issue can easily happen if the shell commands are typed in using a fancy word-processing editor that substitutes in typographically-pretty but non-standard characters. As tripleee points out, it can also happen when copying-and-pasting from the websites with inappropriate typographical styling.

midi to ogg - pipeline distortion

I am trying to convert midi files to ogg or mp3. Eventually this will happen on a linux webserver but currently I am using a Windows 7 machine. I am using timidity to convert the midi to wav and then either sox or ffmpeg to convert the wav to ogg/mp3.
When I use an intermediate file the process works fine (in the first line below timidity creates file.wav)
timidity.exe file.mid -Ow
sox.exe file.wav file.ogg
However, when I try to pipe the timidity output into sox (as below), the resulting file ogg is horribly distorted
timidity.exe file.mid -Ow -o - | sox.exe -t wav - file.ogg
and I get a warning
sox.exe WARN wav: Premature EOF on .wav input file
I also get the same distortion problem when I replace sox with ffmpeg (and the appropriate command line options), or when I replace ogg with mp3 as the output format.
So what am I doing wrong?
Thanks,
Chris
Regarding the warning itself, you're doing nothing wrong. You may also see a warning from timidity that reads something like
Warning: -: Illegal seek: Can't make valid header
What's happening there is explained in the timidity manual page:
If output is directed to a non-seekable file, or if TiMidity++ is interrupted before closing the file, the file header will contain 0xffffffff in the RIFF and data block length fields.
Note that RIFF is the encoding format commonly called by its file extension, .wav. When timidity writes a RIFF file, it doesn't know how long the file will be, so it writes some placeholder junk in the header and moves on to writing the data. When it finishes with the data, it knows how long the file is, so it goes back to the beginning of the file and writes over that junk in the header. When you write to a pipe, it has no way to go back and rewrite anything: the downstream program has to handle the placeholder junk. Also from the timidity manual page:
The popular sound conversion utility sox is able to read such malformed files, so you can pipe data directly to sox for on-the-fly conversion to other formats.
Thus, the message you mentioned. Sox is informing you that the chef prepared the file wrong BUT SOX IS HAPPY TO EAT IT ANYWAY BECAUSE SOX IS NOT PICKY. Sox is apparently passive-aggressive. Who knew?
You can ignore those warning messages, because now they are telling you something you already know. Or, you can use a raw format and explicitly tell timidity and sox how to play well with one another:
timidity file.midi -Or1Ssl -s44.1 -o- | sox -t raw -b 16 -e signed -r 44.1k -c 2 - file.ogg
As for the distortion, that may be caused in part by quirks in the audio libraries on the Windows system. I note that the pipeline in the question, sans .exe extensions, produces output with no notable distortion on a linux system. Using a well-defined raw format in the pipeline may also help with that issue.
Note that for Ogg output, you can now get that directly from timidity:
timidity file.midi -o file.ogg -Ov

Mix audio files with an offset(at particular points) using SOX

I have two audio files one is 10 secs long and other is 17 secs long, I want to mix the files together so that the 17 sec file starts playing from the start, while the 10 sec file will start after 7 seconds into the 17seconds file.
How can I do this?
I followed this link, I also tried other commands mentioned in Sox FAQ, question number 7, but I am unable to mix two files by providing an offset, I also tried the command in command line and the error is same.
The error which I see is
option ` ' not recognized
and the command I used is
sox -m drums.wav "|sox beats.wav -p pad 1.5" out.wav
Edit: It seems to me that the pipe operator "|" is broken, how do I fix this?
My problem is exactly the same as mentioned in this forum
I think there's an issue with ".
Try
sox -m drums.wav '|sox beats.wav -p pad 1.5' out.wav

Resources