Changeset 2044 for branches/blt4/src
- Timestamp:
- Jan 18, 2011 7:07:10 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/src/objects/RpVideo.c
r1932 r2044 19 19 #include <string.h> 20 20 21 #include <libavcodec/avcodec.h> 22 #include <libavformat/avformat.h> 23 #include <libswscale/swscale.h> 21 #include "config.h" 22 23 #ifdef HAVE_FFMPEG_AVCODEC_H 24 # include <ffmpeg/avcodec.h> 25 #endif 26 27 #ifdef HAVE_LIBAVCODEC_AVCODEC_H 28 # include <libavcodec/avcodec.h> 29 #endif 30 31 #ifdef HAVE_FFMPEG_AVFORMAT_H 32 # include <ffmpeg/avformat.h> 33 #endif 34 35 #ifdef HAVE_LIBAVFORMAT_AVFORMAT_H 36 # include <libavformat/avformat.h> 37 #endif 38 39 #ifdef HAVE_FFMPEG_AVUTIL_H 40 # include <ffmpeg/avutil.h> 41 #endif 42 43 #ifdef HAVE_LIBAVUTIL_AVUTIL_H 44 # include <libavutil/avutil.h> 45 #endif 46 47 #ifdef HAVE_FFMPEG_SWSCALE_H 48 # include <ffmpeg/swscale.h> 49 #endif 50 51 #ifdef HAVE_LIBSWSCALE_SWSCALE_H 52 # include <libswscale/swscale.h> 53 #endif 24 54 25 55 #include "RpVideo.h" … … 53 83 char mode[64]; 54 84 char fmt[64]; 85 int lastframe; 55 86 56 87 /* tmp buffer to give images back to user */ … … 124 155 *vid->mode = '\0'; 125 156 *vid->fmt = '\0'; 157 vid->lastframe = 0; 126 158 127 159 vid->img = NULL; … … 141 173 int fnlen = 0; 142 174 int err = 0; 175 int lastframe = 0; 143 176 144 177 if (fileName == NULL) { … … 176 209 return err; 177 210 } 211 212 VideoFindLastFrame(vidPtr,&lastframe); 213 vidPtr->lastframe = lastframe; 178 214 } else if (*mode == 'w') { 179 215 /* we're now in "input" mode */ … … 186 222 return 0; 187 223 } 224 225 /* 226 * ------------------------------------------------------------------------ 227 * VideoFindLastFrame() 228 * 229 * Find the last readable frame. 230 * ------------------------------------------------------------------------ 231 */ 232 int 233 VideoFindLastFrame(vidPtr,lastframe) 234 VideoObj *vidPtr; 235 int *lastframe; 236 { 237 int f = 0; 238 int nframe = 0; 239 int cur = 0; 240 AVStream *vstreamPtr; 241 242 if (vidPtr == NULL) { 243 return -1; 244 } 245 246 if (lastframe == NULL) { 247 return -1; 248 } 249 250 if (VideoModeRead(vidPtr) != 0) { 251 return -1; 252 } 253 254 // calculate an estimate of the last frame 255 vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream]; 256 nframe = VideoTime2Frame(vstreamPtr, 257 vstreamPtr->start_time + vstreamPtr->duration); 258 259 // get the real last readable frame 260 // is 50 frames far enough to go back 261 // to be outside of the last key frame? 262 f = vidPtr->frameNumber; 263 cur = VideoGoToN(vidPtr,nframe-50); 264 while (cur != nframe) { 265 cur = nframe; 266 nframe = VideoGoNext(vidPtr); 267 } 268 *lastframe = nframe; 269 VideoGoToN(vidPtr,f); 270 271 return 0; 272 } 273 188 274 189 275 /* … … 619 705 global_video_pkt_pts = packet.pts; 620 706 621 // avcodec_decode_video(vcodecCtx, vidPtr->pFrameYUV, 622 // &frameFinished, packet.data, packet.size); 623 624 // packet.flags = PKT_FLAG_KEY; 625 avcodec_decode_video2(vcodecCtx, vidPtr->pFrameYUV, 626 &frameFinished, &packet); 627 628 // avcodec_decode_video2(_pCodecCtx, _pFrame, &frameFinished, 629 // &_packet); 707 avcodec_decode_video(vcodecCtx, vidPtr->pFrameYUV, 708 &frameFinished, packet.data, packet.size); 709 710 // avcodec_decode_video2(vcodecCtx, vidPtr->pFrameYUV, 711 // &frameFinished, &packet); 630 712 631 713 if (packet.dts == AV_NOPTS_VALUE … … 686 768 /* 687 769 * ------------------------------------------------------------------------ 688 * VideoInit Cmd()770 * VideoInit() 689 771 * 690 772 * Implements the body of the _ffmpeg_init method in the "video" class. … … 694 776 */ 695 777 VideoObj * 696 VideoInit Cmd()778 VideoInit() 697 779 { 698 780 /* … … 708 790 /* 709 791 * ------------------------------------------------------------------------ 710 * VideoCleanup Cmd()792 * VideoCleanup() 711 793 * 712 794 * Implements the body of the _ffmpeg_cleanup method in the "video" class. … … 716 798 */ 717 799 int 718 VideoCleanup Cmd(vidPtr)800 VideoCleanup(vidPtr) 719 801 VideoObj *vidPtr; 720 802 { … … 744 826 /* 745 827 * ------------------------------------------------------------------------ 746 * VideoSize Cmd()828 * VideoSize() 747 829 * 748 830 * Implements the body of the "size" method in the "video" class. … … 751 833 */ 752 834 int 753 VideoSize Cmd(vidPtr, width, height)835 VideoSize(vidPtr, width, height) 754 836 VideoObj *vidPtr; 755 837 int *width; … … 781 863 /* 782 864 * ------------------------------------------------------------------------ 783 * VideoGo Cmd()865 * VideoGo() 784 866 * 785 867 * Implements the body of the "go" method in the "video" class. … … 796 878 VideoObj *vidPtr; 797 879 { 798 return VideoGoPlusMinusN(vidPtr,1); 880 int nabs; 881 882 if (vidPtr == NULL) { 883 return -1; 884 } 885 886 nabs = vidPtr->frameNumber + 1; 887 return VideoGoToN(vidPtr, nabs); 799 888 } 800 889 … … 819 908 int n; 820 909 { 821 int nrel, nabs, seekFlags, gotframe ;910 int nrel, nabs, seekFlags, gotframe, t; 822 911 int64_t nseek; 823 912 AVCodecContext *vcodecCtx; … … 855 944 vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream]; 856 945 nseek = VideoFrame2Time(vstreamPtr, nabs); 946 // not sure why it is checking against the number 100 857 947 if (nseek > 100) { 858 948 nseek -= 100; … … 865 955 nseek, seekFlags); 866 956 957 // this doesn't seem to give me back the true frame number 958 // feels like it is more of a reverse of the VideoFrame2Time call 959 // because vidPtr->frameNumber always equals nabs 867 960 vidPtr->frameNumber = VideoTime2Frame(vstreamPtr, nseek); 868 961 vidPtr->atEnd = 0; 962 963 /* read the frame to figure out what the frame number is */ 964 VideoNextFrame(vidPtr); 869 965 870 966 /* then, move forward until we reach the desired frame */ … … 877 973 /* get at least one frame, unless we're done or at the beginning*/ 878 974 if (!gotframe && !vidPtr->atEnd) { 879 VideoNextFrame(vidPtr); 975 if (vidPtr->frameNumber > nabs) { 976 // we are probably at a key frame, just past 977 // the requested frame and need to seek backwards. 978 VideoGoToN(vidPtr,n); 979 } else { 980 VideoNextFrame(vidPtr); 981 } 880 982 } 881 983 } … … 894 996 /* 895 997 * ------------------------------------------------------------------------ 896 * VideoGet Cmd()998 * VideoGet() 897 999 * 898 1000 * Implements the body of the "get" method in the "video" class. … … 1007 1109 free(vidPtr->img); 1008 1110 VideoAllocImgBuffer(vidPtr,iw,ih); 1009 } else {1010 // image buffer is the correct size1011 // do nothing1012 1111 } 1013 1112 } … … 1024 1123 1025 1124 int 1026 Video GetFrameRate (vidPtr, fr)1125 VideoFrameRate (vidPtr, fr) 1027 1126 VideoObj *vidPtr; 1028 1127 double *fr; … … 1051 1150 // as frames per second. 1052 1151 *fr = av_q2d(vstreamPtr->r_frame_rate); 1152 1153 return 0; 1154 } 1155 1156 int 1157 VideoFileName (vidPtr, fname) 1158 VideoObj *vidPtr; 1159 const char **fname; 1160 { 1161 AVStream *vstreamPtr; 1162 1163 if (vidPtr == NULL) { 1164 return -1; 1165 } 1166 1167 if (fname == NULL) { 1168 return -1; 1169 } 1170 1171 if (vidPtr->pFormatCtx == NULL) { 1172 // vidPtr->pFormatCtx is NULL, video not open 1173 return -1; 1174 } 1175 1176 *fname = vidPtr->fileName; 1177 1178 return 0; 1179 } 1180 1181 int 1182 VideoPixelAspectRatio (vidPtr, num, den) 1183 VideoObj *vidPtr; 1184 int *num; 1185 int *den; 1186 { 1187 AVCodecContext *vcodecCtx; 1188 1189 if (vidPtr == NULL) { 1190 return -1; 1191 } 1192 1193 if ((num == NULL) || (den == NULL)) { 1194 return -1; 1195 } 1196 1197 if (vidPtr->pFormatCtx == NULL) { 1198 // vidPtr->pFormatCtx is NULL, video not open 1199 return -1; 1200 } 1201 1202 vcodecCtx = vidPtr->pFormatCtx->streams[vidPtr->videoStream]->codec; 1203 1204 *num = vcodecCtx->sample_aspect_ratio.num; 1205 *den = vcodecCtx->sample_aspect_ratio.den; 1206 1207 return 0; 1208 } 1209 1210 int 1211 VideoDisplayAspectRatio (vidPtr, num, den) 1212 VideoObj *vidPtr; 1213 int *num; 1214 int *den; 1215 { 1216 AVCodecContext *vcodecCtx; 1217 int width = 0; 1218 int height = 0; 1219 int64_t gcd = 0; 1220 int64_t gcd2 = 0; 1221 1222 if (vidPtr == NULL) { 1223 return -1; 1224 } 1225 1226 if ((num == NULL) || (den == NULL)) { 1227 return -1; 1228 } 1229 1230 if (vidPtr->pFormatCtx == NULL) { 1231 // vidPtr->pFormatCtx is NULL, video not open 1232 return -1; 1233 } 1234 1235 VideoSize(vidPtr, &width, &height); 1236 VideoPixelAspectRatio(vidPtr, num, den); 1237 1238 width = (*num)*width; 1239 height = (*den)*height; 1240 gcd = av_gcd(FFABS(width), FFABS(height)); 1241 1242 *num = width/gcd; 1243 *den = height/gcd; 1244 1245 if (*den == 0) { 1246 *num = 0; 1247 *den = 1; 1248 } 1053 1249 1054 1250 return 0; … … 1122 1318 int *pos; 1123 1319 { 1124 int nframe = -1;1125 1320 AVStream *vstreamPtr; 1126 1321 … … 1137 1332 } 1138 1333 1139 if (vidPtr->pFormatCtx) { 1140 vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream]; 1141 nframe = VideoTime2Frame(vstreamPtr, 1142 vstreamPtr->start_time + vstreamPtr->duration); 1143 } 1144 1145 *pos = nframe; 1334 *pos = vidPtr->lastframe; 1146 1335 return 0; 1147 1336 } … … 1150 1339 ///* 1151 1340 // * ------------------------------------------------------------------------ 1152 // * VideoPut Cmd()1341 // * VideoPut() 1153 1342 // * 1154 1343 // * Implements the body of the "put" method in the "video" class. … … 1158 1347 // */ 1159 1348 //int 1160 //VideoPut Cmd(cdata, interp, argc, argv)1349 //VideoPut(cdata, interp, argc, argv) 1161 1350 // ClientData cdata; /* not used */ 1162 1351 // Tcl_Interp *interp; /* interpreter */
Note: See TracChangeset
for help on using the changeset viewer.