Jump to content

pic over audio


iamtheky
 Share

Recommended Posts

many sites will not permit the uploading of a video container that only contains an audio stream. And one in particular has all of their customizable music players broken. This simple script loops a single jpg as the video stream over the audio of your choosing and outputs an .avi.

*requires ffmpeg

$pic = "picture.jpg"
$song = "song.mp3"
$result = "result.avi"
 
runwait ("ffmpeg -loop_input -f image2 -i " & $pic & " -r 1 -vcodec flv -i " & $song & " -acodec copy -qscale 2 -g 5 -cmp 3 -subcmp 3 -mbd 2 " & $result & " -shortest", @ScriptDir)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • 1 month later...

hey this is a good idea, I sometimes send sound files (mp3) to my sister as a change from a typed email message - just me talking about stuff but I can now use this to send a sort of video file with my picture!! might have been good if you could have used two pictures and had them change from one to the other every few minutes just to make it less boring?!

hmm now I've tried it - it doesnt work for me

I put a jpg and a mp3 file in the same dir as the script and made sure they were named correctly to go with the script

I also made sure ffmpeg.exe was in the same dir

ran the script but nothing happened.

Edited by Hellooopsforgotsendcommand
Link to comment
Share on other sites

  • 4 years later...

Im going to rez this just cause I had to use it again and it works fine save for some deprecated args like -loop_input.  You can remove that and the pic only appears at 0:00, leaving a black screen and audio playing the remainder, which is ideal if you want to keep file size down, and is what i did today with the latest version.  It still cries about some of the others but processes them just fine.

runwait ("ffmpeg -f image2 -i " & $pic & " -r 1 -vcodec flv -i " & $song & " -acodec copy -qscale 2 -g 5 -cmp 3 -subcmp 3 -mbd 2 " & $result & " -shortest", @ScriptDir)

 

just upped ForAmber(Full) AVI built with the above script https://t.co/nu9OYOkgN4

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • 3 months later...

had to adjust fire on the command again.  The last version only inserts the picture into the first frame, this one will set the picture in every frame, for the duration of the song.

$pic = "picture.jpg"
$song = "song.mp3"
$result = "result.avi"

runwait ("cmd /k ffmpeg -f image2 -loop 1 -i " & $pic & " -vcodec flv -i " & $song & " -acodec copy -qscale 2 -g 5 -cmp 3 -subcmp 3 -mbd 2 -shortest " & $result, @ScriptDir)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • 2 months later...
On 12/14/2016 at 3:54 PM, iamtheky said:

had to adjust fire on the command again.  The last version only inserts the picture into the first frame, this one will set the picture in every frame, for the duration of the song.

$pic = "picture.jpg"
$song = "song.mp3"
$result = "result.avi"

runwait ("cmd /k ffmpeg -f image2 -loop 1 -i " & $pic & " -vcodec flv -i " & $song & " -acodec copy -qscale 2 -g 5 -cmp 3 -subcmp 3 -mbd 2 -shortest " & $result, @ScriptDir)

 

 

So, in order to maintain tags, I had to change the result filetype from avi to mp4.  Unfortunately, that caused the video to be blank ... sound only.

How can we generate a mp4 using map_metadata to keep audio tags and still be playable?  Further, is there a way to reduce the file size?

Link to comment
Share on other sites

hm never tried, I will play with that this afternoon.  And "I am the K-y", I would describe it further but discussions of that nature are a slippery slope, and I make them slippier.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Ah ;) Kentucky!

I actually figured it out ... the solution I mean ... myself:

Now the problem with the pic was actually the pic itself.  Perhaps pics under a certain size work better with avi instead of mp4.  Whatever the case, I chose a larger pic and it worked for both mp4 and avi.  mp4 is preferred so I can see that the metadata mapped using Tag&Rename.

Now, as far as size, I pretty much removed all of the options in your previous example and ... voila!

$cmd = '"' & $ffmpegExe & '" -f image2 -loop 1 -i "' & $pic & '" -i "' & $aud & '" -shortest -map_metadata 1 "' & $vid & '"'

This yielded a mp4 only a fraction larger than the mp3 source, roughly 1mb per minute.

Link to comment
Share on other sites

nice, I will probably use your command now.  I really only used it because fb makes me upload a video if I want to upload any tracks.  like this:

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

 

A little more research has shown that ffmpeg will construct videos even if the image in unusable.  There are certain warnings generated ("deprecated pixel format", "width not divisible by 2", etc...).  So, just because it produces a video, doesn't mean it will be viewable.

 

While I could not find a way (yet) to force ffmpeg to abort on warnings, I did find some useful options (pix_fmt, vf scale) to force any of my bad images to work properly. Here is my current command:

$cmd = '"' & $ffmpegExe & '" -f image2 -loop 1 -i "' & $pic & '" -i "' & $aud & '" -shortest -map_metadata 1 -pix_fmt yuv420p -vf scale=800:400 "' & $vid & '"'

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...