Skip to content

take a screenshot with scrcpy, suggestion need #18

Description

@saknarak

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions