You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Added a DisplayWaveform method on a frame, to help debug audio issues. It uses ImageMagick to draw each channel and all samples in each channel.
This commit is contained in:
@@ -70,6 +70,9 @@ namespace openshot
|
||||
/// Display the frame image to the screen (primarily used for debugging reasons)
|
||||
void Display();
|
||||
|
||||
/// Display the wave form
|
||||
void DisplayWaveform(bool resize);
|
||||
|
||||
/// Get pixel data (as packets)
|
||||
const Magick::PixelPacket* GetPixels();
|
||||
|
||||
|
||||
@@ -429,6 +429,10 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int
|
||||
packet.size -= sample_count;
|
||||
}
|
||||
|
||||
|
||||
cout << "Added Audio Samples: " << packet_samples << endl;
|
||||
|
||||
|
||||
for (int channel_filter = 0; channel_filter < info.channels; channel_filter++)
|
||||
{
|
||||
// Array of floats (to hold samples for each channel)
|
||||
|
||||
@@ -121,6 +121,77 @@ void Frame::Display()
|
||||
image->display();
|
||||
}
|
||||
|
||||
// Display the wave form
|
||||
void Frame::DisplayWaveform(bool resize)
|
||||
{
|
||||
// Create black image
|
||||
int width = audio->getNumSamples();
|
||||
int height = 200 * audio->getNumChannels();
|
||||
int height_padding = 20 * (audio->getNumChannels() - 1);
|
||||
int total_height = height + height_padding;
|
||||
Magick::Image wave_image(Magick::Geometry(width, total_height), Magick::Color("#000000"));
|
||||
|
||||
// Init a list of lines
|
||||
list<Magick::Drawable> lines;
|
||||
lines.push_back(Magick::DrawableFillColor("#0070ff"));
|
||||
lines.push_back(Magick::DrawablePointSize(16));
|
||||
|
||||
// Loop through each audio channel
|
||||
int Y = 100;
|
||||
for (int channel = 0; channel < audio->getNumChannels(); channel++)
|
||||
{
|
||||
// Get audio for this channel
|
||||
float *samples = audio->getSampleData(channel);
|
||||
|
||||
for (int sample = 0; sample < audio->getNumSamples(); sample++)
|
||||
{
|
||||
// Sample value (scaled to -100 to 100)
|
||||
float value = samples[sample] * 100;
|
||||
|
||||
if (value > 100 || value < -100)
|
||||
cout << "TOO BIG!!! " << value << endl;
|
||||
|
||||
// Append a line segment for each sample
|
||||
if (value != 0.0)
|
||||
{
|
||||
// LINE
|
||||
lines.push_back(Magick::DrawableStrokeColor("#0070ff"));
|
||||
lines.push_back(Magick::DrawableStrokeWidth(1));
|
||||
lines.push_back(Magick::DrawableLine(sample,Y, sample,Y-value)); // sample=X coordinate, Y=100 is the middle
|
||||
}
|
||||
else
|
||||
{
|
||||
// DOT
|
||||
lines.push_back(Magick::DrawableFillColor("#0070ff"));
|
||||
lines.push_back(Magick::DrawableStrokeWidth(1));
|
||||
lines.push_back(Magick::DrawablePoint(sample,Y));
|
||||
}
|
||||
}
|
||||
|
||||
// Add Channel Label
|
||||
stringstream label;
|
||||
label << "Channel " << channel;
|
||||
lines.push_back(Magick::DrawableStrokeColor("#ffffff"));
|
||||
lines.push_back(Magick::DrawableFillColor("#ffffff"));
|
||||
lines.push_back(Magick::DrawableStrokeWidth(0.1));
|
||||
lines.push_back(Magick::DrawableText(5, Y - 5, label.str()));
|
||||
|
||||
// Increment Y
|
||||
Y += (200 + height_padding);
|
||||
}
|
||||
|
||||
// Draw the waveform
|
||||
wave_image.draw(lines);
|
||||
|
||||
// Resize Image (if requested)
|
||||
if (resize)
|
||||
// Resize to 60%
|
||||
wave_image.resize(Magick::Geometry(width * 0.6, total_height * 0.6));
|
||||
|
||||
// Display Image
|
||||
wave_image.display();
|
||||
}
|
||||
|
||||
// Get pixel data (as packets)
|
||||
const Magick::PixelPacket* Frame::GetPixels()
|
||||
{
|
||||
|
||||
15
src/Main.cpp
15
src/Main.cpp
@@ -16,9 +16,9 @@ int main()
|
||||
|
||||
// openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/test.mp4");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/test1.mp4");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Videos/Version 1.1a.mp4");
|
||||
openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Videos/OpenShot_Now_In_3d.mp4");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4");
|
||||
openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/test.wav");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Music/Army of Lovers/Crucified/Army of Lovers - Crucified [Single Version].mp3");
|
||||
// openshot::FFmpegReader r("/home/jonathan/Documents/OpenShot Art/bannertemplate.png");
|
||||
@@ -28,8 +28,13 @@ int main()
|
||||
// Display debug info
|
||||
r.DisplayInfo();
|
||||
|
||||
r.GetFrame(1).Display();
|
||||
r.GetFrame(300).Display();
|
||||
r.GetFrame(400).DisplayWaveform(false);
|
||||
r.GetFrame(401).DisplayWaveform(false);
|
||||
r.GetFrame(402).DisplayWaveform(false);
|
||||
r.GetFrame(403).DisplayWaveform(false);
|
||||
r.GetFrame(404).DisplayWaveform(false);
|
||||
//r.GetFrame(301).DisplayWaveform();
|
||||
//r.GetFrame(302).DisplayWaveform();
|
||||
|
||||
//Player g;
|
||||
//g.SetReader(&r);
|
||||
|
||||
Reference in New Issue
Block a user