![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Multimedia & Video Have multimedia question? ATI, Nvidia, Sound cards. Just ask here. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Just Give Me the Beans!
![]() Join Date: Apr 2005
Location: Toulouse,France
Beans: 81
Ubuntu 9.04 Jaunty Jackalope
|
[SOLVED] Convert mp3 to avi
Hi,
I need to convert a mp3 to avi because my Upnp player (freebox-tv) does not read mp3 but supports well xvid videos. I thus will transcode my music as blank videos. With ffmpeg, the conversion is easy : Code:
ffmpeg -i input.mp3 -vn -acodec copy -f avi output.avi I made a small blank video (attached as txt), 1 black frame. With mencoder, I managed to have both video and audio : Code:
mencoder black.avi -o output.avi -ovc xvid -oac copy -audiofile input.mp3 How can I specify to loop over the blank video accordingly to audio stream length ? Thank you guyz for any ideas! Last edited by cudjoe; August 21st, 2009 at 04:06 AM.. Reason: solved |
|
|
|
|
|
#2 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,746
|
Re: Convert mp3 to avi
Create blank black image (convert is part of the imagemagick package):
Code:
convert -size 320x240 xc:black black.png Code:
convert -size 320x240 xc:black -fill white -draw "gravity Center text 0,0 'The Pogues'" black.png Code:
ffmpeg -loop_input -i black.png -i fairytale_of_new_york.mp3 -shortest -acodec copy output.avi HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoding in FFmpeg Last edited by FakeOutdoorsman; 2 Weeks Ago at 02:13 AM.. Reason: now use -shortest instead of getting duration and using -t |
|
|
|
|
|
#3 |
|
Skinny Soy Caramel Ubuntu
![]() Join Date: Aug 2007
Beans: 684
|
Re: Convert mp3 to avi
save this python script, name it script.py (or whatever you want)
Code:
import os, sys
fps = 30
if len(sys.argv) != 4:
print "Usage: makevid.py imagefile audiofile seconds"
sys.exit(1)
secs = int(sys.argv[3])
if secs < 0:
print "Please pass a positive amount of seconds"
sys.exit(1)
secs = 1 / float(secs)
filesexist = True
for each_file in sys.argv[1:2]:
if not os.path.exists(each_file):
print "%s doesn't exist" % each_file
filesexist = False
if not filesexist: sys.exit(1)
mencoder_cmd = ('mencoder "mf://%s" -mf fps=%f -vf harddup -ovc lavc'\
' -lavcopts vbitrate=100 -audiofile "%s" -oac copy -ofps %d'\
' -o output.avi') % (sys.argv[1], secs, sys.argv[2], fps)
print "Starting mencoder"
os.system(mencoder_cmd)
print "Video is complete, output written to output.avi"
Code:
python script.py [imagefile] [audiofile] [length in seconds] |
|
|
|
|
|
#4 |
|
Just Give Me the Beans!
![]() Join Date: Apr 2005
Location: Toulouse,France
Beans: 81
Ubuntu 9.04 Jaunty Jackalope
|
Thanks Locutus_of_Borg.
With the information of Fakeoutdoorsman, I made this small shell script (ffmpeg instead of mencoder) : Code:
input=$1 output=$2 background=/tmp/bng-black.jpg convert -size 320x240 xc:black $background duration=`ffmpeg -i $input 2>&1 | grep Duration | cut -f1 -d, | cut -f2,3,4,5 -d:` ffmpeg -loop_input -i $background -i $input -vcodec mpeg4 -acodec copy -t $duration $output |
|
|
|
|
|
#5 |
|
Just Give Me the Beans!
![]() Join Date: Jun 2007
Beans: 71
|
Re: Convert mp3 to avi
Thanks! I just used your shell script, replacing the background.jpg with an image I wanted to use, and converted an mp3 file into an avi! It was EASY with the script. thank you VERY much!
|
|
|
|
|
|
#6 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,746
|
Re: Convert mp3 to avi
I updated my first post to now use the -shortest option which will automatically finish encoding the video when the music ends. Much easier than getting the audio duration and then using that number to determine the encoding length. So now cudjoe's script can look like this:
Code:
#!/bin/bash # Usage: mp32avi.sh input.mp3 output.avi input=$1 output=$2 background=/tmp/bng-black.jpg convert -size 320x240 xc:black $background ffmpeg -loop_input -i $background -i $input -vcodec mpeg4 -acodec copy -shortest -qscale 5 $output Update: I also added -qscale 5 to cudjoe's script so the output quality should be better for more complicated backgrounds other than just a solid color. Last edited by FakeOutdoorsman; 2 Weeks Ago at 02:34 AM.. |
|
|
|
|
|
#7 |
|
Dark Roasted Ubuntu
![]() Join Date: Sep 2006
Beans: 1,102
Kubuntu 9.10 Karmic Koala
|
transcoding or wrapping
@ FakeOutdoorsman : That looks useful. Sorry for a dumb question: Does that method wrap the MP3s as AVI as is, or does it transcode them and reduce the sound quality further?
|
|
|
|
|
|
#8 | |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,746
|
Re: transcoding or wrapping
Quote:
There is a -vcodec copy option as well which is quite useful. Both of these options are good for trimming a video without re-encoding or adding/removing audio/video to a file without any need to re-encode. |
|
|
|
|
|
|
#9 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,746
|
Re: transcoding or wrapping
Here's a new version:
Code:
#!/bin/bash # Requires: imagemagick, ffmpeg # Usage: ./mp32avi.sh input.mp3 output.avi background=/tmp/$RANDOM.gif title=`ffmpeg -i $1 2>&1 | grep TIT2 | cut -d: -f 2` convert -size 320x240 xc:black -fill white -draw "gravity Center text 0,0 '$title'" $background ffmpeg -loop_input -r ntsc -i $background -i $1 -acodec copy -shortest -qscale 5 $2 rm $background exit Last edited by FakeOutdoorsman; 2 Weeks Ago at 04:32 PM.. |
|
|
|
|
|
#10 |
|
Just Give Me the Beans!
![]() Join Date: Jun 2007
Beans: 71
|
Re: Convert mp3 to avi
this scrip creates the avi just fine, but the background is plain black. For some reason its not grabbing the mp3 title info.
I made certain the title was populated in both v1 and v2 tags. Am I missing some component? thanks again! |
|
|
|
| Bookmarks |
| Tags |
| avi, black video, conversion, ffmpeg, mp3 |
| Thread Tools | |
| Display Modes | |
|
|