[FFmpeg-devel] Blackmagic DeckLink indev

Michael Niedermayer michaelni at gmx.at
Thu Mar 29 18:27:21 CEST 2012


On Thu, Mar 29, 2012 at 10:27:55AM +0100, JULIAN GARDNER wrote:
> Code from the Blackmagic/Decklink WIP
> 
> As posted before, problem is that one a 1080i50 it works, but on a 720p59.94 i get 0.06 fps as the frame rate.
[...]

#define TIMESCALE AV_TIME_BASE


>             v->GetStreamTime(&pts, &duration, avfc->streams[0]->codec->time_base.den);

v->GetStreamTime(&pts, &duration, TIMESCALE)
also the return value should be checked for failure



> // av_log(avfc, AV_LOG_INFO, "Video Pts:%d, Duration %d, %d %d\n", pts, duration, avfc->streams[0]->codec->time_base.num, avfc->streams[1]->codec->time_base.den);
>             pkt.size= v->GetRowBytes() * v->GetHeight();
>             pkt.flags |= AV_PKT_FLAG_KEY;
>             pkt.stream_index = 0;
>             //pkt.pts = pkt.dts = pts/avfc->streams[0]->codec->time_base.num;

pkt.pts = pkt.dts = pts;


>             pkt.duration = duration;
>             packet_queue_put(bmd->queue, &pkt);
>         }
>     }
> 
>     if (a) {
>         av_init_packet(&pkt);
>         //XXX channels * sample bytes
>         pkt.size = a->GetSampleFrameCount() * 2 * 2;
>         a->GetBytes((void **)&pkt.data);
>         a->GetPacketTime(&pts, avfc->streams[1]->codec->time_base.den);
> // av_log(avfc, AV_LOG_INFO, "Audio Pts:%d %d %d\n", pts, avfc->streams[1]->codec->time_base.num, avfc->streams[1]->codec->time_base.den);
>         // pkt.pts = pkt.dts = pts;
>         pkt.flags |= AV_PKT_FLAG_KEY;
>         pkt.stream_index = 1;
>         //pkt.pts = pkt.dts = pts; // /avfc->streams[1]->codec->time_base.num;
>         packet_queue_put(bmd->queue, &pkt);
>     }
>     return S_OK;
> }
> 
> HRESULT
> DeckLinkCaptureDelegate::VideoInputFormatChanged(BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *mode, BMDDetectedVideoInputFormatFlags)
> {
>     return S_OK;
> }
> 
> extern "C" {
> 
> static AVStream *video_stream(AVFormatContext *s)
> {
>     BlackmagicData *bmd = (BlackmagicData *)s->priv_data;
>     AVStream *st = av_new_stream(s, 0);
>     BMDTimeValue num;
>     BMDTimeValue den;
> 
>     if (!st) return NULL;
> 
>     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
>     st->codec->codec_id = CODEC_ID_RAWVIDEO;
>     st->codec->width = bmd->display->GetWidth();
>     st->codec->height = bmd->display->GetHeight();
>     st->codec->pix_fmt = PIX_FMT_UYVY422;
>     bmd->display->GetFrameRate(&num, &den);


> /*    st->codec->time_base.den = den;
>     st->codec->time_base.num = num; */
>     st->codec->bit_rate = avpicture_get_size(st->codec->pix_fmt,
>                                              st->codec->width,
>                                              st->codec->height);
>     st->codec->bit_rate *= 1/av_q2d(st->codec->time_base) * 8;

you are changing the bit_rate based on a time_base, for which the
code setting it is commented out


> 
>     av_log(s, AV_LOG_INFO, "Video num:%d, den:%d\n", num, den);
> 
>     av_set_pts_info(st, 8*sizeof(BMDTimeValue), num, den);

av_assert0(sizeof(BMDTimeValue) >= 8); //will not work with the choosen TIMESCALE otherwise

avpriv_set_pts_info(st, 64, 1, TIMESCALE);


> 
>     return st;
> }
> //XXX hardcoded...
> static AVStream *audio_stream(AVFormatContext *s)
> {
>     BlackmagicData *bmd = (BlackmagicData *)s->priv_data;
>     AVStream *st = av_new_stream(s, 1);
>     BMDTimeValue num;
>     BMDTimeValue den;
> 
>     if (!st) return NULL;
> 
>     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
>     st->codec->codec_id = CODEC_ID_PCM_S16LE;
>     st->codec->sample_fmt = AV_SAMPLE_FMT_S16;
>     st->codec->sample_rate = 48000;
>     st->codec->channels = 2;
> 
>     bmd->display->GetFrameRate(&num, &den);

>     av_set_pts_info(st, sizeof(BMDTimeValue), num, den);

avpriv_set_pts_info(st, 64, 1, TIMESCALE);


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120329/bc63ef8e/attachment.asc>


More information about the ffmpeg-devel mailing list