summaryrefslogtreecommitdiff
path: root/rotord/test_ffms2.c
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-02-17 13:36:38 +0000
committerTim Redfern <tim@eclectronics.org>2014-02-17 13:36:38 +0000
commit22e28216336da876e1fd17f380ce42eaf1446769 (patch)
tree444dad3dc7e2656992d29f34f7bce31970c122a5 /rotord/test_ffms2.c
parentae5e8541f6e06e64c28719467cdf366ac57aff31 (diff)
chasing indexing error
Diffstat (limited to 'rotord/test_ffms2.c')
-rw-r--r--rotord/test_ffms2.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/rotord/test_ffms2.c b/rotord/test_ffms2.c
new file mode 100644
index 0000000..1b30b04
--- /dev/null
+++ b/rotord/test_ffms2.c
@@ -0,0 +1,117 @@
+#include <ffms.h>
+#include <stdio.h>
+#ifdef _WIN32
+#include <objbase.h>
+#endif
+
+
+
+int main (int argc, char *argv[]) {
+
+ if(argc<2){
+ printf("Error: USAGE - test filename\n");
+ return 0;
+ }
+ /* If you are on Windows you should first initialize COM, or all MPEG-TS/PS and OGM
+ files may return an error when you try to open them (if the library was built
+ with HAALISOURCE defined). All other formats will work normally. */
+#ifdef _WIN32
+ bool com_inited = false;
+ HRESULT res = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+ if (SUCCEEDED(res))
+ com_inited = true;
+ else if (res != RPC_E_CHANGED_MODE) {
+ /* com initialization failed, handle error */
+ }
+#endif
+
+ /* Initialize the library itself.
+ The cpu caps are autodetected almost all places nowadays. Passing 0 should have close to no performance
+ impact with a recent FFmpeg. If you want you can pass something like
+ FFMS_CPU_CAPS_MMX | FFMS_CPU_CAPS_MMX2. */
+ FFMS_Init(0, 0);
+
+ /* Index the source file. Note that this example does not index any audio tracks. */
+ char errmsg[1024];
+ FFMS_ErrorInfo errinfo;
+ errinfo.Buffer = errmsg;
+ errinfo.BufferSize = sizeof(errmsg);
+ errinfo.ErrorType = FFMS_ERROR_SUCCESS;
+ errinfo.SubType = FFMS_ERROR_SUCCESS;
+ const char *sourcefile = argv[1];
+ FFMS_Index *index = FFMS_MakeIndex(sourcefile, 0, 0, NULL, NULL, FFMS_IEH_STOP_TRACK, NULL, NULL, &errinfo);
+ if (index == NULL) {
+ /* handle error (print errinfo.Buffer somewhere) */
+ printf("Error: cannot index %s\n",sourcefile);
+ return 0;
+ }
+
+ /* Retrieve the track number of the first video track */
+ int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_VIDEO, &errinfo);
+ if (trackno < 0) {
+ /* no video tracks found in the file, this is bad and you should handle it */
+ /* (print the errmsg somewhere) */
+ }
+
+ /* We now have enough information to create the video source object */
+ FFMS_VideoSource *videosource = FFMS_CreateVideoSource(sourcefile, trackno, index, 1, FFMS_SEEK_NORMAL, &errinfo);
+ if (videosource == NULL) {
+ /* handle error (you should know what to do by now) */
+ }
+
+ /* Since the index is copied into the video source object upon its creation,
+ we can and should now destroy the index object. */
+ FFMS_DestroyIndex(index);
+
+ /* Retrieve video properties so we know what we're getting.
+ As the lack of the errmsg parameter indicates, this function cannot fail. */
+ const FFMS_VideoProperties *videoprops = FFMS_GetVideoProperties(videosource);
+
+ /* Now you may want to do something with the info, like check how many frames the video has */
+ int num_frames = videoprops->NumFrames;
+
+ /* Get the first frame for examination so we know what we're getting. This is required
+ because resolution and colorspace is a per frame property and NOT global for the video. */
+ const FFMS_Frame *propframe = FFMS_GetFrame(videosource, 0, &errinfo);
+
+ /* Now you may want to do something with the info; particularly interesting values are:
+ propframe->EncodedWidth; (frame width in pixels)
+ propframe->EncodedHeight; (frame height in pixels)
+ propframe->EncodedPixelFormat; (actual frame colorspace)
+ */
+
+ /* If you want to change the output colorspace or resize the output frame size,
+ now is the time to do it. IMPORTANT: This step is also required to prevent
+ resolution and colorspace changes midstream. You can you can always tell a frame's
+ original properties by examining the Encoded* properties in FFMS_Frame. */
+ /* See libavutil/pixfmt.h for the list of pixel formats/colorspaces.
+ To get the name of a given pixel format, strip the leading PIX_FMT_
+ and convert to lowercase. For example, PIX_FMT_YUV420P becomes "yuv420p". */
+
+ /* A -1 terminated list of the acceptable output formats. */
+ int pixfmts[2];
+ pixfmts[0] = FFMS_GetPixFmt("bgra");
+ pixfmts[1] = -1;
+
+ if (FFMS_SetOutputFormatV2(videosource, pixfmts, propframe->EncodedWidth, propframe->EncodedHeight, FFMS_RESIZER_BICUBIC, &errinfo)) {
+ /* handle error */
+ }
+
+ /* now we're ready to actually retrieve the video frames */
+ int framenumber = 0; /* valid until next call to FFMS_GetFrame* on the same video object */
+ const FFMS_Frame *curframe = FFMS_GetFrame(videosource, framenumber, &errinfo);
+ if (curframe == NULL) {
+ /* handle error */
+ }
+ /* do something with curframe */
+ /* continue doing this until you're bored, or something */
+
+ /* now it's time to clean up */
+ FFMS_DestroyVideoSource(videosource);
+#ifdef _WIN32
+ if (com_inited)
+ CoUninitialize();
+#endif
+
+ return 0;
+} \ No newline at end of file