Slightly improved (and apparently broken?) PRS encoding

Originally committed to SVN as r263.
This commit is contained in:
Rodrigo Braz Monteiro 2006-03-31 02:06:50 +00:00
parent 7b7b17d42b
commit 2ffcf9d1cc
2 changed files with 63 additions and 32 deletions

View File

@ -101,50 +101,80 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
AssDialogue *diag = NULL; AssDialogue *diag = NULL;
PClip clip1 = script1.AsClip(); PClip clip1 = script1.AsClip();
PClip clip2 = script2.AsClip(); PClip clip2 = script2.AsClip();
wxArrayInt frames;
int id = 0; int id = 0;
for (entryIter cur=ass->Line.begin();cur!=ass->Line.end();cur++) { for (entryIter cur=ass->Line.begin();cur!=ass->Line.end();cur++) {
diag = AssEntry::GetAsDialogue(*cur); diag = AssEntry::GetAsDialogue(*cur);
// Dialogue found // Dialogue found
if (diag) { if (diag) {
// Read its image // Parse tags
int framen = VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true); diag->ParseASSTags();
PVideoFrame frame1 = clip1->GetFrame(framen,env1);
PVideoFrame frame2 = clip2->GetFrame(framen,env2);
// Convert to PNG // Check if there is any animation tag
int x=0,y=0; bool hasAnimation = false;
wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch(),&x,&y); int blocks = diag->Blocks.size();
if (!bmp.Ok()) continue; AssDialogueBlockOverride *block;
wxMemoryOutputStream stream; for (int i=0;i<blocks;i++) {
bmp.SaveFile(stream,wxBITMAP_TYPE_PNG); block = AssDialogueBlock::GetAsOverride(diag->Blocks[i]);
bmp.SaveFile(filename + wxString::Format(_T("%i.png"),id),wxBITMAP_TYPE_PNG); if (block) {
hasAnimation = true;
}
}
// Create PRSImage // If it has animation, include all frames, otherwise, just the first
PRSImage *img = new PRSImage; if (hasAnimation) {
img->id = id; int start = VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true);
img->dataLen = stream.GetSize(); int end = VFR_Output.GetFrameAtTime(diag->End.GetMS(),false);
img->data = new char[img->dataLen]; for (int i=start;i<=end;i++) frames.Add(i);
img->imageType = PNG_IMG; }
stream.CopyTo(img->data,img->dataLen); else frames.Add(VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true));
// Create PRSDisplay // Clean up
PRSDisplay *display = new PRSDisplay; diag->ClearBlocks();
display->start = diag->Start.GetMS();
display->end = diag->End.GetMS();
display->id = id;
display->x = x;
display->y = y;
display->alpha = 255;
display->blend = 0;
// Insert into list
file.AddEntry(img);
file.AddEntry(display);
id++;
} }
} }
// Render all frames that were detected to contain subtitles
int totalFrames = frames.Count();
for (int i=0;i<totalFrames;i++) {
// Read its image
int framen = frames[i];
PVideoFrame frame1 = clip1->GetFrame(framen,env1);
PVideoFrame frame2 = clip2->GetFrame(framen,env2);
// Convert to PNG
int x=0,y=0;
wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch(),&x,&y);
if (!bmp.Ok()) continue;
wxMemoryOutputStream stream;
bmp.SaveFile(stream,wxBITMAP_TYPE_PNG);
bmp.SaveFile(filename + wxString::Format(_T("%i.png"),id),wxBITMAP_TYPE_PNG);
// Create PRSImage
PRSImage *img = new PRSImage;
img->id = id;
img->dataLen = stream.GetSize();
img->data = new char[img->dataLen];
img->imageType = PNG_IMG;
stream.CopyTo(img->data,img->dataLen);
// Create PRSDisplay
PRSDisplay *display = new PRSDisplay;
display->start = diag->Start.GetMS();
display->end = diag->End.GetMS();
display->id = id;
display->x = x;
display->y = y;
display->alpha = 255;
display->blend = 0;
// Insert into list
file.AddEntry(img);
file.AddEntry(display);
id++;
}
// Save file // Save file
file.Save((const char*)filename.mb_str(wxConvLocal)); file.Save((const char*)filename.mb_str(wxConvLocal));
#endif #endif

View File

@ -56,6 +56,7 @@ TipOfTheDay::TipOfTheDay (size_t currentTip): wxTipProvider(currentTip) {
tips.push_back(_("The fonts collector is one of the most useful features, which resumes the boring task of hunting down fonts into a matter of a few clicks.")); tips.push_back(_("The fonts collector is one of the most useful features, which resumes the boring task of hunting down fonts into a matter of a few clicks."));
tips.push_back(_("When you are done with your subtitles and ready to distribute them, remember: say no to MP4, OGM or AVI. Matroska is your friend.")); tips.push_back(_("When you are done with your subtitles and ready to distribute them, remember: say no to MP4, OGM or AVI. Matroska is your friend."));
tips.push_back(_("Much like anything loaded via DirectShow, certain files may have a strange structure (such as h.264 into AVI or XviD will null frames) which may cause unreliable seeking (that is, video frames might be off by one frame). This is not an Aegisub bug - you may consider reencoding those videos before working with them.")); tips.push_back(_("Much like anything loaded via DirectShow, certain files may have a strange structure (such as h.264 into AVI or XviD will null frames) which may cause unreliable seeking (that is, video frames might be off by one frame). This is not an Aegisub bug - you may consider reencoding those videos before working with them."));
tips.push_back(_("If anything goes wrong, blame movax."));
//tips.push_back(_("")); //tips.push_back(_(""));
} }