📄 mp4syncfiles.cpp
字号:
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is MPEG4IP. * * The Initial Developer of the Original Code is Cisco Systems Inc. * Portions created by Cisco Systems Inc. are * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. * * Contributor(s): * Bill May wmay@cisco.com */#include "mp4.h"#include "mpeg4ip_getopt.h"static bool compare_duration(char *toname, MP4FileHandle to, char *fromname, MP4FileHandle from){ MP4Duration todur, fromdur; todur = MP4GetTrackDuration(to, 1); fromdur = MP4GetTrackDuration(from, 1); if (todur == fromdur) return true; printf("%s durations do not match "U64" "U64"\n", fromname, fromdur, todur); return false;}static void sync_duration (char *toFileName, MP4FileHandle durfile){ MP4Duration todur; MP4FileHandle tofile; char newname[PATH_MAX]; todur = MP4GetTrackDuration(durfile, 1) + 1024; tmpnam(newname); MP4FileHandle fromfile; uint32_t numTracks; fromfile = MP4Modify(toFileName); if (fromfile == MP4_INVALID_FILE_HANDLE) { printf("Can't open %s\n", toFileName); return; } tofile = MP4Create(newname); if (tofile == MP4_INVALID_FILE_HANDLE) { printf("Can't create %s\n", newname); return; } numTracks = MP4GetNumberOfTracks(fromfile); for (uint32_t ix = 0; ix < numTracks; ix++) { MP4TrackId trackId = MP4FindTrackId(fromfile, ix); MP4EditId eid = MP4AddTrackEdit(fromfile, trackId, 1, 0, todur); if (eid == MP4_INVALID_EDIT_ID) { printf("invalid edit\n"); } else { MP4CopyTrack(fromfile, trackId, tofile, true); MP4DeleteTrackEdit(fromfile, trackId, eid); } } MP4Close(tofile); MP4Close(fromfile); unlink(toFileName); rename(newname, toFileName);}static bool compare_meta(char *toname, MP4FileHandle to, char *fromname, MP4FileHandle from){ char *tovalue, *fromvalue; uint16_t tonum, tonum2, fromnum, fromnum2; uint32_t toverb, fromverb; toverb = MP4GetVerbosity(to); MP4SetVerbosity(to, 0); fromverb = MP4GetVerbosity(from); MP4SetVerbosity(from, 0); tovalue = fromvalue = NULL; MP4GetMetadataName(to, &tovalue); MP4GetMetadataName(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { printf("%s name \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataArtist(to, &tovalue); MP4GetMetadataArtist(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { printf("%s artist \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataWriter(to, &tovalue); MP4GetMetadataWriter(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { if (tovalue != NULL || fromvalue != NULL) { printf("%s writer \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataYear(to, &tovalue); MP4GetMetadataYear(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { printf("%s year \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataAlbum(to, &tovalue); MP4GetMetadataAlbum(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { printf("%s album \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataAlbumArtist(to, &tovalue); MP4GetMetadataAlbumArtist(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { printf("%s album artist \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataGenre(to, &tovalue); MP4GetMetadataGenre(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { printf("%s genre \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataGrouping(to, &tovalue); MP4GetMetadataGrouping(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { if (tovalue != NULL || fromvalue != NULL) { printf("%s grouping \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataComment(to, &tovalue); MP4GetMetadataComment(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { if (tovalue != NULL || fromvalue != NULL) { printf("%s comment \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataAlbumArtist(to, &tovalue); MP4GetMetadataAlbumArtist(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { if (tovalue != NULL || fromvalue != NULL) { printf("%s comment \"%s\" \"%s\"\n", fromname, fromvalue, tovalue); CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); return false; } } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataTempo(to, &tonum); MP4GetMetadataTempo(from, &fromnum); if (tonum != fromnum) { printf("%s tempo %u %u \n", fromname, fromnum, tonum); return false; } MP4GetMetadataTrack(to, &tonum, &tonum2); MP4GetMetadataTrack(from, &fromnum, &fromnum2); if (tonum != fromnum || tonum2 != fromnum2) { printf("%s track %u %u from %u %u\n", fromname, tonum, tonum2, fromnum, fromnum2); return false; } MP4GetMetadataDisk(to, &tonum, &tonum2); MP4GetMetadataDisk(from, &fromnum, &fromnum2); if (tonum != fromnum || tonum2 != fromnum2) { printf("%s disk %u %u from %u %u\n", fromname, tonum, tonum2, fromnum, fromnum2); return false; } uint32_t toart, fromart; toart = MP4GetMetadataCoverArtCount(to); fromart = MP4GetMetadataCoverArtCount(from); if (toart != fromart) { printf("%s art count %u %u\n", fromname, toart, fromart); return false; } MP4SetVerbosity(to, toverb); MP4SetVerbosity(from, fromverb); return true;}static void copy_meta(char *toname, MP4FileHandle to, char *fromname, MP4FileHandle from, bool force){ char *tovalue, *fromvalue; uint16_t tonum, tonum2, fromnum, fromnum2; uint32_t toverb, fromverb; toverb = MP4GetVerbosity(to); MP4SetVerbosity(to, 0); fromverb = MP4GetVerbosity(from); MP4SetVerbosity(from, 0); tovalue = fromvalue = NULL; MP4GetMetadataName(to, &tovalue); MP4GetMetadataName(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { if (tovalue != NULL) MP4DeleteMetadataName(to); if (fromvalue != NULL) MP4SetMetadataName(to, fromvalue); } CHECK_AND_FREE(tovalue); CHECK_AND_FREE(fromvalue); MP4GetMetadataArtist(to, &tovalue); MP4GetMetadataArtist(from, &fromvalue); if (tovalue == NULL || fromvalue == NULL || strcmp(tovalue, fromvalue) != 0) { if (tovalue != NULL) MP4DeleteMetadataArtist(to); if (fromvalue != NULL) MP4SetMetadataArtist(to, fromvalue); } CHECK_AND_FREE(tovalue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -