Wednesday, October 14, 2015

Link to time base in ffmpeg

Reference (by Rich Felker ) : https://lists.libav.org/pipermail/ffmpeg-user/2005-September/001042.html


"You set timebase to the fundamental time unit you want to work with,
in seconds. Then you set the timestamp of each frame to the time (in
timebase units) at which that frame should be shown. For example
suppose you have a system in which frames may take place on 1/120
second granularity, with a mix of 24fps and 30fps content. You could
use a timebase of 1/120 with timestamps:

00 05 10 15 20 25 30 34 38 42 46 50 54 58 62 66 70 ...
\_________________/\_____________________________/
  24 fps sequence          30 fps sequence

If your frames don't come in on any regular interval, but at
completly random times (supposedly some webcam devices are random..)
then you can just set a timebase of 1/1000 or something and use
timestamps in milliseconds taken from the actual (system clock) times
at which you sampled the frames."

Tuesday, October 13, 2015

backyard fence

replaced in Sep 2015. painted using wood stain method. the stain is "solid color - redwood color - with stain and sealer all in one." the product claims 25 years guarantee. stain was purchased from home depot. the label "deep base" doesn't mean anything. it is only used by the store to add and mix color. 

Convert a static lib to a dynamic lib

Link: http://stackoverflow.com/questions/16082470/osx-how-do-i-convert-a-static-library-to-a-dynamic-one


g++ -fpic -shared -Wl,-all_load somelib.a -Wl,-noall_load -o somelib.dylib

Monday, September 21, 2015

ffmpeg link

http://ffmpegmac.net

provides version 2.7.2 that works on Yosemite

Building ffmpeg 32-bit target on a 64-bit machine

https://trac.ffmpeg.org/ticket/2659

$ ./configure --enable-small --cc='cc -m32'
$ ./configure --enable-shared --disable-static --cc='cc -m32'
$ ./configure --enable-shared --disable-static --enable-small --cc='cc -m32'
$ cc-v
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

$make
$make examples

Friday, May 22, 2015

Delete Thumbs.db

Thumbs.db file is a system file which is hidden by default. Under a network drive, you will not be able to delete that directory if there is a hidden thumbs.db file in it. The trick is to use command line to force a delete. First, if you can't see the mapped network drive, use net use command to explicitly map the drive (even though that drive might be accessible in windows explorer), and then enter the directory, and use the following command (remember to run dos as an administrator mode) :
    del /ash /s thumbs.db

Wednesday, May 06, 2015

Jasper-Banff

7/2: Arrived in Calgary. Get rental car, stay in Executive Royal Inn Hotel which is very close to T&T supermarket. Get some supplies before heading to Banff.

7/3: heading to Banff and stay at Bow View Lodge. the small hotel is very close to the main street and also close to small river. check out Banff town, Banff ave. get a map.

7/4: hiking and check out nearby places. then drive to Jasper and stay at Fairmount Japser (very expensive).

7/5: return from Jasper and stop at Lake Louise and then stay at Canmore's Mountain View Inn, a cheaper hotel.

The list of places:
- banff town, banff ave.
- bow river
 - bow falls
- castle mountain
- lake louise
- Minnewanka
- Morain Lake
- icefield parkway
- emeral lake

Monday, April 13, 2015

Using ffmpeg in your own MSVC projects

1. download dev build with headers and libs from http://ffmpeg.zeranoe.com/builds/
2. also download shared build because we will need those dll during run-time
3. make headers and libs visible to VC projects
4. add the following defines:


    #define __STDC_CONSTANT_MACROS
    #define __STDC_FORMAT_MACROS









5. some functions that use newer C features are not supported by MS Visual C++ 2012, like the following function call in log_packet(). These are not critical and can be commented out.

printf("pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n",
           buf1, av_ts2timestr(pkt->pts, time_base),
           buf2, av_ts2timestr(pkt->dts, time_base),
           buf3, av_ts2timestr(pkt->duration, time_base),
           pkt->stream_index);

6. some ffmpeg code directly assigned structure values which also failed in MSVC. the workaround is that we define a temporary variable, and then assign values for each field, and then do the copy.
    AVRational tmp;
    tmp.den = 1; tmp.num = c->sample_rate;
    ost->st->time_base = tmp;

7. remember to always call av_register_all(); otherwise, codec is not found.
8. in doc/example directory, check example code muxing. c for how to output video/audio samples with a container such as AVI.

9. a complete working code that generates MPEG4 AVI based on muxing.c example code is shown below:

    OutputStream video_st = { 0 }, audio_st = { 0 };
    char filename[] = "zz.avi";
    AVOutputFormat *fmt;
    AVFormatContext *oc;
    AVCodec *audio_codec, *video_codec;
    int ret;
    int have_video = 0, have_audio = 0;
    int encode_video = 0, encode_audio = 0;
    AVDictionary *opt = NULL;


    av_register_all();

    avformat_alloc_output_context2(&oc, NULL, NULL, filename);

    if (!oc) {
        printf("Could not deduce output format from file extension.\n");
        exit(1);
    }
 
    fmt = oc->oformat;
    if (fmt->video_codec != AV_CODEC_ID_NONE) {
        add_stream(&video_st, oc, &video_codec, fmt->video_codec);
        have_video = 1;
        encode_video = 1;
    }

     if (have_video)
        open_video(oc, video_codec, &video_st, opt);
     av_dump_format(oc, 0, filename, 1);

    /* open the output file, if needed */
    if (!(fmt->flags & AVFMT_NOFILE)) {
        ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);
        if (ret < 0) {
            fprintf(stderr, "Could not open '%s'\n", filename);
            exit(1);
        }
    }

        /* Write the stream header, if any. */
    ret = avformat_write_header(oc, &opt);
    if (ret < 0) {
        fprintf(stderr, "Error occurred when opening output file.\n");
        exit(1);
    }

    while (encode_video) {
        /* select the stream to encode */
        if (encode_video &&
            (!encode_audio || av_compare_ts(video_st.next_pts, video_st.st->codec->time_base,
                                            audio_st.next_pts, audio_st.st->codec->time_base) <= 0)) {
            encode_video = !write_video_frame(oc, &video_st);
        }
    }
     /* Write the trailer, if any. The trailer must be written before you
     * close the CodecContexts open when you wrote the header; otherwise
     * av_write_trailer() may try to use memory that was freed on
     * av_codec_close(). */
    av_write_trailer(oc);

    /* Close each codec. */
    if (have_video)
        close_stream(oc, &video_st);

    if (!(fmt->flags & AVFMT_NOFILE))
        /* Close the output file. */
        avio_closep(&oc->pb);

    /* free the stream */
    avformat_free_context(oc);

Sunday, December 07, 2014

redirect temporary burning directory

When burning a disc, sometimes the C drive is running out of space, or sometimes it is very slow to copy from one drive to the other. If we need to reconfigure the temporary burning folder to another location, we could use the following commands:

c:\Users\jzhou\AppData\Local\Microsoft\Windows > mklink /J burn e:\burn