I am trying to merge two files (.mp3 & .mp4) to a single .mp4
The videos and audio are located in the same folder as my main.py, and aren't corrupted
Here is the code that seems to create the error:
if (haveAudio):
infile1 = ffmpeg.input(title+"_video.mp4")
infile2 = ffmpeg.input(title+"_audio.mp3")
merged = ffmpeg.concat(infile1, infile2, v=1, a=1)
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
I am getting an error on the last line:
Traceback (most recent call last):
File "C:\Users\...\projectName\main.py", line 67, in <module>
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
File "C:\Users\...\Python\Python39\lib\site-packages\ffmpeg\nodes.py", line 70, in __getitem__
raise TypeError("Expected string index (e.g. 'a'); got {!r}".format(index))
TypeError: Expected string index (e.g. 'a'); got 0
My guess would be that an argument is missing when calling ffmpeg.output() but based on the documentation it seems correct.
I learnt from this tutorial: https://github.com/JNYH/pytube/blob/master/pytube_sample_code.ipynb
I used below 2 ways and they both worked for me:
audio = ffmpeg.input('audio.mp3')
video = ffmpeg.input('video.mp4')
ffmpeg.output(audio, video, 'my_file.mp4').run()
or
ffmpeg.concat(video, audio, v=1, a=1).output('my_file.mp4').run(overwrite_output=True)
Related
Let me first start this off by stating that I am a complete beginner to coding and my attempts to fix this have been limited. I am trying to follow this Arduino controlled piano robot. It takes a textified midi file and uses python to translate it into 8-bit. The code is attached near the bottom of the link, I had some formatting issues when placing it here.
This link to the textified midi file used. before running the code I changed the input_file = open to text file path like so,
input_file = open("C:\\Users\\nby20\\Downloads\\megalovania.txt")
After running the code I get a text output file as expected however it is blank and I get a few errors:
Traceback (most recent call last):
File "C:\Users\nby20\Downloads\python_code_for_translation.py", line 184, in <module>
main()
File "C:\Users\nby20\Downloads\python_code_for_translation.py", line 23, in main
result[-1] = str(temp_time) + "," + set_bit_prev(on_off_finder(a), note_finder(a), -1)
File "C:\Users\nby20\Downloads\python_code_for_translation.py", line 178, in on_off_finder
end = in_string.index("ch=") - 1
ValueError: substring not found
Any suggestions on how to fix this would be greatly appreciated.
The Traceback is like debugging information you can use to trace which functions were called when the error was thrown. It seems the error occurred when it was executing this bit of conditional logic, lines 22-23, of the main function:
elif time_finder_comm(result[-1]) == temp_time:
result[-1] = str(temp_time) + "," + set_bit_prev(on_off_finder(a), note_finder(a), -1)
which called the on_off_finder function which just tries to figure out if the line says 'On' or 'Off'.
It seems the file reader only expects lines like this:
55248 Off ch=10 n=40 v=64
However, in the file you uploaded, there also lines like this:
55248 Meta TrkEnd
TrkEnd
The index function throws ValueError: substring not found if the substring passed in does not exist in the string, which in this case (line 178 below) is the string "ch":
end = in_string.index("ch=") - 1
Try removing those kind of lines and re-run the script? Find all lines with "Trk" and and remove them, or make 3 separate files because there seem to be 3 blocks of lines in 'megalovania.txt' that will trip up the script:
(starting at line 2469):
55248 Meta TrkEnd
TrkEnd
MTrk
...
(starting at line 4071):
58368 Meta TrkEnd
TrkEnd
MTrk
...
(starting at line 6431):
55296 Meta TrkEnd
TrkEnd
I have used pygame a lot, but never used sound before. I have checked and the files are there by the right name, and I have used the right pathway, but I just get this error message:
Traceback (most recent call last):
File "C:\Users\Rajive\AppData\Local\Programs\Python\Python3.4.3\D C W.py", line 11, in module
door_opening = pygame.mixer.Sound('C:\Users\Rajive\Downloads\door_opening.m4a')
pygame.error: Unable to open file 'C:\Users\Rajive\Downloads\door_opening.m4a'
import random, time, pygame
time = time.clock()
pygame.init()
diff = 1
door_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\door_opening.m4a')
door_closing = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\door_closing.m4a')
closet_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\closet_opening.m4a')
closet_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\closet_closing.m4a')
window_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\window_opening.m4a')
window_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\window_closing.m4a')
From pygame documentation:
The Sound can be loaded from an OGG audio file or from an uncompressed WAV.
Doesn't look like the .m4a codec is supported. Perhaps try converting your file first.
i'm working on a authentication system with raspberry pi with the Fingerprint Scanner - TTL (GT-511C3) and i have a function that create a template and returns as result the following :
I want to extract only th data part so i did like this : response 1['Data']
but when i print it i get this :
i added this as header of my file :
reload(sys)
sys.setdefaultencoding('utf8')
and i tried a couple of solutions i found in the forum but i couldn't find one that works with me.
my problem is when i try to compare the created template with the ones already in the database of the scanner with a function called IdentifyTemplate and takes as a parameter a template it gives me the following error :
Traceback (most recent call last):
File "finger.py", line 169, in
indetifyResponse = f.IdentifyTemplate(makeTemplateResponse)
File "/home/pi/Desktop/fingerpi/fingerpi/fingerpi.py", line 213, in
IdentifyTemplate
if self.sendData(template, 498):
File "/home/pi/Desktop/fingerpi/fingerpi/fingerpi.py", line 53, in sendData
packet = encode_data_packet(data, data_len, device_id = self.device_id)
File "/home/pi/Desktop/fingerpi/fingerpi/base.py", line 72, in
encode_data_packet
data # Data to be sent
struct.error: argument for 's' must be a string
i suspect that the problem is comming from that Data that i'm trying to print.
Any help is much appreciated. My Python version is 2.7.13
Edit: Trying to get these libraries to work in python 3.3 was clearly the wrong approach, and my problem now is entirely different so I'll just re-ask it in a new question.
I want to be able to edit ID3 tags of mp3 files with python commands, for example something like setAlbumName("folderPath\song.mp3", "albumname"). So far I've tried Mutagen, PyID3, pytagger, eyeD3, and they all seem to be outdated because the installation fails due to syntax errors. I tried to fix it in eyeD3, but I hit a dead end: http://i41.tinypic.com/o6zklv.png (second screenshot from after I had fixed all the prints and "except Error, e" and so on).
I tried the same with Mutagen, but I ran into a wall there as well when replacing "raise KeyError, key" with "raise KeyError as key" didn't work.
I didn't even know what to make of this one (pytagger): http://i41.tinypic.com/29fz7mh.png
It seems to suggest that there's something wrong with my python installation? Not getting into that.
So, would anyone like to point me to an ID3 package that works, or have a go at fixing an outdated one?
(Also, I tried both "python setup.py install" and "setup.py install" and it seemed to make no difference. I'm on windows 8.)
Edit: From the screenshot below, plus the source code (mutagen with python 2.7.5)
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.pprint()
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 5, in <module>
audio.pprint()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 138, in pprint
try: tags = self.tags.pprint()
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 190, in pprint
frames = list(map(Frame.pprint, self.values()))
TypeError: unbound method pprint() must be called with Frame instance as first a
rgument (got str instance instead)
_
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 7, in <module>
audio.save()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 132, in save
return self.tags.save(filename, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 370, in save
framedata = [self.__save_frame(frame) for (key, frame) in frames]
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 461, in __save_frame
framedata = frame._writeData()
AttributeError: 'str' object has no attribute '_writeData'
mutagen works great for me with Python 2.7.
examples:
https://code.google.com/p/mutagen/wiki/Tutorial
from mutagen.mp3 import MP3
audio = MP3("example.mp3")
audio["title"] = "An example"
audio.pprint()
audio.save()
p.s. please post code samples so people can help.. not links to screenshots.
p.p.s. it looks like you are trying to install Python2 libs into Python3.
Mutagen also has an EasyID3 tool, which handles simple tasks like changing the file's title:
from mutagen.easyid3 import EasyID3
f = EasyID3("file.mp3")
f["title"] = u"Some title"
f.save()
Works like a charm. But it has very restricted functionality.
See more examples at http://code.google.com/p/mutagen/wiki/Tutorial
I'm running python2.5 and trying to use the astLib library to analyse WCS information in astronomical images. I try and get the object instanciated with the following skeleton code:
from astLib import astWCS
w = astWCS.WCS('file.fits') # error here
where file.fits is a string pointing to a valid fits file.
I have tried using the alternate method of passing a pyfits header object and this fails also:
import pyfits
from astLib import astWCS
f = pyfits.open('file.fits')
header = f[0].header
f.close()
w = astWCS.WCS(header, mode='pyfits') # error here also
The error is this:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/astro/phrfbf/build/lib/python2.6/site-packages/astLib/astWCS.py", line 79, in __init__
self.updateFromHeader()
File "/home/astro/phrfbf/build/lib/python2.6/site-packages/astLib/astWCS.py", line 119, in updateFromHeader
self.WCSStructure=wcs.wcsinit(cardstring)
File "/home/astro/phrfbf/build/lib/python2.6/site-packages/PyWCSTools/wcs.py", line 70, in wcsinit
return _wcs.wcsinit(*args)
TypeError: in method 'wcsinit', argument 1 of type 'char *'
When I run in ipython, I get the full error here on the pastebin
I know the astWCS module is a wrapped version of WCStools but i'd prefer to use the Python module as the rest of my code is in Python
Can anyone help with this problem?
Just found out the updated version of this library has fixed the problem, thanks for everyone's help
Oh sorry, I should have seen. Looking at the pastebin in more detail, the only error I can think of is that, for some reason the header has unicode in it. It can't be converted to char *, and you get the error. I tried searching for something in the header, but everything looks okay. Can you do this and post the output in another pastebin?
import pyfits
f = pyfits.open('file.fits')
header = f[0].header
f.close()
for x, i in enumerate(header.iteritems()):
if len(str(i[1])) >= 70:
print x, str(i[1])
cardlist = header.ascardlist()
cardstring = ""
for card in cardlist:
cardstring = cardstring + str(card)
print repr(cardstring)
Or, if you can check the header of your fits file for "funny" characters, getting rid of them should solve the issue.