Trouble getting footage path after effects sdk

删除回忆录丶 提交于 2019-12-13 16:44:46

问题


Having trouble with the after effects sdk. Basically I'm looping through all of the footage project items and trying to get the footage path from them. Here's the code I have inside of the loop.

AEGP_ItemType itemType = NULL;
ERR(suites.ItemSuite6()->AEGP_GetNextProjItem(projH, itemH, &itemH));
if (itemH == NULL) {
  break;
}
ERR(suites.ItemSuite6()->AEGP_GetItemType(itemH, &itemType));
if (itemType == AEGP_ItemType_FOOTAGE) {
          numFootage++;
          AEGP_FootageH footageH;
          ERR(suites.FootageSuite5()->AEGP_GetMainFootageFromItem(itemH, &footageH));
          A_char newItemName[AEGP_MAX_ITEM_NAME_SIZE] = {""};
          wchar_t footagePath[AEGP_MAX_PATH_SIZE];
          ERR(suites.ItemSuite6()->AEGP_GetItemName(itemH, newItemName));
          AEGP_MemHandle pathH = NULL;
          ERR(suites.FootageSuite5()->AEGP_GetFootagePath(footageH, 0, AEGP_FOOTAGE_MAIN_FILE_INDEX, &pathH));
          ERR(suites.MemorySuite1()->AEGP_LockMemHandle(pathH, reinterpret_cast<void**>(&footagePath)));
          std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
          const std::string utf8_string = converter.to_bytes(footagePath);
          std::ofstream tempFile;
          tempFile.open ("C:\\temp\\log1.txt");
          tempFile << utf8_string;
          tempFile.close();
          ERR(suites.MemorySuite1()->AEGP_UnlockMemHandle(pathH));
          ERR(suites.MemorySuite1()->AEGP_FreeMemHandle(pathH));
}

I'm getting the footagePath

I then convert the UTF-16 (wchar_t) pointer to a UTF-8 string

Then I write that UTF-8 string to a temp file and it always outputs the following.

펐㛻

Can I please have some guidance on this? Thanks!


回答1:


You've already had the data as smarter std::wstring, why did you convert it to byte array and then force it as simple std::string? In general, you should avoid converting strings via byte arrays. My knowledge on C++ STDLIB is a few years off now, but the problem may be in that the std::string class may simply still not have any UTF8 support.

Do you really need to store it as utf8? If it is just for logging, try using ofwstream (the wide one), remove the conversion and the 'string' completely, and just write the 'wstring' directly to the stream instead.

Also, it is completely possible that everything went correctly, and it is just your FILE VIEWER that goes rabid. Examine your log file with hexeditor and check if the beginning of the file contains the Unicode format markers like 0xFFFE etc:

  • if it has some, and you wrote data in not-identical encoding as the markers indicate, then that's the problem
  • if it has none, then try adding correct markers. Maybe your file-viewer simply did not notice it is unicode-of-that-type and misread the file. Unicode markers help the readers to decode data properly.



回答2:


I was able to figure out the answer. http://forums.adobe.com/message/5112560#5112560

This is what was wrong. It was because the executing code was in a loop and I wasn't allocating strings with the new operator.

This was the line that needed a new on it. wchar_t footagePath[AEGP_MAX_PATH_SIZE];

Another piece of information that would have been useful to know is that not ALL footage items have paths.

If the don't have a path it will return empty string. This is the code I ended up with.

if (itemType == AEGP_ItemType_FOOTAGE) {
          A_char* newItemName = new A_char[AEGP_MAX_ITEM_NAME_SIZE];
          ERR(suites.ItemSuite6()->AEGP_GetItemName(newItemH, newItemName));
          AEGP_MemHandle nameH = NULL;
          AEGP_FootageH footageH = NULL;
          char* footagePathStr = new char[AEGP_MAX_PATH_SIZE];
          ERR(suites.FootageSuite5()->AEGP_GetMainFootageFromItem(newItemH, &footageH));
          if (footageH) {
                            suites.FootageSuite5()->AEGP_ GetFootagePath(footageH, 0, AEGP_FOOTAGE_MAIN_FILE_INDEX, &nameH);
                            if(nameH) {
                                       tries++;
                                       AEGP_MemSize size = 0;
                                       A_UTF16Char *nameP = NULL;
                                       suites.MemorySuite1()->AEGP_GetMemHandleSize(nameH, &size);
                                       suites.MemorySuite1()->AEGP_LockMemHandle(nameH, (void **)&nameP);
                                       std::wstring test = L"HELLO";
                                       std::string output;
                                       int len = WideCharToMultiByte(CP_OEMCP, 0, (LPCWSTR)nameP, -1, NULL, 0, NULL, NULL);
                                       if (len > 1) {
                                                  footagePathStr = new char[len];
                                                  int len2 = WideCharToMultiByte(CP_OEMCP, 0, (LPCWSTR)nameP, -1, footagePathStr, len, NULL, NULL);
                                                  ERR(suites.MemorySuite1()->AEGP_UnlockMemHandle(nameH));
                                                  suites.MemorySuite1()->AEGP_FreeMemHandle(nameH);
                                       }
                            }
          }
}


来源:https://stackoverflow.com/questions/15078661/trouble-getting-footage-path-after-effects-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!