[Libav-user] 回复: (no subject)
Blake Senftner
bsenftner at earthlink.net
Wed Dec 21 19:22:03 EET 2016
I have tried your url, and it opens and plays correct in my software. I just updated to the 3.2.2 libs yesterday, I suggest you make sure you are working with the latest too. (I’m working in Windows, and pre-built libs can be dlowloaded from here: https://ffmpeg.zeranoe.com/builds/) Your URL plays fine, as it appears to be encoded as 15 fps; it issue I am trying to solve in my code right now is I can not get greater than 15 fps.
Anyway, to help you, here is my logic that opens IP cameras and live streams, up till the point where avcodec_open2() is called. I also fixed incorrect h264 decompressing yesterday, which this code includes.
// setting up IP Camera options:
mp_opts = NULL;
av_dict_set( &mp_opts, "threads", "auto", 0 ); // if multi-threading is needed, do it, appears to be used
av_dict_set( &mp_opts, "max_delay", "1000000", 0 );
av_dict_set( &mp_opts, "rtsp_transport", "tcp", 0 );
av_dict_set( &mp_opts, "framerate", "29.97", 0 );
if (avformat_open_input( &mp_format_context, camera_stream, NULL, &mp_opts ) !=0)
return false; // failed to open stream
if (avformat_find_stream_info( mp_format_context, NULL ) < 0)
return false; // Couldn't find stream information
m_video_stream = -1;
for (uint32 i = 0; i < (uint32)mp_format_context->nb_streams; i++)
{
if (mp_format_context->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO)
{
m_video_stream = i;
break;
}
}
if (m_video_stream == -1)
return false;
AVCodecParameters* codecPars = mp_format_context->streams[m_video_stream]->codecpar;
AVCodec* pCodec = avcodec_find_decoder( codecPars->codec_id );
if (pCodec==NULL)
return false; // unsupported codec
mp_codec_context = avcodec_alloc_context3( pCodec );
if (avcodec_parameters_to_context( mp_codec_context, codecPars ) != 0)
return false; // Failed to copy codec context
if (avcodec_open2( mp_codec_context, pCodec, &mp_opts ) < 0)
return false; // failed to open codec
// and so on… I posted a few days ago the portion of my code that does the packet reading and display...
Sincerely,
-Blake Senftner
> On Dec 21, 2016, at 8:32 AM, sea <2509044372 at qq.com> wrote:
>
> Thank you very much. I download a .mov file from http://www.hd-trailers.net/movie/rogue-one-a-star-wars-story/, but get the same result, avcodec_open2 returns -1.
>
> Function av_dump_format gives .mov file information as :
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mov':
> Metadata:
> major_brand : qt
> minor_version : 537199360
> compatible_brands: qt
> creation_time : 2016-12-15 23:51:52
> timecode : 01:00:49:17
> Duration: 00:00:43.00, start: 0.000000, bitrate: 1080 kb/s
> Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 848x360, 997 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default)
> Metadata:
> creation_time : 2016-12-15 23:51:52
> handler_name : Apple Video Media Handler
> encoder : H.264
> Stream #0:1(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
> Metadata:
> creation_time : 2016-12-15 23:51:52
> handler_name : Time Code Media Handler
> timecode : 01:00:49:17
> Stream #0:2(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 76 kb/s (default)
> Metadata:
> creation_time : 2016-12-15 23:51:52
> handler_name : Apple Sound Media Handler
>
>
> I tried the stream address rtmp://live.hkstv.hk.lxdns.com/live/hks, the video stream has the type of h264. avcodec_open2 returns -1.
> av_dump_format print as:
> Input #0, flv, from 'rtmp://live.hkstv.hk.lxdns.com/live/hks':
> Metadata:
> author : PowerSmart
> copyright :
> description :
> datarate : 500
> livetime : 1470020146
> timeshift : 0
> Duration: 01:00:00.00, start: 0.000000, bitrate: N/A
> Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 640x480, 15.17 fps, 15 tbr, 1k tbn, 30 tbc
> Stream #0:1: Audio: aac, 32000 Hz, stereo, fltp
>
>
>
>
>
>
>
> ------------------ 原始邮件 ------------------
> 发件人: "Blake Senftner";<bsenftner at earthlink.net>;
> 发送时间: 2016年12月21日(星期三) 晚上11:46
> 收件人: "This list is about using libavcodec, libavformat, libavutil,libavdevice and libavfilter."<libav-user at ffmpeg.org>;
> 主题: Re: [Libav-user] (no subject)
>
> Is the h264 file you are using available online to test against?
>
> I have been using the h264 film trailers from here http://www.hd-trailers.net/movie/rogue-one-a-star-wars-story/
>
> And they open and play without issue. Do you get the same issue with your software using one of these clips?
>
> You may need to post your function that opens a stream up to the point where you call avcodec_open2()...
>
> Sincerely,
> -Blake Senftner
> Computer Stuff
>
>> On Dec 21, 2016, at 7:24 AM, sea <2509044372 at qq.com> wrote:
>>
>> In transcoding project of LeiXiaoHua(demo of usage of filters), if I use media file with h264 video stream as input file, the function avcodec_open2 will return -1. Media file with video stream in other format, such as mpeg4, mjpeg return 0 (OK). Why ? Someone meets the same problem?
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
More information about the Libav-user
mailing list