adbkit icon indicating copy to clipboard operation
adbkit copied to clipboard

take a screenshot with scrcpy, suggestion need

Open saknarak opened this issue 11 months ago • 1 comments

I don't know how to decode/encdoe from h264 to jpeg without write to mp4 first and then call ffmpeg to get frame snapshot

here is my code

const scrcpy = client.scrcpy({
  crop: '640:480:0:300',
})
scrcpy.on('config', config => {
  console.log('config=', config)
})
scrcpy.on('frame', async data => {
  // how to decode data into jpeg, following code from test task
  let dm = await beamcoder.demuxer() // HELP NEED
  let dec = beamcoder.decoder({ demuxer: dm, stream_index: 0 }) // Create a decoder
  let packet = await dm.read()
  let decResult = await dec.decode(packet)
  let enc = beamcoder.encoder({ // Create an encoder for JPEG data
    name: 'mjpeg', // FFmpeg does not have an encoder called 'jpeg'
    width: dec.width,
    height: dec.height,
    pix_fmt: dec.pix_fmt.indexOf('422') >= 0 ? 'yuvj422p' : 'yuvj420p',
    time_base: [1, 1],
  })
  let jpegResult = await enc.encode(decResult.frames[0]) // Encode the frame
  await enc.flush() // Tidy the encoder
  await fs.promises.writeFile(`./out/snap_${new Date().getTime()}.jpeg`, jpegResult.packets[0].data)
})

let info = await scrcpy.start()
// firstFrame is undefined, it would be nice if firstFrame is a frame data
let frame = await info.firstFrame

PS. I want to make screenshot from some restrict app that not allow to. Only scrcpy tools can cast stream out , but it can't take a screenshot.

saknarak avatar Aug 08 '23 11:08 saknarak