From patchwork Fri Apr 22 08:37:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Malviya, Janpriya" X-Patchwork-Id: 35373 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b9e:b0:7d:cfb5:dc7c with SMTP id b30csp254381pzh; Fri, 22 Apr 2022 01:37:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+dQ4mbGV4eP/FgJSJm1SWECPcGQFy5iRx5h9MUZpHRht5nZHbwRW8ykJ2cVm4XRTzTEwR X-Received: by 2002:a17:907:2d08:b0:6f0:2c6b:df52 with SMTP id gs8-20020a1709072d0800b006f02c6bdf52mr2927958ejc.210.1650616648547; Fri, 22 Apr 2022 01:37:28 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j8-20020aa7c0c8000000b00423e88cfbe1si5330399edp.588.2022.04.22.01.37.25; Fri, 22 Apr 2022 01:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@bose.com header.s=pps1 header.b="X/MjJsvk"; dkim=neutral (body hash did not verify) header.i=@bose.com header.s=selector1 header.b=HZcFBsHD; dkim=neutral (body hash did not verify) header.i=@bose.com header.s=selector1 header.b=HZcFBsHD; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=bose.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6AF4268B185; Fri, 22 Apr 2022 11:37:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0a-00428a01.pphosted.com (mx0a-00428a01.pphosted.com [205.220.165.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7758768B185 for ; Fri, 22 Apr 2022 11:37:13 +0300 (EEST) Received: from pps.filterd (m0243507.ppops.net [127.0.0.1]) by mx0b-00428a01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23M7lV5c008976 for ; Fri, 22 Apr 2022 04:37:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bose.com; h=from : to : cc : subject : date : message-id : content-type : mime-version; s=pps1; bh=kku3VCWGyMrF4vVYvXL36zGTra7oD1CfgR8y6h0W3kI=; b=X/MjJsvk2bK6ZI+c+Q23Rr760vnl4BCap6IEJyXb1PvRwVgUe5t9z/0qvw1PkpUmAfGe cXqKPE4NzVohOnkbcm+oB1/VzRn1kpyrnjwSuyTVD9vrRYNUzvcMxSORDrXg8JJDcspY QFMVQlNe20bbhp4L9Z+p0SRfxAyyjXv9Bjlj13wqhff7sfQJy9uj3a9VkNM8DgEWwGLR ULaFAnjPbAKRy4loo5H0Gbls5duyAIJEAnowVRaq9w/oTr359Tt8PeeBdq9T4gpiPK+b okWSr6VLxrAyxQGAyLleHzOE/DnYco4NQswJJmumgc7CJDpSyMpcQgrHDV4mBLfXtzEy ng== Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2048.outbound.protection.outlook.com [104.47.73.48]) by mx0b-00428a01.pphosted.com (PPS) with ESMTPS id 3ffqumrmhu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 22 Apr 2022 04:37:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bose.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kku3VCWGyMrF4vVYvXL36zGTra7oD1CfgR8y6h0W3kI=; b=HZcFBsHD+F0JGZW2w7SRAg9S3rz5bF+29Udod49kEeC7MdmbtGGyEVP5H+jAjkzZYdM+tXDVA3INakVBXbiEKoapNFBGA/nCFLTubg46sZBbLmqoVqr7aMnlMTFLtC0olRTaT7Zasb1iBilIUgUweg9ILBtzp4IjF36Xhkgz8HY= Received: from MW4PR03CA0018.namprd03.prod.outlook.com (2603:10b6:303:8f::23) by BN0PR08MB7293.namprd08.prod.outlook.com (2603:10b6:408:148::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Fri, 22 Apr 2022 08:37:06 +0000 Received: from MW2NAM10FT041.eop-nam10.prod.protection.outlook.com (2603:10b6:303:8f:cafe::e6) by MW4PR03CA0018.outlook.office365.com (2603:10b6:303:8f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:37:06 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 34.202.228.63) smtp.mailfrom=bose.com; dkim=pass (signature was verified) header.d=bose.com;dmarc=pass action=none header.from=bose.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning bose.com discourages use of 34.202.228.63 as permitted sender) Received: from dg1.bose.com (34.202.228.63) by MW2NAM10FT041.mail.protection.outlook.com (10.13.155.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:37:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kMOyzri/RdV9sfV71imamwArLvIGgj27rZgdbeH/gFw59oz5onxKqlQUIoiJpk3dUwezNmjtR3ZvIS0qq4GCCjLrdFycsnHYTxP8wy+ZvykrkNdF0odNWRwqq9yu5HW/BD6CnEoTluzK6fdiMySQT/veaSdXLiLh6yO/TIaFxcFJQ4mr6rRy/1OXFHMswJEXST2p1oa6Mf/6ZXwuI6ASO8bCAROqdv1NRb58t2JHqrw3ZPeJhvBZjdoF+f7nThSmNZfuk8P0c81Qi6l08OobsKm+wcOLJgrz24l0bOE6xC+6m6lU0MpQb1ySCZGeA/n5ZN+IXn3dy3YLhYn8t0APIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kku3VCWGyMrF4vVYvXL36zGTra7oD1CfgR8y6h0W3kI=; b=mMJt3ZtdrQNAVfCfA8NjUUMm7erfvOVIuLEk7vu1S5P5M5Iovn8x3/7j98NDlSCrzfMSO962vTYE/bvQu69EPTT2accVpdlnDEScHqRf2bzNa+VRnN4Bsa2Vo7CbpK5s4QjPyJk1uJ5Si7Tms9b9IdjmqG1woqmcnb/4obrqGZyNhuV9OCAjEhykK2Riwa7BWDi7/Ri7p7ovsv3b5EIVyxmKkPxeQsOMd923VqtelDsbxGkqTk4uCLKUuMsF0t5PCIyL2ip2eAO2jqSxDq91mVIonlBmkcfgpRPzDne9yMRi1M6Aq4Zcbex6tkEbQ8Uz1atspsjsokwLgIiKVvVr9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bose.com; dmarc=pass action=none header.from=bose.com; dkim=pass header.d=bose.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bose.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kku3VCWGyMrF4vVYvXL36zGTra7oD1CfgR8y6h0W3kI=; b=HZcFBsHD+F0JGZW2w7SRAg9S3rz5bF+29Udod49kEeC7MdmbtGGyEVP5H+jAjkzZYdM+tXDVA3INakVBXbiEKoapNFBGA/nCFLTubg46sZBbLmqoVqr7aMnlMTFLtC0olRTaT7Zasb1iBilIUgUweg9ILBtzp4IjF36Xhkgz8HY= From: "Malviya, Janpriya" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] libavformat/mov.c : Avoid seek request with invalid seek offset ( 9223372036854775799 ) after EOS Thread-Index: AdhWEyc7NcjLMc2bSTyYe3BqgReNoA== X-DGNDLP: BoseProcessed1 Date: Fri, 22 Apr 2022 08:37:01 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: msip_labels: MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_Enabled=true; MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_SetDate=2022-04-22T08:12:35Z; MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_Method=Standard; MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_Name=879e395e-e3b5-421f-8616-70a10f9451af; MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_SiteId=0beb0c35-9cbb-4feb-99e5-589e415c7944; MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_ActionId=6026d4c2-1e2d-43b0-bf86-1b1a5bd55b86; MSIP_Label_879e395e-e3b5-421f-8616-70a10f9451af_ContentBits=0 Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bose.com; x-ms-exchange-messagesentrepresentingtype: 1 X-MS-Office365-Filtering-Correlation-Id: f7c36389-d7a0-43b5-1605-08da243b4804 x-ms-traffictypediagnostic: BN7PR08MB4323:EE_|MW2NAM10FT041:EE_|BN0PR08MB7293:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: qMsMRw5MIHff2z5nSvFJcPopcAzZcnZI64pcxD5skVJyJs8Y9OgDhM7WNad8Yh9MG7LKc5IyPwZ3sHWl/o8Nb57nQGYac/rffDLgs6vlq6KNfpA653jP6gAjycOubc20kGXBHE4KiVEPrT8KX2iv0cKrWqxy7y0a1yC/OwFf5ngYIA+81MTuaRfwyp5+e/RM1EXYDdFl6/NHm8ILn41rdMpLKQTxKBZLXnagdSwxLJ/KF/BkW01tptY+eOo1g+jIcNVBIXGjSxduzLQSAIri9dGdvLhWF4nUzm/5Tw4yhn1QRdZSL75CgB9yXQAz6GO2DFbvHuN+hX2blMQhJK81Ev8qavbeUpTmNpQ6t9tFETVDBRHOBC/LQweOBHZ5AGeEHW4I4unzwv9LSuQEiXgR5f1SDrV9rBWJTXiy3BxXgrsoBGTiCvCLqarSzYxknyhdT0vscDQyBGpgMWsDIZEd5fod2ggKVTU6lLB610HHXQKjr9ZxLld1ZjnsjOz8atH3msZB7mfqZanrHUnPd8JdLytoqh0IvV4eekrL+Vm7xMOqd5voegW19sjF2YOrKfiODpxqmizRD6XUpsn2PngdQ3Q82hx6WBasGs1N7Kz0dmtHMJyZnIKhSY2GBQ+5x9Z+YgpMqaGb1RmGtbVEyyl6fDmgQ5yr4KZzcEuFyNo8e1s9QyMcfxNoPyInvbzr3CybAZllx7rRRcdhROswU/BnjP0LcukJm78bn84YxeG7jCU= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR08MB2655.namprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(9686003)(38100700002)(6506007)(66476007)(5660300002)(55236004)(186003)(99936003)(6916009)(71200400001)(26005)(8936002)(107886003)(38070700005)(508600001)(52536014)(54906003)(33656002)(66446008)(64756008)(86362001)(122000001)(4326008)(83380400001)(7696005)(8676002)(55016003)(316002)(66946007)(2906002)(76116006)(66556008)(116584003); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR08MB4323 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: MW2NAM10FT041.eop-nam10.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4961f026-84c8-49a2-79a6-08da243b4559 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i1DVBEDkNlqbxZspo3JTmz0FlBXuKhU+4ufBIgRb298SJPN3Had7QJsZioujhyqpfrFpKE0Ae2ZwUNgGVqZ2sk54kiL6EduANxsCmJNtop8JViLK9/VUZPNowBsYITjfCSZWfmR4FCESk3ZowC9m91pSPZyCL0vMAWIvml1j9EzgGkNe4ikR4/a49ZqTk5GoKsBh183/BOWNPbUVPYEiN8Dg+Bl0/4+CAcnVuJGRqlEm4D8M1p6eqFOnyY/Jw2uEXTs4TeZPYOEOj6ToP94w2J3ikuCCJ6HNKF2/nEBliCLiJX3NKKb3HXrf3DjrHOnsD9bNH1Ez74DAno9ht5pVnoA40bpTmhWP46+LRupnjwrAidXE7YsflB+I448mYeCrNFjQfXuwpcK1Jt4wdUDgCL0KLoAs6RJb3xph6zFXssM3/XSlm7NGtJCCQfsCM46nOptVJ/JE2xXVEzqTYa8XI/UNu9+gH8Z5hf5uGo7Bcs41mARQVi9KHN2SSAqwivnpGA5ZMdMZNOfawjzlyiPlWjmGfdGkRsUETgQPutEJgHhwrudYM+jc28ffauFvz8wyKEvXNLww698SPLSEWLceYo5cxPIXN0adPsw2gFkmcoCFKytU8SbNoeoj1qi+VhufMvpv4aOnxV+jHftcDgQWwFJiziN2eadleeTDwNf76+OBWWtboQhIxY3Y9UkzfhfDXSV9/O3dNLRt/cMCMsZs/Q== X-Forefront-Antispam-Report: CIP:34.202.228.63; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:dg1.bose.com; PTR:ec2-34-202-228-63.compute-1.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(316002)(99936003)(356005)(81166007)(9686003)(6512007)(8936002)(36860700001)(86362001)(83380400001)(33656002)(82310400005)(36736006)(33964004)(70586007)(8676002)(4326008)(70206006)(6666004)(40460700003)(2906002)(6486002)(6916009)(54906003)(956004)(235185007)(336012)(508600001)(118246002)(5660300002)(107886003)(47076005)(26005)(52536014)(186003)(116584003); DIR:OUT; SFP:1101; X-OriginatorOrg: bose.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:37:05.4369 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7c36389-d7a0-43b5-1605-08da243b4804 X-MS-Exchange-CrossTenant-Id: 5d8ae07e-7fd0-404d-85c1-453ff3dc8c1e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d8ae07e-7fd0-404d-85c1-453ff3dc8c1e; Ip=[34.202.228.63]; Helo=[dg1.bose.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM10FT041.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR08MB7293 X-Proofpoint-ORIG-GUID: vp5ZEhsuoZDAkBNfpSQlTeYwpzjyw5Wg X-Proofpoint-GUID: vp5ZEhsuoZDAkBNfpSQlTeYwpzjyw5Wg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-22_02,2022-04-21_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 mlxlogscore=747 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204220037 Subject: [FFmpeg-devel] [PATCH] libavformat/mov.c : Avoid seek request with invalid seek offset ( 9223372036854775799 ) after EOS X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "Banerjee, Debasmit" , "Patel, Pratik" , "Van Iderstine, David" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: myEii9KQ9Nld Hello ffmpeg Dev team, While integrating FFmpeg for M4A , MP4 stream & facing issue that mov demuxer trying to request seek for invalid seek offset. Issue details:- - Modified doc/examples/demuxing_decoding.c example to support Custom IO call-back because we have our own mechanism to read data from source - In custom IO seek call back , we do not support “whence” values AVSEEK_SIZE & SEEK_END , used to find stream size ( returning -1 in both the cases ). - In attached screen shot , where we are observing seek with invalid seek offset and the seek requested after End of stream is detected - Seek offset value 9223372036854775799 always the same ( I think INT64_MAX – 8 , 8 is length Atom type & size field ) - If we allow to return proper stream size in seek callback then this problem is not observed. Fix : In attached patch to verify EOS condition before going to parse atom data. Signed-off-by: Janpriya Malviya Signed-off-by: Janpriya Malviya --- libavformat/mov.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.7.4 /* * Copyright (c) 2012 Stefano Sabatini * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /** * @file * Demuxing and decoding example. * * Show how to use the libavformat and libavcodec API to demux and * decode audio and video data. * @example demuxing_decoding.c */ //#include #include #include #include #include #include #include #define IO_BUF_SIZE ( 1024 * 2 ) #define SUPPORT_STREAM_SIZE 0 struct customIO { int file_fd; char* name; }; static AVFormatContext *fmt_ctx = NULL; static AVCodecContext *audio_dec_ctx = NULL; static AVStream *audio_stream = NULL; static const char *src_filename = NULL; static const char *audio_dst_filename = NULL; static FILE *audio_dst_file = NULL; static int audio_stream_idx = -1; static AVFrame *frame = NULL; static AVPacket *pkt = NULL; static int audio_frame_count = 0; static struct customIO input_file_io; static int read_packet( void *opaque, uint8_t *buf, int buf_size ) { struct customIO* in_file = ( struct customIO* )( opaque ); int length = 0; //printf( "read_packet : size %d \n", buf_size ); if( !in_file || ( in_file->file_fd < 0 ) ) { printf("read_packet : invalid fd or opaque ptr \n " ); return -1; } errno = 0; length = read( in_file->file_fd , &buf[0], buf_size ); if( length == 0 ) { printf( "EOS stream found \n" ); length = AVERROR_EOF; } return length; } static int64_t read_seek( void *opaque, int64_t offset, int whence ) { struct customIO* in_file = ( struct customIO* )( opaque ); off_t seek_ret = -1; if( !in_file || ( in_file->file_fd < 0 ) ) { printf("read_packet : invalid fd or opaque ptr \n " ); return -1; } printf( "ENTER : offset %" PRId64 " whence %d \n", offset, whence ); //============== // Special case for FFMPGE get stream size but we not supported this //============== if( whence == AVSEEK_SIZE ) { #if SUPPORT_STREAM_SIZE struct stat st; seek_ret = fstat(in_file->file_fd, &st); return seek_ret < 0 ? AVERROR(errno) : (S_ISFIFO(st.st_mode) ? 0 : st.st_size); #else //we not supporting stream size return -1;//return in->totalsize; #endif } //============== // Special case for us not supported this //============== if( whence == SEEK_END ) { return -1; } // printf( "ENTER : offset %" PRId64 " whence %d \n", offset, whence ); errno = 0; seek_ret = lseek( in_file->file_fd , offset, whence ); if( seek_ret < 0 ) { printf( "Seek Failed at SeekOffset ret: %d errono:%d offset: %lld \n",seek_ret, errno , offset );// %ll ret: %ll whence: %d errno: %d \n", offset, seek_ret, whence, errono ); } return seek_ret; } static int output_audio_frame(AVFrame *frame) { size_t unpadded_linesize = frame->nb_samples * av_get_bytes_per_sample(frame->format); //printf("audio_frame n:%d nb_samples:%d pts:%s\n", // audio_frame_count++, frame->nb_samples, // av_ts2timestr(frame->pts, &audio_dec_ctx->time_base)); /* Write the raw audio data samples of the first plane. This works * fine for packed formats (e.g. AV_SAMPLE_FMT_S16). However, * most audio decoders output planar audio, which uses a separate * plane of audio samples for each channel (e.g. AV_SAMPLE_FMT_S16P). * In other words, this code will write only the first audio channel * in these cases. * You should use libswresample or libavfilter to convert the frame * to packed data. */ fwrite(frame->extended_data[0], 1, unpadded_linesize, audio_dst_file); return 0; } static int decode_packet(AVCodecContext *dec, const AVPacket *pkt) { int ret = 0; // submit the packet to the decoder ret = avcodec_send_packet(dec, pkt); if (ret < 0) { fprintf(stderr, "Error submitting a packet for decoding (%s)\n", av_err2str(ret)); return ret; } // get all the available frames from the decoder while (ret >= 0) { ret = avcodec_receive_frame(dec, frame); if (ret < 0) { // those two return values are special and mean there is no output // frame available, but there were no errors during decoding if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN)) return 0; fprintf(stderr, "Error during decoding (%s)\n", av_err2str(ret)); return ret; } // write the frame data to output file ret = output_audio_frame(frame); av_frame_unref(frame); if (ret < 0) return ret; } return 0; } static int open_codec_context(int *stream_idx, AVCodecContext **dec_ctx, AVFormatContext *fmt_ctx, enum AVMediaType type) { int ret, stream_index; AVStream *st; const AVCodec *dec = NULL; ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0); if (ret < 0) { fprintf(stderr, "Could not find %s stream in input file '%s'\n", av_get_media_type_string(type), src_filename); return ret; } else { stream_index = ret; st = fmt_ctx->streams[stream_index]; /* find decoder for the stream */ dec = avcodec_find_decoder(st->codecpar->codec_id); if (!dec) { fprintf(stderr, "Failed to find %s codec\n", av_get_media_type_string(type)); return AVERROR(EINVAL); } /* Allocate a codec context for the decoder */ *dec_ctx = avcodec_alloc_context3(dec); if (!*dec_ctx) { fprintf(stderr, "Failed to allocate the %s codec context\n", av_get_media_type_string(type)); return AVERROR(ENOMEM); } /* Copy codec parameters from input stream to output codec context */ if ((ret = avcodec_parameters_to_context(*dec_ctx, st->codecpar)) < 0) { fprintf(stderr, "Failed to copy %s codec parameters to decoder context\n", av_get_media_type_string(type)); return ret; } /* Init the decoders */ if ((ret = avcodec_open2(*dec_ctx, dec, NULL)) < 0) { fprintf(stderr, "Failed to open %s codec\n", av_get_media_type_string(type)); return ret; } *stream_idx = stream_index; } return 0; } static int open_input_customIo( AVFormatContext *fmt_ctx , struct customIO* io ) { AVIOContext *avio_ctx = NULL; size_t avio_ctx_buffer_size = IO_BUF_SIZE; uint8_t* avio_ctx_buffer = ( uint8_t* )av_malloc( avio_ctx_buffer_size ); if( !avio_ctx_buffer ) { return AVERROR( ENOMEM ); } avio_ctx = avio_alloc_context( avio_ctx_buffer, avio_ctx_buffer_size, 0, (void*)(io), &read_packet, NULL, &read_seek ); if( !avio_ctx ) { return AVERROR( ENOMEM ); } fmt_ctx->pb = avio_ctx; fmt_ctx->flags = ( fmt_ctx->flags | AVFMT_FLAG_FAST_SEEK | AVFMT_FLAG_CUSTOM_IO ); return 0; } static int get_format_from_sample_fmt(const char **fmt, enum AVSampleFormat sample_fmt) { int i; struct sample_fmt_entry { enum AVSampleFormat sample_fmt; const char *fmt_be, *fmt_le; } sample_fmt_entries[] = { { AV_SAMPLE_FMT_U8, "u8", "u8" }, { AV_SAMPLE_FMT_S16, "s16be", "s16le" }, { AV_SAMPLE_FMT_S32, "s32be", "s32le" }, { AV_SAMPLE_FMT_FLT, "f32be", "f32le" }, { AV_SAMPLE_FMT_DBL, "f64be", "f64le" }, }; *fmt = NULL; for (i = 0; i < FF_ARRAY_ELEMS(sample_fmt_entries); i++) { struct sample_fmt_entry *entry = &sample_fmt_entries[i]; if (sample_fmt == entry->sample_fmt) { *fmt = AV_NE(entry->fmt_be, entry->fmt_le); return 0; } } fprintf(stderr, "sample format %s is not supported as output format\n", av_get_sample_fmt_name(sample_fmt)); return -1; } int main (int argc, char **argv) { int ret = 0; if (argc != 3) { fprintf(stderr, "usage: %s input_file audio_output_file\n" "API example program to show how to read frames from an input file.\n" "audio frames to a rawaudio file named audio_output_file.\n", argv[0]); exit(1); } //av_register_all(); src_filename = argv[1]; audio_dst_filename = argv[2]; input_file_io.name = src_filename; input_file_io.file_fd = open( input_file_io.name , O_RDONLY ); if( input_file_io.file_fd < 0 ) { printf(" input file not able to open \n"); return 0; } printf(" input_file_io.file_fd %d \n",input_file_io.file_fd); /* create input context */ fmt_ctx = avformat_alloc_context(); //Is FFmpeg parser created ? if( fmt_ctx ) { open_input_customIo( fmt_ctx , &input_file_io ); } /* open input file, and allocate format context */ if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) { fprintf(stderr, "avformat_open_input:Could not open source file %s\n", src_filename); exit(1); } /* retrieve stream information */ if (avformat_find_stream_info(fmt_ctx, NULL) < 0) { fprintf(stderr, "avformat_find_stream_info:Could not find stream information\n"); exit(1); } if (open_codec_context(&audio_stream_idx, &audio_dec_ctx, fmt_ctx, AVMEDIA_TYPE_AUDIO) >= 0) { audio_stream = fmt_ctx->streams[audio_stream_idx]; audio_dst_file = fopen(audio_dst_filename, "wb"); if (!audio_dst_file) { fprintf(stderr, "open_codec_context: Could not open destination file %s\n", audio_dst_filename); ret = 1; goto end; } } /* dump input information to stderr */ av_dump_format(fmt_ctx, 0, src_filename, 0); if (!audio_stream ) { fprintf(stderr, "Could not find audio or video stream in the input, aborting\n"); ret = 1; goto end; } frame = av_frame_alloc(); if (!frame) { fprintf(stderr, "Could not allocate frame\n"); ret = AVERROR(ENOMEM); goto end; } pkt = av_packet_alloc(); if (!pkt) { fprintf(stderr, "Could not allocate packet\n"); ret = AVERROR(ENOMEM); goto end; } if (audio_stream) printf("Demuxing audio from file '%s' into '%s'\n", src_filename, audio_dst_filename); /* read frames from the file */ while (av_read_frame(fmt_ctx, pkt) >= 0) { // check if the packet belongs to a stream we are interested in, otherwise // skip it if (pkt->stream_index == audio_stream_idx) ret = decode_packet(audio_dec_ctx, pkt); av_packet_unref(pkt); if (ret < 0) break; } /* flush the decoders */ if (audio_dec_ctx) decode_packet(audio_dec_ctx, NULL); printf("Demuxing succeeded.\n"); if (audio_stream) { enum AVSampleFormat sfmt = audio_dec_ctx->sample_fmt; int n_channels = audio_dec_ctx->ch_layout.nb_channels; const char *fmt; if (av_sample_fmt_is_planar(sfmt)) { const char *packed = av_get_sample_fmt_name(sfmt); printf("Warning: the sample format the decoder produced is planar " "(%s). This example will output the first channel only.\n", packed ? packed : "?"); sfmt = av_get_packed_sample_fmt(sfmt); n_channels = 1; } if ((ret = get_format_from_sample_fmt(&fmt, sfmt)) < 0) goto end; printf("Play the output audio file with the command:\n" "ffplay -f %s -ac %d -ar %d %s\n", fmt, n_channels, audio_dec_ctx->sample_rate, audio_dst_filename); } end: avcodec_free_context(&audio_dec_ctx); avformat_close_input(&fmt_ctx); if (audio_dst_file) fclose(audio_dst_file); av_packet_free(&pkt); av_frame_free(&frame); return ret < 0; } diff --git a/libavformat/mov.c b/libavformat/mov.c index 6c847de..9704550 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7556,6 +7556,10 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (atom.size >= 8) { a.size = avio_rb32(pb); a.type = avio_rl32(pb); + + if(avio_feof(pb)) + continue; + if (((a.type == MKTAG('f','r','e','e') && c->moov_retry) || a.type == MKTAG('h','o','o','v')) && a.size >= 8 &&