mp4cut.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <string>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cctype>
  5. void replace_colon(char* str)
  6. {
  7. while (*str) {
  8. if (*str == ':')
  9. *str = '-';
  10. str++;
  11. }
  12. }
  13. int main(int argc, char* argv[])
  14. {
  15. if (4 != argc) {
  16. puts("Usage: mp4cut.exe sample.mp4 00:08 01:18 ");
  17. return -1;
  18. }
  19. /*******
  20. FFMPEG 按时间截取视频
  21. ffmpeg -i ./plutopr.mp4 \
  22. -vcodec copy -acodec copy -ss 00:18:45 -to 00:19:36 \
  23. ./cutout1.mp4 -y
  24. *******/
  25. char cmdline[4096];
  26. sprintf(cmdline, "ffmpeg -i \"%s\" -vcodec copy -acodec copy -ss %s -to %s -y \"%s\" ",
  27. argv[1], argv[2], argv[3], argv[1]);
  28. char newfile[512]; // 时间戳文件名后缀
  29. sprintf(newfile, ".Cut_%s_%s.mp4\" ", argv[2], argv[3]);
  30. replace_colon(newfile);
  31. char* pch = strrchr(cmdline, '.');
  32. FILE* pFile;
  33. pFile = fopen(argv[1], "r");
  34. if (pch != NULL) {
  35. strcpy(pch, newfile);
  36. if (pFile != NULL) {
  37. // puts(cmdline);
  38. system(cmdline);
  39. }
  40. }
  41. }